1

I was reading a comment on another post on Ethereum SE and found the following statement:

21,000 is for sending Ether, not anything else.

The user suggested to "just set it to a large enough value (which you are willing to pay in the worst case)"

I'm perplexed. When sending ECR20 tokens (such as USDC and USDT) is the gas limit arbitrary? Or is it fixed? Setting it to an arbitrarily large number and hoping it will get accepted by the network might work but it doesn't address the fundamental question of how gas fees are calculated when sending ECR20 based tokens?

Another user suggested in a different thread that the gas fee is in fact fixed by the creator of the token:

You will have control over the gasPrice however a standard ERC20 token transfer's gasUsed will be "fixed" (or at least out of your control).

What is the right answer? How should I calculate the gas fee when sending USDT and USDC?

2

The base number of gas needed for any transaction is 21,000 gas. Like you mentioned, sending Ether from an EOA to an EOA, without any data in the transaction, will always take exactly 21,000 gas.

Any gas on top of that is determined by a few things:

  • Transaction data: any zero byte of data costs 4 gas for example, and any non-zero byte costs 68 gas.
  • Contract execution: the cost of running code on the blockchain. This is determined by the opcodes that are used in the contract execution.

How much gas an ERC-20 token transaction takes depends on the contract implementation. A more complex contract, will result in a higher gas cost. There's no fixed number for token transfers, since the gas cost can depend on many different factors. For example, if someone never received tokens before (balance = 0), the cost for contract execution will be slightly higher because you're changing a number (balance) from zero to a non-zero value.

The cost of each operation is specified in the Ethereum Yellow Paper. To get an estimate of how much gas you need for a transaction, you can use the eth_estimateGas JSON-RPC function.

2
  • Thanks for your reply. Assuming I'm sending transaction w/o data and to address that already has ETH (non zero balance), does Coinbase (USDC) or Tether (USDT) make the gas fees public or I would need to analyze the byte code (contract) and calculate the fee myself? One thing seems clear it will always be > 21,000..? – S.O.S Jan 18 at 3:34
  • Token transactions need data to send the token, that's where the value and target address are specified. If you want to get the gas required for your transaction, the easiest way is to use eth_estimateGas as I mentioned, but I suppose you could do it manually too by analysing the byte code (but I wouldn't recommend it). – Morten Jan 18 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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