Lesson 2 of 4 Gas and Transaction Fees

Calculating Transaction Fees

Fee calculation is a core exam skill. This lesson explains the EIP-1559 fee market, the base fee, priority fee and max fee, how to calculate the fee a transaction pays and how legacy transactions differ.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the base fee, priority fee and max fee of EIP-1559.
  • Explain how the base fee changes between blocks.
  • Calculate the fee, the burned amount and the proposer's tip of a transaction.
  • Explain how legacy transactions are priced.

The EIP-1559 fee market

Before the London upgrade (August 2021), each transaction offered a single gas price in a first-price auction, which made fees volatile and hard to predict. EIP-1559 introduced a protocol-set base fee per gas for every block. The following terms describe the parts of a fee.

Base fee
Set by the protocol for each block from the previous block's usage. It is burned, removing ether from circulation.
Priority fee (tip)
The extra amount per gas the sender offers the block proposer to include the transaction.
maxPriorityFeePerGas
The highest tip per gas the sender will pay.
maxFeePerGas
The highest total price per gas (base fee plus tip) the sender will pay.
Effective gas price
What the sender actually pays per gas: min(maxFeePerGas, baseFee + maxPriorityFeePerGas).
Match the pairs

Parts of a fee

Exam skills 5.1.2

Match each part of an EIP-1559 fee with what it is.

Log in to try this activity Interactive activities are free with an account.

How the base fee moves

Each block has a gas target equal to half its gas limit. If a block uses more gas than the target, the next block's base fee rises, by up to 12.5% when the block is full; if it uses less, the base fee falls by up to 12.5%. Sustained demand therefore raises the base fee exponentially until some users stop sending, and quiet periods lower it. Because the change per block is bounded, wallets can predict the next base fee and set a max fee with headroom, commonly twice the current base fee plus the tip.

The following diagram shows the base fee changing with block fullness.

How the base fee moves. Each block has a gas target of half its gas limit. A full block raises the next block's base fee by 12.5%, a block exactly at the target leaves it unchanged, and an empty block lowers it by 12.5%. Because the change per block is bounded, wallets can predict the next base fee, commonly setting the max fee to twice the base fee plus the tip.
Values are illustrative, starting from 20 gwei.
Fill in the number

Predicting the base fee

Exam skills 5.1.2

Calculate how the base fee changes from one block to the next.

Log in to try this activity Interactive activities are free with an account.

Calculating the fee

The fee paid follows from the effective gas price.

effectiveGasPrice = min(maxFeePerGas, baseFee + maxPriorityFeePerGas)
fee               = gasUsed × effectiveGasPrice
burned            = gasUsed × baseFee
to proposer       = gasUsed × (effectiveGasPrice − baseFee)

The difference between maxFeePerGas and the effective price is never charged. If the current base fee exceeds maxFeePerGas, the transaction cannot be included until the base fee falls. Receipts report gasUsed and effectiveGasPrice, so the actual fee can always be computed afterwards.

The following diagram splits the price per unit of gas.

How the fee is calculated under EIP-1559. The effective gas price is the lower of maxFeePerGas and the base fee plus maxPriorityFeePerGas. The fee is gasUsed times the effective price. The base fee part is burned, and the rest, the tip, goes to the block proposer. Any difference between the max fee and the effective price is never charged. If the base fee exceeds the max fee, the transaction waits until it falls.
Values are illustrative.
Fill in the number

Calculating a fee

Exam skills 5.1.2

Calculate the effective gas price, fee and burn for a transaction.

Log in to try this activity Interactive activities are free with an account.

Legacy transactions and units

Legacy (type 0) transactions, which older material describes, have a single gasPrice field. Since London, they are treated as if both maxFeePerGas and maxPriorityFeePerGas equal gasPrice: the base fee is burned and everything above it goes to the proposer as a tip, so legacy transactions usually overpay.

Unit conversions are part of every calculation. The following table shows the units in use.

UnitWeiTypical use
wei1All on-chain amounts
gwei109Gas prices
ether1018Balances and values shown to users
Fill in the number

Units and legacy prices

Exam skills 5.1.2 · 1.2.1

Convert between wei, gwei and ether, and work out how a legacy transaction is split.

Log in to try this activity Interactive activities are free with an account.
Worked example

A complete fee calculation

A token transfer uses 51,000 gas. The block's base fee is 20 gwei; the transaction set maxPriorityFeePerGas to 2 gwei and maxFeePerGas to 50 gwei. What does the sender pay, how much is burned and how much does the proposer receive?

Effective gas price = min(50, 20 + 2) = 22 gwei. Fee = 51,000 × 22 = 1,122,000 gwei = 0.001122 ETH. Burned = 51,000 × 20 = 1,020,000 gwei = 0.00102 ETH. Proposer = 51,000 × 2 = 102,000 gwei = 0.000102 ETH. The 28 gwei per gas between 22 and the 50 gwei maximum is not charged.

Worked example

When the max fee is the limit

The base fee is 45 gwei. A transaction sets maxFeePerGas to 46 gwei and maxPriorityFeePerGas to 3 gwei, and uses 21,000 gas. What is its effective gas price, and what happens if the base fee rises to 48 gwei before it is included?

At a base fee of 45 gwei, the effective price is min(46, 45 + 3) = 46 gwei: the max fee caps it, so the proposer receives only 1 gwei per gas. The fee is 21,000 × 46 = 966,000 gwei. If the base fee rises to 48 gwei, above the max fee, the transaction cannot be included and waits in the mempool until the base fee falls to 46 gwei or below, or until the sender replaces it with a higher max fee.

Check yourself

Base fee 10 gwei, max priority fee 3 gwei, max fee 12 gwei. What is the effective gas price?

Show answer

12 gwei: min(12, 10 + 3). The max fee caps the price, so the proposer receives only 2 gwei per gas.

Exam Tips

Remember for the exam

  • Effective gas price = min(maxFeePerGas, baseFee + maxPriorityFeePerGas).
  • Fee = gasUsed × effective gas price; the base fee portion is burned, the tip goes to the proposer.
  • The base fee changes by at most 12.5% per block, around a target of half the block limit.
  • Legacy gasPrice acts as both max fee and max priority fee.
  • 1 gwei = 10^9 wei; 1 ether = 10^18 wei.