Sub topic 7
Ether as Fuel: Gas, Base Fee, and Priority Fee
This chapter assumes you understand public and private keys, wallets, and the basic idea of a blockchain. You should also be comfortable reading short Python programs. The goal is to calculate an Ethereum transaction fee and understand where each part goes.
Gas measures computation
Ethereum transactions do more than transfer ether. They can call smart contracts, change stored data, or create new contracts. Each operation consumes computational resources. Gas is the unit used to measure that work.
A simple ether transfer uses a standard amount of 21,000 gas. A contract call usually uses more. The amount depends on the operations performed and the data they change.
Gas is not itself money. The fee is calculated as:
transaction fee = gas used × price per unit of gas
Ethereum measures gas prices in gwei. One gwei is 1 billion wei, and one ether is 10^18 wei. Wei is Ethereum's smallest accounting unit.
The EIP-1559 fee model
Ethereum's current fee model separates the gas price into two main parts:
| Part | Set by | What happens to it |
|---|---|---|
| Base fee | Protocol rules | Burned, or permanently removed |
| Priority fee | User and market conditions | Paid to the validator as a tip |
The base fee changes from block to block. It rises when recent blocks are crowded and falls when demand is lower. The protocol adjusts it toward a target block usage level.
The priority fee encourages a validator to include a transaction. A user can offer a larger tip when quick inclusion matters. The validator receives this tip, but does not receive the base fee.
A transaction also specifies a maximum fee per gas. This is the most the sender is willing to pay per unit. If the maximum is too low for current conditions, the transaction waits or becomes invalid for inclusion. The sender pays for the gas actually used, not the entire gas limit. Unused gas from the limit is returned.
Worked fee calculation
Suppose a plain transfer uses 21,000 gas. The base fee is 20 gwei, and the priority fee is 2 gwei.
- Burned amount: 21,000 × 20 gwei = 420,000 gwei = 0.00042 ETH
- Validator tip: 21,000 × 2 gwei = 42,000 gwei = 0.000042 ETH
- Total fee: 0.000462 ETH
The recipient receives the transferred ether separately. The fee is charged to the sender's account.
WEI_PER_GWEI = 10**9
WEI_PER_ETH = 10**18
gas_used = 21_000
base_fee_gwei = 20
priority_fee_gwei = 2
burned_wei = gas_used * base_fee_gwei * WEI_PER_GWEI
tip_wei = gas_used * priority_fee_gwei * WEI_PER_GWEI
total_wei = burned_wei + tip_wei
print(burned_wei / WEI_PER_ETH)
print(tip_wei / WEI_PER_ETH)
print(total_wei / WEI_PER_ETH)The output is approximately 0.00042, 0.000042, and 0.000462.
Exercise
A transaction uses 50,000 gas. The base fee is 10 gwei and the priority fee is 1 gwei. What total fee does the sender pay in ETH?
Show answer
The total price is 11 gwei per gas. The fee is 50,000 × 11 gwei = 550,000,000,000,000 wei = 0.00055 ETH.