Overview
After Ethereum's London upgrade, the network implemented EIP1559 for gas calculation. This introduced a more complex gas mechanism, which we'll explore in detail here.
Key topics covered:
- New
gas pricestructure underEIP1559 - Transaction fee calculation methods
Note: This article refers to "miners" as the merge was imminent during writing.
Core Concepts
Gas vs. Gas Price
Gas:
- The computational "fuel" for Ethereum transactions (transfers or smart contract operations).
- Each opcode has a fixed gas cost (e.g., ETH transfers consume
21,000gas, as seen in this transaction). - Tools like Foundry (
forge test --gas-report) generate gas reports for contracts:
| Contract Method | Gas Used |
|---|---|
| deploy | 1,200,000 |
| transfer | 21,000 |
Gas Price:
- Dynamic value (in ETH) paid per unit of gas.
Transaction fee formula:
Fee = Gas Used Γ Gas Price
π Understand Ethereum gas like a pro
Gas Limit Estimation
Ethereum provides the eth_estimateGas RPC API to predict gas requirements.
Example 1: ETH Transfer
Request:
{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"from": "0x8D976...",
"to": "0xd3CdA...",
"value": "0x186a0"
}],
"id": 0
}Response:
{
"jsonrpc": "2.0",
"result": "0x5208", // 21,000 in decimal
"id": 0
}Example 2: Smart Contract Interaction
For WETH deposits (deposit() function):
{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{
"to": "0xC02aaA...",
"data": "0xd0e30db0" // deposit() function selector
}],
"id": 1
}Key Takeaways
Gas Limits
- Transactions fail if
Gas Limit < Actual Gas Used(e.g., this failed call). - Unused gas is refunded.
- Transactions fail if
EIP1559 Updates
- Introduces a base fee + priority tip model.
- Reduces fee volatility and improves UX.
π Master Ethereum transactions today
FAQ
Q: Why does ETH transfer cost exactly 21,000 gas?
A: Itβs a fixed cost for simple transfers without contract logic.
Q: How is gas price determined post-EIP1559?
A: A base fee (burned) + priority tip (to miners).
Q: Can I estimate gas without running a transaction?
A: Yes, using eth_estimateGas or tools like Foundry.