Sub topic 12
Ethereum and EVM Chains: Gas, Base Fee, and Priority Fee
Assume you know what a blockchain transaction is and can read percentages and basic Python. This chapter explains how Ethereum Virtual Machine (EVM) chains price the computation and data used by a transaction.
Gas measures the work
On an EVM chain, gas is a unit of computational work. Every operation, such as transferring tokens or updating a smart contract, consumes a defined amount of gas.
A transaction usually specifies:
- Gas used: The amount of work the transaction actually consumes.
- Gas limit: The maximum gas the sender allows the transaction to consume.
- Gas price: The price paid for each unit of gas.
The basic fee formula is:
transaction fee = gas used × effective gas price
A simple ETH transfer uses about 21,000 gas. A token transfer or decentralized exchange swap usually needs more because it runs smart-contract code and changes more blockchain state.
Base fee and priority fee
Modern Ethereum uses a fee model introduced by EIP-1559. The effective gas price has two main parts:
| Component | Purpose |
|---|---|
| Base fee | Network-determined price, which is burned |
| Priority fee | Tip offered to the block producer for including the transaction |
The sender also sets a maximum fee per gas. The effective price is:
effective gas price = min(max fee, base fee + priority fee)
If the maximum fee is higher than necessary, the unused portion is not charged. The sender pays the effective price for the gas actually used.
GWEI = 10**9
WEI_PER_ETH = 10**18
def evm_fee_eth(gas_used, base_fee_gwei, priority_fee_gwei, max_fee_gwei):
gas_price_gwei = min(max_fee_gwei, base_fee_gwei + priority_fee_gwei)
return gas_used * gas_price_gwei * GWEI / WEI_PER_ETH
# A plain ETH transfer uses 21,000 gas.
fee = evm_fee_eth(21_000, 20, 2, 50)
print(fee) # 0.000462 ETHHere, the effective gas price is 22 gwei, not 50 gwei. The transaction pays:
21,000 × 22 gwei = 462,000 gwei = 0.000462 ETH
The base fee is burned. The priority fee goes to the block producer, subject to the chain's rules.
Limits and failure modes
A gas limit that is too low causes an out-of-gas failure. The state changes are reverted, but the gas already consumed is still charged.
A maximum fee below the current base fee generally prevents the transaction from being included until conditions change. A high priority fee may improve inclusion speed, but it does not reduce the base fee.
Different EVM chains can use different fee rules. Layer-2 networks may also add a separate fee for publishing transaction data to Ethereum. Check the wallet's fee breakdown instead of assuming that every displayed fee is only execution gas.
Exercise
A transaction uses 50,000 gas. The base fee is 30 gwei, the priority fee is 3 gwei, and the maximum fee is 40 gwei. What fee does it pay in ETH?
Show answer
The effective price is 33 gwei. The fee is 50,000 × 33 gwei = 1,650,000 gwei = 0.00165 ETH.