Detailed Explanation of Ethereum Gas Mechanism (EIP-1559)

ยท

Introduction to Gas

Gas in Ethereum measures the computational resources required to execute smart contracts and transactions. It serves three key purposes:

  1. Preventing network abuse
  2. Ensuring efficient transaction processing
  3. Maintaining network health through fair resource allocation

Each operation consumes a specific amount of Gas, paid for by users via GasPrice. Think of Ethereum as a worker - Gas represents the labor expended, while GasPrice is the wage per unit of work.

Key Gas Concepts

EIP-1559 Transaction Structure

A typical EIP-1559 transaction contains these components:

ComponentDescription
Gas Limit & UsageShows GasLimit vs actual consumption
Gas FeesIncludes Base and Priority fees
Burnt FeesPortion permanently removed from circulation
Txn SavingsDifference between max and actual fees

Example transaction type: 2 (EIP-1559) as defined by EIP-2718.

BaseFee Mechanism

Introduced by EIP-1559, BaseFee dynamically adjusts to network congestion. Key characteristics:

Calculation Formula

BaseFee change = parentBaseFee * (GasUsedDelta / parentGasTarget) / 8

Where:

๐Ÿ‘‰ See live BaseFee adjustments on Etherscan

Priority Fees (MaxPriorityFeePerGas)

This voluntary tip to miners determines transaction priority. Key points:

MaxFee Protection

The maximum price users are willing to pay, calculated as:

MaxFee = (2 * BaseFee) + MaxPriorityFee

This ensures transactions remain valid through multiple blocks even if BaseFee rises.

Fee Economics

Burnt Fees

Transaction Savings

Savings = (MaxFee * GasUsed) - Actual Fee Paid

JSON-RPC Methods

Developers can access Gas parameters through these Ethereum node methods:

eth_estimateGas

eth_maxPriorityFeePerGas

eth_getBlockByNumber

๐Ÿ‘‰ Learn more about Ethereum's fee market

FAQs

Why did Ethereum implement EIP-1559?

To create more predictable gas fees and introduce a deflationary mechanism through fee burning.

How often does BaseFee change?

Every block (approximately every 12-15 seconds).

What happens if I set MaxPriorityFee too low?

Your transaction may take longer to process or get stuck during network congestion.

How is the burnt fee calculated?

Burnt Fee = BaseFee * GasUsed in the transaction.

Can I get a refund if BaseFee decreases?

Yes, you'll pay the current lower rate and receive the difference back.

Why use MaxFee instead of just GasPrice?

MaxFee protects against sudden BaseFee spikes while still allowing you to benefit from decreases.