6

I would like to know what is the gas limit for other ERC-20 tokens like BAT, 0X, or OMG.

I understand that for regular transactions in Ethereum the gas limit is 21000, but is it the same for the rest of tokens mentioned?

I also want to know what other kind of transactions make the gas limit rise?

1
  • I have the same problem here, it is super annoying. Apr 20, 2021 at 13:14

3 Answers 3

9

Short answer: it really depends on the token, and typically varies from 25'000 to 150'000, with very rare cases going over 500'000 gas.

Recommendation: set it 200'000 if you don't have access to an estimate, it will work 99% of the time. It is a "limit" anyway, you will get back any unspent gas immediately.

If your wallet proposes an estimate, add roughly 10-20% to it.

Long answer:

There are several ways to get to the numbers you are looking for. The simplest is probably to use a good software wallet and let it do an estimate.

Many plugins and apps that allow you to send transactions on the Ethereum blockchain will tell you in advance how much gas they think the transaction will cost, and that is usually a good starting point to choose your gas limit.

What they do is actually pre-run the transaction locally, and by simulating the transaction, you get the estimated gas cost, which is often exactly correct. It may however vary, if the smart contract was called and its state changed in between the estimate and the actual mining of the tx. If the state change in some way affects your transaction, then the real gas cost may be different.

So I usually recommend to take the estimate and roughly round it up by about 10-20%. E.g. 129'543 ==> 150000. Anyway any excess gas sent along the transaction will be refunded immediately after the transaction is mined.

You can use any good wallet app or the Metamask plugin, there's many tools that could do the job.


As for which other operations make the limit rise: all of them.

Sending a transaction costs a minimum of 21000gas in principle. If the transaction involves any kind of computation or storage, then the gas cost will go up, and the gas limit you need to use must at least match it. So any call to a smart contract function will cost 21000 plus the cost of executing its code.

Most typical arithmetic operations cost between 3 and 10gas, as do most logical, memory and flow operations. Reading a 256bits word from storage costs 50, and writing a new variable to storage costs 20000, updating it costs 5000. Getting the eth balance costs 20. Validating the address of an elliptic curve signature costs 3000.

So a typical erc20 transfer will cost around 45k gas if the recipient didnt have any tokens before: 21k base + 20k to store the brand new token balance for this user + a few thousand for the validations, flow and event. A second transfer to the same rexipient will cost closer to 30, since his balance is now non-zero.

This should get you an idea of what's lying under the hood, and you can refer to the yellow paper for detailed gas costs of all opcodes.

0

Ether transfer to an externally-owned account will cost you exactly 21,000 gas units.

Ether transfer to a smart contract will cost you more than 21,000 gas units, and the exact amount depends on the implementation of the fallback function in that contract.

Token transfer - which subsequently triggers a smart contract function - will cost you more than 21,000 gas units, and the exact amount depends on the implementation of the token-transfer function in that contract.

2
  • So transfer of tokens like OMG, 0X, BAT will cost more than 21000? Is there any documentation you know where I can read more about? Thanks
    – Ricardo
    May 29, 2019 at 15:23
  • @Ricardo: Yes, No. May 29, 2019 at 16:01
0

Difinitly it costs more than 21000 because you run a smart contract....you can see gas limit and gas used of bat transaction here : https://etherscan.io/tx/0x136f818dfe87b367eee9890c162ef343dbd65e409aef102219a6091ba7e696d7 https://etherscan.io/tx/0xa3f00ca789c09a74e11945460e776c71e0731670902276381ba5a2b2c8336c8a https://etherscan.io/tx/0xc260a3d613a25113b6d2542c13fa5811e9bccddeac6838f3ae2b9da21e97bd68 https://etherscan.io/tx/0x3c481c15f9d4de82d22153d567ef2ea141fa23a76b31c330a620ca2d06400930

gas used is 37,064 and 52,040 most of the time

so you can consider 100'000 or 200'000 gas limit and then network return you the remain.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.