Search code examples
blockchainethereumsoliditycontracterc20

Why this ethereum contract transaction used less gas?


Please checkout this below ethereum transaction:

0xe9adbe7e538ccf9f9d4ede8cc4200581dac131976738d3bbf0eb90700cd8a2b6

An ethereum transaction consumes at least 35,000 GAS to transfer ERC20 tokens on contracts for replacing two accounts balances and one event.

But, this transaction just used 21,003 GAS. How is that possible?


Solution

  • an ethereum transaction is consumes at least 35,000 GAS to transfer ERC20 tokens on contracts for replacing two accounts balances and one event

    This statement is not necessarily correct. The amount of gas consumed depends on if the previous and/or the post update balance for that account is 0.

    From the Ethereum yellow paper (OPCODE Name|Gas cost|Description):

    Gsset 20000 Paid for an SSTORE operation when the storage value is set to non-zero from zero.

    Gsreset 5000 Paid for an SSTORE operation when the storage value’s zeroness remains unchanged or is set to zero.

    Rsclear 15000 Refund given (added into refund counter) when the storage value is set to zero from non-zero.

    In the case of the transaction you posted, the sender transferred all of their tokens setting their balance to 0, so a 15000 gas refund was given.