Why do some transactions use more gas than others, even when they are transferring the same ERC20 token, for example USDC. Even when the receiver is the same and the transferred amount is the same. This one used 42,381 gas: https://etherscan.io/tx/0x05c86098176a2d7d7d85375c7745503c36b7abc7dbdcbcdd01802859b6fec3a9 This one used 27,381 gas: https://etherscan.io/tx/0x4499361f0ab60aed804f6d4ead7aa2ec0f801dcc3cfa1d945bd82c1081ca8611
1 Answer
The difference of 15,000 gas is caused by a gas refund which occurs when storage is cleared (see Yellow Paper Appendix G):
Rsclear 15000 Refund given (added into refund counter) when the storage value is set to zero from non-zero.
-
To clarify: the gas consumption depends on if the receiver has already tokens and if the sender has zero tokens after the transaction is done. Mar 10, 2021 at 7:41
-
So this refund happenes automatically, if I send all my token, because there is nothing to be recorded in the blockchain anymore. Is that correct?– ThomasMar 18, 2021 at 11:36
-