What is the need is deployTransaction] if we already deployed the contract using deploy() and confirmed using deployed() #5514
-
I am following the FCC course of BLOCKCHAIN AND SOLIDITY.. In the HH-SimpleStorage-FCC section we deployed the contract using BUT then we also have the following statement if NO then what is the need to the code snippet for the deployment of the contract is as follows const main = async () => {
const SimpleStorageFactory = await ethers.getContractFactory(
"SimpleStorage"
)
console.log("Deploying ...")
const simpleStorage = await SimpleStorageFactory.deploy()
await simpleStorage.deployed()
console.log(`Deployed to ${simpleStorage.address}`)
if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
await simpleStorage.deployTransaction.wait(6)
await verify(simpleStorage.address,[])
}
const currentValue = await simpleStorage.retrieve()
console.log(`Current value is ${currentValue}`)
const transactionResponse = await simpleStorage.store(7)
await transactionResponse.wait(1)
const updatedValue = await simpleStorage.retrieve()
console.log(`Updated value is ${updatedValue}`)
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello @adityapadekar We are doing |
Beta Was this translation helpful? Give feedback.
-
@adityapadekar Actually on the next line we have to verify our smart contract programmatically on etherscan and etherscan can only verify our smart contract when it will be available on the blockchain. Sometimes transaction takes 1 block to confirm and sometimes need more but we are not sure how many blocks we need to confirm. So as a rule of thumb is to wait for 6 blocks so we can say our transaction is confirmed, a smart contract is deployed and now etherscan can verify the smart contract. |
Beta Was this translation helpful? Give feedback.
Hello @adityapadekar
We are doing
simpleStorage.deployTransaction.wait(6)
because it means we are waiting 6 BLOCKS to confirm transacion (We will specify waiting blocks confirmation in hardhat.config.js later on in course). If you will dowait(6)
you are not waiting for blocks confirmations but only for 6 seconds.