USDT Transfer – Gas Limit Issue

gas-limitout-of-gastransferusdt

i have been asking by my client to save ETH when transfer out his USDT, he hope there is no or very little ETH left in his new USDT address. Please assume that USDT address has no initial ETH and next i got to transfer some ETH into it.

after long refer from other old transactions. i decided to use 26500 as gas limit (i assure that the recipient address has USDT) and not long needed ETH come after this and now i have enough gas to transfer USDT.

After broadcast the new tx to network, a moment later i encounter out-of-gas error. I tried with higher gas limit until i give up and set it to 60000. then guess now what, the tx is success! and actual consume gas is even lesser than 26500.

Anybody explain me why this happen? why i cant set exact gas limit to solve my problem? is transfer() in usdt contract has special condition? Thanks in advanced.

Best Answer

eventually i manage to find out this answer for myself.

This phenomenon happen because contract execution trigger refund gas mechanism.

Back to time when i transfer my whole USDT, upon contract execution, script was trigger opcode sstore[x] = 0 to remove my address info because i hold nothing and this will in turn refund me 15,000 gas.

In order to get the refund, one must set higher gas limit. It is worth to note that refund always happen at the end of contract execution. So you must ensure you have enough gas to take the refund. for example, a process need 300 gas to get 50 gas of refund, if you set 250 gas then u will encounter out-of-gas error and lost all the fund.

further study in How do gas refunds work? https://www.btcschools.net/ethereum/eth_gas.php

Related Topic