Introduction to Gas in Ethereum
Gas refers to the computational work required to execute specific operations on the Ethereum network. Every transaction consumes resources, necessitating a fee paid in Ether (ETH). Gas fees are denominated in Gwei (1 Gwei = 0.000000001 ETH), a subunit of ETH, simplifying cost communication (e.g., "1 Gwei" vs. "0.000000001 ETH").
Key Concepts:
- Wei: The smallest ETH unit (1 Gwei = 1 billion Wei).
- Purpose: Gas fees secure the network by preventing spam and incentivizing miners.
Gas Fee Calculation: Pre-London Upgrade
Before August 2021, fees were calculated as:
Total Fee = Gas Units (Limit) × Gas Price per Unit
Example:
- Transaction: Alice sends Bob 1 ETH.
- Gas Limit: 21,000 units.
- Gas Price: 200 Gwei.
- Fee: 21,000 × 200 = 4,200,000 Gwei (0.0042 ETH).
Post-London Upgrade: EIP-1559
The London Upgrade introduced a new fee structure:
- Base Fee: Dynamically adjusted per block, burned (removed from circulation).
- Priority Fee (Tip): Paid to miners for transaction inclusion.
- Max Fee (maxFeePerGas): User-specified ceiling; excess is refunded.
Formula:
Total Fee = Gas Units × (Base Fee + Priority Fee)
Example:
- Gas Limit: 21,000 units.
- Base Fee: 10 Gwei.
- Tip: 2 Gwei.
- Fee: 21,000 × (10 + 2) = 252,000 Gwei (0.000252 ETH).
- Refund:
maxFeePerGas - (Base Fee + Tip)
.
Variable Block Sizes and Base Fee Adjustment
- Target Block Size: 15 million gas.
- Max Block Size: 30 million gas (2× target).
Base Fee Adjustment:
- Increases by up to 12.5% if the previous block exceeded the target.
- Decreases if below target.
Example Base Fee Progression:
Block | Gas Used | Adjustment | New Base Fee |
---|---|---|---|
1 | 15M | 0% | 100 Gwei |
2 | 30M | 12.5% | 112.5 Gwei |
Priority Fee (Tip) and Miner Incentives
- Miners receive tips, motivating them to include transactions.
- Higher Tips = Faster Inclusion.
Advanced Topics
Fuel Limit and User Control
- Standard ETH Transfer: 21,000 gas limit.
- Smart Contracts: Higher limits due to complexity.
- Setting Limits Too Low: Transactions fail; gas is still consumed.
Why High Gas Fees?
- Network demand > Block space supply.
- Users bid higher tips for priority.
Reducing Gas Costs
Strategies:
- Set Lower Tips: For non-urgent transactions.
- Layer-2 Solutions: Scalability enhancements (e.g., Arbitrum, Polygon).
- Monitor Tools: Use gas estimators to time transactions.
Recommended Tools:
👉 Etherscan Gas Tracker
👉 ETH Gas Station
FAQ Section
Q1: What happens if I set maxFeePerGas too low?
A: The transaction won’t execute until the base fee falls below your max fee.
Q2: Can gas fees be refunded?
A: Yes! Excess maxFeePerGas
(above base + tip) is refunded.
Q3: Why are tips necessary?
A: They compensate miners after base fees are burned.