Create your own
Lesson illustration

Understanding Gas and EIP-1559

Hello! Welcome back to our course.

In the last lesson, we traced the entire lifecycle of a transaction, from its creation and signing to its final inclusion in the blockchain. We noted that a transaction's journey is powered by an economic incentive—the transaction fee—but we deferred the details. Today, we'll dive into that crucial topic.

The fee you pay for a transaction isn't arbitrary. It's determined by a sophisticated market mechanism designed to balance network security, usability, and economic sustainability. Understanding this is fundamental to building efficient and cost-effective applications on Ethereum.

Learning Outcome: By the end of this lesson, you will be able to analyze the factors determining transaction cost (gas) and the fee market mechanism (EIP-1559).

1. The Fundamentals of Gas

Before we can understand the market, we need to understand the product being sold: gas.

In the EVM, every single operation—from adding two numbers to writing data into storage—has a fixed cost. This cost isn't measured in ETH, but in a separate unit called gas. Gas is a measure of computational effort. A simple operation like ADD costs very little gas, while a complex one like creating a new contract or SSTORE (writing to storage) costs a lot.

The total fee you pay for a transaction is then calculated as:

  • Gas Used: The sum of the gas costs of all operations executed in your transaction.
  • Gas Price: The price you pay per unit of gas, denominated in ETH (usually in a smaller unit called Gwei, where 1 Gwei = ETH).

This separation of computational cost (gas) from monetary cost (ETH) is a key design choice. It allows the price of computation to float with network demand, independent of ETH's market price.

To get a clear overview of these core concepts, let's start with a short video.

What Is GAS? Ethereum HIGH Transaction Fees Explained

This video from Finematics provides an excellent animated explanation of what gas is, how it relates to transaction fees, and why it's a necessary component of the Ethereum protocol.

Please watch the segments from 00:22 to 03:44 and 05:05 to 07:30. Focus on: The distinction between gas cost (the fixed computational effort) and gas price (the market rate). The role of gas in preventing infinite loops (the halting problem) and Denial-of-Service (DoS) attacks.

As the video explains, when you send a transaction, you also set a gasLimit. This is the maximum amount of gas you are willing to let your transaction consume. It acts as a safety valve. If your transaction runs out of gas before completing, the EVM reverts all state changes but still consumes the gas used up to that point, and you pay the fee for the work done. If it completes using less gas than the limit, the unused gas is never charged.

2. The Old World: The First-Price Auction Problem

Prior to the London Hard Fork in August 2021, Ethereum's fee market operated on a simple first-price auction model. Users would specify a single gasPrice they were willing to pay. Validators (then miners) would look at the pool of pending transactions (the mempool) and prioritize those offering the highest gasPrice, as they kept 100% of the fee.

This led to several problems:

  • Fee Volatility: During periods of high demand (e.g., an NFT mint), users would get into bidding wars, causing gas prices to spike unpredictably.
  • Poor User Experience: It was difficult for wallets to estimate the "correct" gas price. Users had to choose between overpaying to get in quickly or risking a long wait time by bidding too low.
  • Inefficiency: Because it was a blind auction, many users ended up paying far more than the minimum price that would have secured their spot in the block.

To truly grasp these inefficiencies, it's helpful to think about the value validators were extracting. The following video provides a deep and insightful analysis of the pre-EIP-1559 market dynamics.

EIP1559: The Ethereum Fee Burn Explained

This video by Jordan McKinney offers a detailed breakdown of the problems with the first-price auction system. It introduces the concepts of 'auction MEV' and 'base MEV', which are useful for framing the economic inefficiencies that EIP-1559 was designed to solve.

Watch from 21:31 to 35:56. The speaker uses a great visual model to explain: The 'market clearing price' for inclusion in a block. How users overpay in a first-price auction (what he terms 'auction MEV'). The portion of the fee that is simply due to network congestion ('base MEV').

As you saw, the old system was not only inefficient for users but also created complex incentives for miners. The goal of a new system was to reduce the "auction MEV" (user overpayment) and do something more productive with the "base MEV" (the congestion fee).

3. EIP-1559: A Modern Fee Market

EIP-1559 completely redesigned the fee market to address the problems of the first-price auction. It introduced a new transaction type (0x02) and a new set of rules.

The core idea is to separate the transaction fee into two parts: a base fee and a priority fee (tip).

This diagram contrasts the old bidding system with the EIP-1559 model, highlighting the introduction of a burned base fee and a separate miner/validator tip.

3.1. Base Fee and Priority Fee

  • Base Fee (baseFeePerGas): This is a protocol-defined fee that is burned (destroyed), removing it from the ETH supply. It is the minimum price per unit of gas required for a transaction to be included in a block. Crucially, this fee is not set by the user but is calculated by the network for each block.
  • Priority Fee (maxPriorityFeePerGas): This is an optional "tip" that the user includes in their transaction. This fee goes directly to the validator as an incentive to prioritize their transaction over others.

