I have deployed this Simple ERC20 contract on Goerli to understand the gas amount required to deploy it.

I can see that it cost 1,252,517 wei to deploy, because on Etherscan it tells me:

Gas Limit & Usage by Txn: 1,252,517 | 1,252,517 (100%)

However, when I use ethers to estimate the gas cost ahead of time, it tell me Got the gas estimate 53000. Here is the code that produces this result.

const provider = new ethers.providers.AlchemyProvider("goerli", alchemyApiKey);
const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
const estimatedGas = await provider.estimateGas(contractFactory.getDeployTransaction(args[0],args[1],args[2],args[3],args[4]).data);
console.log("Got the gas estimate " + estimatedGas);

This is extremely inaccurate. Which leads me to my question...

Why is ethers estimateGas very inaccurate when estimating the cost for contract deployment?



Your Answer

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

Browse other questions tagged or ask your own question.