I am currently running some tests on ganache using web3.js connector.

Most of my transactions run OK if I supply the same amount of gas that is suggested by web3.eth.estimateGas(), however, one of the transactions uses about 3x the gas estimate provided by web3.eth.estimateGas(....), is this normal??

My concern is that once I deploy this on the mainnet and if this recurs randomly then I could be out of a lot of gas due to aborted operations resulting from inadequate gas supplied for the transaction.

What is the best practice for handling this kind of situation, should I normally supply x times the gasEstimate just to be on the safe side...what is a good value for x.

as a side note, the function call in question has three require statements, does that impact gas consumption in a big way??

  • does this transaction that uses 3x gas free some storage?
    – Nulik
    Sep 13, 2018 at 1:57
  • no, it adds a small amount of storage (2 x strings < 64 bytes + 1 x uint32
    – satyendra
    Sep 13, 2018 at 3:03
  • if the execution path is constant and you are 100% sure your contract isn't releasing any storage (that is setting some storage to 0) , estimateGas() should give accurate estimation. It is only wrong when you release storage. Every release of storage gives you +15000 more gas requirement, so if you clean some set of data in a loop, that's going to cost a lot in gas, an estimateGas() has no way of knowing it
    – Nulik
    Sep 13, 2018 at 14:51
  • What are the values are you talking about? 1M -> 3M or 40k -> 120k. Estimation is done executing the transaction and discarding the changes. I've seen transfers of the same ERC20 tokens vary from 40k to around 100k.
    – Ismael
    Sep 14, 2018 at 2:17
  • @Nulik: From my experience, it is wrong also when your function calls a function in another contract. Sep 14, 2018 at 5:24

1 Answer 1


Gas estimations are generally correct but sometimes gas used is very high as compared to gas estimation which depends on output too. If your transaction is successful gas used is low but when it fails gas used is high as it uses some searching algorithms.

For the safe side you can increase gas limit and gas price. I use GasPrice = 5000000 wei and GasLimit = 2000000000 wei. Works well for me.

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.