I am currently developing a D-app for Ethereum, usable with the Metamask extension. I use the truffle framework and testrpc to test locally my app.

When the user has to make a transaction to execute a function of smart contracts, the Gas Limit for the transactions in the Metamask window is always already set to a (variable) certain amount. As this amount is enough for most of my transactions, except a few for which I have to set manually the gas limit, I was wondering myself how is this amount for the gas limit calculated/estimated.

Where could I find some good information about this matter?

Any help would be greatly appreciated

enter image description here

1 Answer 1


I believe that MetaMask simply calls eth_estimateGas on whatever Ethereum node it's talking to. The implementation of eth_estimateGas is typically to simulate the transaction and measure the actual gas used. The actual amount of gas needed when the transaction is mined could be different if the contract's gas usage depends on things like the block number, block hash, or other data that may have changed between the time of the estimate and the time of the actual transaction.

  • 1
    Is there anything you can do as a developer to help the estimateGas be more accurate? It's a bad UX for transactions to fail.
    – Otto
    Nov 2, 2021 at 0:03

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.