The total price per gas a user pays is baseFeePerGas + priorityFeePerGas.

3.2. Dynamic Block Size and Base Fee Adjustment

The real innovation of EIP-1559 is how the baseFee is determined. The mechanism aims to keep blocks, on average, 50% full. Ethereum blocks have a gasLimit of 30 million gas, but the EIP-1559 mechanism targets a size of 15 million gas.

The baseFee for the next block is adjusted based on the size of the current block:

  • If the previous block was exactly 50% full (15M gas), the baseFee remains the same.
  • If the previous block was more than 50% full, the baseFee increases for the next block. The network is congested, so the price to get in goes up.
  • If the previous block was less than 50% full, the baseFee decreases. The network has spare capacity, so the price to get in goes down.

This creates a predictable, automated pricing mechanism. The baseFee can increase or decrease by a maximum of 12.5% per block, which smooths out volatility and makes fees much easier for wallets to estimate.

Given your background in radiophysics, you might find the underlying mechanics of this adjustment familiar. It is a classic example of a proportional controller, similar to how a thermostat regulates room temperature.

EIP1559: The Ethereum Fee Burn Explained

Let's return to the Jordan McKinney video for a deep dive into the EIP-1559 mechanism. He explains the dynamic block size and the control theory behind the base fee adjustment.

Watch from 35:56 to 01:01:20 and then from 01:02:29 to 01:13:26. This is a longer segment, but it's the core of the lesson. The first part (35:56 - 01:01:20) explains the overall design: the flexible block size, the role of the tip in full blocks, and the logic behind the maxFeePerGas and maxPriorityFeePerGas fields. The second part (01:02:29 - 01:13:26) delves into the control theory and the exact formula used to update the base fee. Pay close attention to the thermostat analogy and the mathematical breakdown of the update rule.

3.3. The Developer's Perspective

As a developer, you interact with this system through the transaction object. Instead of a single gasPrice, you now specify two values:

  • maxFeePerGas: The absolute maximum total fee (base + priority) you are willing to pay per unit of gas. Your transaction will fail if the block's baseFee exceeds this value.
  • maxPriorityFeePerGas: The maximum tip you are willing to pay the validator.

The actual tip paid will be min(maxPriorityFeePerGas, maxFeePerGas - baseFee). This ensures you never pay a tip that would push your total fee over your specified maxFeePerGas.

So, how do you determine what values to set? You can query a node for the fee history.

EIP-1559: Dynamic Fee Transactions Explained

This article by Andrey Obruchkov provides a practical look at EIP-1559 transactions from a developer's standpoint, including how to estimate the necessary fees.

Read the sections 'EIP-1559 Transaction: Dynamic Fee Transaction' and 'How to set the required fee'. Focus on: The structure of a type 0x02 transaction. The explanation of the eth_feeHistory RPC method and how its response can be used to estimate the next block's baseFee and a reasonable priorityFee.

3.4. Economic Implications: The ETH Burn

A major consequence of EIP-1559 is that the baseFee is burned, permanently removing that ETH from circulation. This ties network usage directly to the scarcity of ETH. During periods of high network activity, more ETH is burned. This can, at times, lead to the total ETH burned being greater than the ETH issued as rewards to validators, making ETH a deflationary asset.

EIP1559: The Ethereum Fee Burn Explained

To conclude our deep dive, let's briefly look at the economic side effect of this new fee market.

Watch the short segment from 01:15:45 to 01:18:23, which discusses how the burning mechanism can lead to negative net issuance of ETH.

Conclusion

We've covered a lot of ground, moving from the basic concept of gas to the sophisticated mechanics of the EIP-1559 fee market. This mechanism is a cornerstone of modern Ethereum, balancing the needs of users, developers, and validators.

Key Takeaways:

  • Gas is the unit of computational work, while the transaction fee is the monetary cost paid in ETH.
  • The pre-EIP-1559 first-price auction was inefficient and led to a poor user experience with volatile, unpredictable fees.
  • EIP-1559 introduced a base fee (burned) and a priority fee (tip for the validator).
  • The baseFee automatically adjusts based on block fullness, creating a more stable and predictable fee environment. This adjustment mechanism acts like a proportional controller.
  • As a developer, you now submit transactions with maxFeePerGas and maxPriorityFeePerGas to navigate this market.
  • The burning of the base fee introduces a deflationary pressure on ETH, linking network activity to its economic value.

In our next lesson, we will shift our focus from the network's mechanics to its participants. We will explore the two fundamental types of accounts on Ethereum: Externally Owned Accounts (EOAs) and Smart Contract Accounts, and analyze what makes them distinct.

Can't find a good explanation? Sign up and we'll make it for you

Sign up