4

Right now, I can deploy a contract with ethers and hardhat like so:

const SimpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
const simpleStorage = await SimpleStorageFactory.deploy()
await simpleStorage.deployed()

However, our contract isn't guaranteed to be deployed. Is there a way to wait x block confirmations off a contract?

2 Answers 2

8

2023 Update

The contract object comes with a deploymentTransaction attribute, that has all the same attributes and functions a normal object has, so you can just do:

await simpleStorage.deploymentTransaction.wait(6)

To wait 6 blocks

Previously

The contract object comes with a deployTransaction attribute, that has all the same attributes and functions a normal object has, so you can just do:

await simpleStorage.deployTransaction.wait(6)

To wait 6 blocks

4
  • Where does the number 6 came from? May 27, 2022 at 11:55
  • 1
    I just picked 6. 6 is usually pretty good. May 31, 2022 at 21:01
  • Hey @PatrickCollins, first of all, thank you for all content, its impressive! I think now with ethers6 they changed and we don't have anymore the .deployTransaction: TypeError: no matching function (argument="key", value="deployTransaction", code=INVALID_ARGUMENT, version=6.6.7) I passed it using the line below: await contract.deploymentTransaction().wait(6) :rocket Jul 30, 2023 at 10:27
  • Are you using hardhat-deploy? I don't see that function in the ethers docs. Jul 30, 2023 at 14:20
1

Note that on recent versions of Hardhat, the deployTransaction attribute has been replaced in favor of a new function called deploymentTransaction. So you would need to do instead:

await simpleStorage.deploymentTransaction().wait(6);

(where 6 is the number of confirmations to wait)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.