I know that web3 exposes a function to estimate gas limit, but is it accurate when sending to a contract?

AFAIK the amount of gas I'm gonna need if sending to a contract depends on the contract code, so in general case can be anything.

Is there a way to reliably figure out the gas limit for a transaction if it's to a contract before sending it?

1 Answer 1


No there is no way to know it reliably. Even sending the same transaction multiple times may result in different gas amounts. (See for example here Why gas-used are different for same transfer() tx? ). Also other factors make it difficult/impossible to estimate it correctly, such as loops (can we know in advance how many times we will loop?).

The amount can only be estimated. Different tools have different estimates - some probably better than others.

Transactions to EOAs (Externally Owned Account) are trivial to estimate as it depends solely on the amount of data you send plus static transaction cost (21000).

  • Thanks a lot. However, regular account transfer is still 21000 + 68 * bytes_of_data, precisely, right? Commented Aug 12, 2019 at 16:19
  • Modified answer to include EOA Commented Aug 12, 2019 at 16:21

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.