Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

hardhat ethers: deploy vs deployed

In following code:

console.log("Deploying contract....");
const simpleStorage = await simpleStorageFactory.deploy();
await simpleStorage.deployed();

Line 2 deploys the contract and we get hold of it.

Why do we need to call deployed method in Line3?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

calling deploy() will create the transaction, and you can get the contract address immediately, however this does not mean the transaction has been processed and included within a block.

deployed() will wait until it has been. Under the hood it will poll the blockchain until the contract has been succesfully processed. See: https://github.com/ethers-io/ethers.js/blob/master/packages/contracts/src.ts/index.ts#L824

I don’t think you technically have to call deployed(), but if you need to do anything after the contract has been deployed and need to make sure it has been included in a mined block, then waiting for deployed() is advised.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading