Sub topic 3
Ethereum and EVM Chains: Gas, Base Fee, and Priority Fee
This chapter assumes you know what a blockchain transaction is, can read basis points (1 bp = 0.01%), and can read short Python. It covers the on-chain cost of a transfer, then the exchange costs that sit around it.
Gas, Base Fee, and Priority Fee
Gas is the unit that measures work done by a transaction. A plain ETH transfer uses 21,000 gas. The price per unit of gas is set in gwei (1 gwei = 0.000000001 ETH).
The base fee is set by the protocol and changes with block demand. It is burned, so no one receives it. The priority fee (tip) goes to the validator who includes your transaction. Your max fee is a ceiling you will not exceed. The price you pay is the lower of the max fee and the base fee plus the tip.
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 round(gas_used * gas_price_gwei * GWEI / WEI_PER_ETH, 6)
print(evm_fee_eth(21_000, 20, 2, 50)) # 0.000462Why Exchange Withdrawal Fees Differ From On-Chain Fees
An exchange sets its withdrawal fee from a published schedule. The network fee depends on congestion when you send. The two numbers rarely match. An exchange may charge more than the network cost, or absorb a cost when congestion is high.
| Cost | Set by | Changes with |
|---|---|---|
| Exchange withdrawal fee | Exchange schedule | Rarely, when the exchange updates it |
| Network fee | Block demand | Congestion at send time |
Fee Discounts, Rebates, and Their Trade-offs
Exchanges reduce trading fees through volume tiers, discounts for paying fees in the exchange's own token, and referral rebates. These lower costs, but they can require locking funds, holding a token whose price moves, or trading more than you otherwise would. Check whether a discount still helps after those trade-offs.
Futures and Perpetuals: Funding and Other Costs
A perpetual futures contract has no expiry, so it uses a funding payment to keep its price near the spot price. Longs and shorts exchange payments at set intervals, often every eight hours. Your funding cost equals the funding rate times your position size. Liquidation fees apply if your margin falls too low.
Computing the Total Cost of a Trade
Add the spread, the fees on each side, and slippage. The spread is paid once across a round trip, so it appears once in the total.
def round_trip_cost_bps(spread_bps, fee_bps_each_side, slippage_bps_each_side=0.0):
return spread_bps + 2 * fee_bps_each_side + 2 * slippage_bps_each_side
print(round_trip_cost_bps(2, 20)) # 42.0
print(round_trip_cost_bps(2, 20, 3)) # 48.0Practical Ways to Lower Your Costs
- Place limit orders that rest on the book to qualify as maker orders.
- Compare total cost, not only the quoted fee, before using instant buy.
- Batch withdrawals to reduce the number of fixed withdrawal fees.
- Send on-chain when network fees are low.
Exercise
A transaction uses 21,000 gas. The base fee is 30 gwei, the priority fee is 1 gwei, and the max fee is 25 gwei. What is the fee in ETH?
Show answer
The price is min(25, 30 + 1) = 25 gwei. The fee is 21,000 × 25 gwei = 525,000 gwei = 0.000525 ETH.