Gas measures execution work

Ethereum assigns a gas cost to operations it executes. A transaction’s gas usage depends on the instructions it runs, such as accessing storage or calling another contract. The amount of ETH transferred is a separate field. For the execution fee, multiply gas used by the effective price per unit of gas.

Calculate a fee from the receipt

If a hypothetical transaction uses 21,000 gas at an effective price of 20 gwei, the execution fee comes to 420,000 gwei, or 0.00042 ETH. One gwei is one billionth of an ETH. This example illustrates the calculation. On an Ethereum rollup, the total fee may also include a charge for posting data to Ethereum.

Read the limit and price cap separately

The gas limit caps the execution work a transaction can consume. Under EIP-1559, a transaction also specifies a maximum fee per unit of gas and a maximum priority fee. The effective price reflects the block’s base fee and the priority fee that fits within the user’s cap. Check the transaction receipt for the actual gas used and effective gas price.

Why a revert can still cost ETH

When a transaction is included and execution reverts, the state changes from the reverted execution are rolled back. The network still charges for the resources consumed. A transaction that ran out of gas and one that reverted early can use different amounts. A failed local simulation is a different event because it does not itself execute a transaction on Ethereum.

Sources

  1. Ethereum 官方文档:Gas与费用
  2. EIP-1559:费用市场机制
  3. Ethereum 官方文档:交易生命周期

Prepared with AI assistance. This guide explains protocol behavior for educational use.

Editorial policy (Chinese)