Sub topic 12
Ethereum and EVM Chains: Gas, Base Fee, and Priority Fee
This chapter assumes you know what a blockchain transaction is, can read gwei and ETH amounts, and can follow short Python snippets. The previous chapters covered how fee markets set the price of block space. Here we apply that to Ethereum and the chains that copy its execution model, the EVM (Ethereum Virtual Machine) chains.
Gas: the unit of work
Every operation the EVM runs costs a fixed amount of gas. Gas measures computation and storage work, not money. A plain ETH transfer costs 21,000 gas. A token transfer or a swap on a decentralized exchange runs more code, so it costs more. An ERC-20 transfer typically uses a few tens of thousands of gas, and a swap often uses well over 100,000.
The fee has two parts:
- Gas used: how much work your transaction actually consumed.
- Gas price: how much you pay per unit of gas, quoted in gwei. One gwei is 10^9 wei, and 10^18 wei is one ETH.
The fee in ETH is gas used multiplied by gas price. A complex transaction at a low price can cost the same as a simple one at a high price.
The three price fields
Since EIP-1559, an Ethereum transaction carries these fields:
| Field | Set by | Meaning |
|---|---|---|
| Gas limit | Sender (wallet estimates it) | Most gas the transaction may consume |
| Max fee per gas | Sender | Highest total price per gas unit the sender accepts |
| Max priority fee per gas | Sender | Highest tip per gas unit offered to the block producer |
| Base fee | Protocol | Per-block price every transaction must pay, burned |
The effective gas price is:
effective_gas_price = min(max_fee, base_fee + max_priority_fee)The base fee is destroyed (burned), so no one collects it. The part of the price above the base fee goes to the validator that includes your transaction. That part is the priority fee, or tip.
Worked calculation
Suppose the base fee is 20 gwei, you offer a 2 gwei priority fee, and you set a max fee of 50 gwei. The effective price is min(50, 22) = 22 gwei. A 21,000-gas transfer then costs 21,000 × 22 gwei = 462,000 gwei, which is 0.000462 ETH.
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
def split_fee_eth(gas_used, base_fee_gwei, priority_fee_gwei, max_fee_gwei):
price = min(max_fee_gwei, base_fee_gwei + priority_fee_gwei)
if price < base_fee_gwei:
raise ValueError("max fee is below the base fee: transaction cannot be included")
burned = gas_used * base_fee_gwei * GWEI / WEI_PER_ETH
tip = gas_used * (price - base_fee_gwei) * GWEI / WEI_PER_ETH
return burned, tip
# A plain ETH transfer uses 21,000 gas.
print(evm_fee_eth(21_000, 20, 2, 50)) # about 0.000462 ETH
print(split_fee_eth(21_000, 20, 2, 50)) # about (0.00042, 0.000042) ETH
# The wallet reserves gas_limit * max_fee up front, then refunds the difference.
print(21_000 * 50 * GWEI / WEI_PER_ETH) # about 0.00105 ETH held, 0.000462 chargedOf the 0.000462 ETH, about 0.00042 ETH is burned and 0.000042 ETH goes to the validator. Your wallet checks that you can cover the maximum (gas limit × max fee) before it sends, but you pay only the effective price.
How the base fee moves
The protocol targets blocks that are half full. The target is half of the block gas limit. After each block, the base fee changes by up to 12.5%:
- A completely full block raises the next base fee by 12.5%.
- A block at the target leaves it unchanged.
- An empty block lowers it by 12.5%.
The change scales in proportion for blocks in between.
def next_base_fee(base_fee, gas_used, gas_target):
return base_fee * (1 + (gas_used - gas_target) / gas_target / 8)
base = 20.0
target = 15_000_000
for _ in range(6): # six completely full blocks in a row
base = next_base_fee(base, 2 * target, target)
print(round(base, 1)) # about 40.5 gwei: roughly doubledSix full blocks take about 72 seconds on Ethereum mainnet, so a demand spike can double the base fee in little more than a minute. The reverse also holds, and quiet periods let it fall quickly. The real protocol uses integer arithmetic, so its numbers differ slightly from this float model.
Gotchas and edge cases
- Gas limit is not the fee. If a transaction uses less gas than its limit, you pay only for what it used. Setting a high limit does not raise the cost of a transaction that succeeds.
- Failed transactions still cost money. If a contract call reverts or runs out of gas, the validator still did the work. You pay for the gas consumed up to the failure, and the transaction's effects are undone.
- Max fee below the base fee stalls the transaction. It stays pending until the base fee falls below your max fee, or you replace it. To replace it, resend with the same nonce and higher fees.
- A tip is only worth paying for priority. The base fee is mandatory. The tip decides your place among competing transactions in the same block. When blocks have room, a small tip is enough.
- The tip can shrink. If max fee minus base fee is less than your priority fee, you pay only the smaller amount. A tight max fee can therefore reduce your tip without warning.
- Wallet estimates can be wrong. Wallets guess the gas limit by simulating the call. Contract state can change between simulation and inclusion, so a transaction near its limit can fail.
Other EVM chains
Many chains run the EVM and quote fees in gas, but the fee token and the pricing rules differ.
- Layer 2 networks (such as Arbitrum, Optimism, and Base) charge an L2 execution fee, which is gas × price and usually small. They also charge an L1 data fee for posting your transaction data to Ethereum. During busy periods on Ethereum, the L1 data part can dominate your L2 fee.
- Sidechains and other L1s (such as BNB Chain and Polygon) pay fees in their own token. Some use EIP-1559-style base fees and some use simpler gas-price rules. Gas used for the same contract call is generally the same across EVM chains. The price per gas and the value of the fee token differ.
- Always check the chain and token. Sending a transaction on the wrong network can cost fees without reaching the destination you intended.
Connecting this to the total cost
The network fee is a flat per-transaction cost, not a percentage of the amount. A 0.000462 ETH fee is the same whether you move 50 dollars or 50,000 dollars of value. That makes it large relative to small trades and negligible relative to large ones. When you add costs into one effective price, as in the total-cost chapter, convert the fee to the quote currency at the current ETH price. Then compare it to the notional in basis points.
Exercise
The base fee is 30 gwei. You send a 65,000-gas token transfer with a max priority fee of 3 gwei and a max fee of 32 gwei. (a) What is the effective gas price? (b) What is the total fee in ETH? (c) How much of it is burned, and how much goes to the validator?
Show answer
(a) The effective price is min(32, 30 + 3) = 32 gwei. The tip is capped at 32 - 30 = 2 gwei. (b) The fee is 65,000 × 32 gwei = 2,080,000 gwei = 0.00208 ETH. (c) The burned part is 65,000 × 30 gwei = 1,950,000 gwei = 0.00195 ETH. The validator receives 65,000 × 2 gwei = 130,000 gwei = 0.00013 ETH.
Exercise
A block is completely full (gas used is twice the target) and the base fee is 40 gwei. What is the base fee of the next block, approximately, and what happens to a pending transaction whose max fee is 42 gwei?
Show answer
The next base fee is about 40 × 1.125 = 45 gwei. The pending transaction's max fee of 42 gwei is now below the base fee, so it cannot be included until the base fee falls back below 42 gwei or the sender replaces it with higher fees.