Skip to content

Commit

Permalink
Added check for existence of contract at expected address
Browse files Browse the repository at this point in the history
  • Loading branch information
SKYBITDev3 committed Aug 15, 2023
1 parent ae1ffab commit e7c136f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/deployCreate3FactoryFromRawTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function main() {
gasPrice: 100000000000n,
value: 0,
chainId: 0,
// chainId: 31337,
}

// Keep this data consistent otherwise the deployment address will become different
Expand All @@ -48,11 +49,17 @@ async function main() {
// const tx = ethers.Transaction.from(txSignedSerialized) // checking the contents of signed transaction
// console.log(`Signed transaction: ${JSON.stringify(tx, null, 2)}`)

const addressOfCreate3Factory = ethers.getCreateAddress({ from: derivedAddressOfSigner, nonce: txData.nonce })
console.log(`Expected address of deployed ${factoryToDeploy} factory contract: ${addressOfCreate3Factory}`)

if(await ethers.provider.getCode(addressOfCreate3Factory) !== "0x") {
console.log(`The factory contract already exists at ${addressOfCreate3Factory}. So you can now simply use it.`)
return
}

const txSignedSerializedHash = ethers.keccak256(txSignedSerialized)
console.log(`Expected transaction ID: ${txSignedSerializedHash}`)

const addressOfCreate3Factory = ethers.getCreateAddress({ from: derivedAddressOfSigner, nonce: txData.nonce })
console.log(`Expected address of deployed ${factoryToDeploy} factory contract: ${addressOfCreate3Factory}`)

const gasCost = await ethers.provider.estimateGas({ data: create3FactoryArtifact.bytecode })
console.log(`Expected gas cost: ${gasCost}`)
Expand Down

0 comments on commit e7c136f

Please sign in to comment.