为什么这个以太坊合约交易使用的gas少?

Why this ethereum contract transaction used less gas?

请查看以下以太坊交易:

0xe9adbe7e538ccf9f9d4ede8cc4200581dac131976738d3bbf0eb90700cd8a2b6

一笔以太坊交易至少消耗 35,000 GAS 来转移合约上的 ERC20 代币以替换两个账户余额和一个事件。

但是,这笔交易只用了21,003 GAS。这怎么可能?

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

这种说法不一定正确。消耗的 gas 量取决于先前 and/or 该帐户的 post 更新余额是否为 0。

来自 Ethereum yellow paper(OPCODE 名称|Gas 成本|描述):

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.

在您 post 的交易中,发件人转移了他们所有的代币,将余额设置为 0,因此获得了 15000 gas 退款。