Understanding the EVM (Ethereum Virtual Machine)
The Ethereum Virtual Machine (EVM) acts as a decentralized "world computer," enabling computational operations and data storage across the blockchain. It processes transactions—the fundamental units of interaction—where gas serves as the metric for resource consumption.
Key Concepts:
- Gas: Measures computational effort (e.g.,
MULcosts 5 gas,ADDcosts 3 gas). - Base Fee: Every transaction incurs a flat 21,000 gas fee, covering address recovery and storage costs.
Gas vs. Fuel: Terminology Breakdown
What Is Fuel?
- Synonym for Gas: Both terms refer to the computational "energy" required to execute operations on Ethereum.
Gwei: The Pricing Unit
- Conversion: 1 gwei = 0.000000001 ETH.
- Gas Price: Market-determined value (in gwei) per unit of gas.
Transaction Mechanics: StartGas and RemainingGas
StartGas (GasLimit)
- Definition: Prepaid gas allocated for a transaction.
Defaults:
- ETH transfers: 21,000 gas (usually sufficient).
- Smart contracts: May require higher limits (beware of exchanges defaulting to 21,000).
RemainingGas
- Post-Execution: Unused gas returned to the sender.
Fees Calculation:
Fees = (StartGas - RemainingGas) × Gas Price (in ETH)
Common Pitfalls and Solutions
Out of Gas Exception
- Issue: Transactions fail if StartGas depletes mid-execution; consumed gas isn’t refunded.
- Solution: Estimate gas needs accurately, especially for contract interactions.
Block Gas Limit (BGL)
- Current BGL: ~4.7 million gas (varies by network upgrades).
Transactions per Block:
BGL / Σ(StartGas of all transactions)
High StartGas Delays
- Why Avoid Overestimation?
Miners prioritize predictable small transactions (e.g., 100× 40,000 gas over 1× 4,000,000 gas).
Advanced Topics: Gas Refunds and Optimization
Gas Refund Mechanism
Actions Qualifying for Refunds:
- Cleaning storage slots: -15,000 gas.
- Self-destructing contracts: -24,000 gas.
- Cap: Refunds ≤ 50% of total gas used.
GasToken Strategies
- Purpose: Hedge against gas price volatility.
How It Works:
- Mint Tokens: Store data when gas prices are low.
- Burn Tokens: Delete data to claim refunds during price spikes.
- Variants: GST1 (storage-based) vs. GST2 (contract-based; more efficient).
👉 Learn how GasToken can slash your transaction costs
FAQs: Quick Answers to Common Questions
1. Why does Ethereum use gas?
Gas ensures fair resource allocation and compensates miners for computational work.
2. How is gas price determined?
By market demand—users bid higher prices during network congestion.
3. What happens if I set StartGas too low?
Your transaction fails ("Out of Gas"), and you lose the spent gas.
4. Can I get a full gas refund?
No—maximum refund is 50% of used gas (via eligible operations).
5. Is GasToken still viable?
Yes, especially GST2 for high gas-price differentials.
6. How does BGL affect transaction speed?
Lower BGL means fewer transactions per block, potentially increasing delays.