2

I am writing a js script that deploy my solidity contract. In the tuto, they use two methods .deploy() and .deployed()

const main = async () => {
const [owner, randomPerson] = await hre.ethers.getSigners();
const waveContractFactory = await hre.ethers.getContractFactory("WavePortal"); 
const waveContract = await waveContractFactory.deploy();
await waveContract.deployed(); 
    

I would like to know what's the difference between these two methods. I can't find any info about .deployed() in hardhat documentation.

3 Answers 3

6

deploy() will trigger this deployment of the contract and .deployed() checks if the contract is already available on the blockchain and if the deployment is still ongoing will wait for the deployment transaction to be mined (see https://github.com/ethers-io/ethers.js/blob/master/packages/contracts/src.ts/index.ts#L819).

0
0

From another view point, deployed() is just waveContract.wait() which is just another function call to wait for some block confirmations

1
  • Hi. I think this should be a comment on the accepted answer, or an edit to the accepted answer, not a answer itself as it does not provide an actual answer to the question. Jun 24, 2022 at 5:59
0

.deployed() helps us to ensure that our contract is properly deployed and is now ready to interact with further in our script. .deploy() handles the actual deployment whereas .deployed() will wait for block confirmations too by calling deployTransaction.wait() and can also logs error if contract is not deployed (See - https://github.com/ethers-io/ethers.js/discussions/1577).

Double checking is always a good practice when it's about deployments and can prevent errors, and that is why I feel .deployed() is good to have in the script.

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.