Ethereum Gas Optimization: Save Money on Every Transaction
Gas fees can make or break your DeFi returns. A $50 swap that costs $30 in gas is a disaster. Master gas optimization to keep more of your profits—and make smaller trades viable.
- Time transactions for weekends/early mornings—gas can be 5-10x cheaper.
- Use L2s for 90%+ savings; batch operations when possible.
- Thrive alerts when gas hits your target price and optimizes transaction timing.
Gas Cost Calculator
Calculate transaction costs and find optimal times to transact:
Estimated Costs
Best Times to Transact
Pro Tips: Use L2s for 90%+ gas savings. Batch transactions when possible. Set gas alerts for your target price. For large trades, aggregator gas costs are often offset by better rates.
Gas Fundamentals
Understanding gas mechanics is the first step to optimization. Gas isn't arbitrary—it's a market for computational resources.
The Gas Formula
Transaction Cost = Gas Used × Gas Price (in Gwei) × ETH Price
Example:
Swap uses 150,000 gas
Gas price: 30 Gwei
ETH price: $2,000
Cost = 150,000 × 30 × 10^-9 × $2,000 = $9.00
What Determines Gas Used
- Simple transfer: 21,000 gas (the minimum)
- ERC-20 transfer: ~65,000 gas
- Token approval: ~46,000 gas
- Simple swap: 100,000-200,000 gas
- Complex swap (aggregator): 300,000-600,000 gas
- LP deposit: 200,000-400,000 gas
- NFT mint: 100,000-300,000 gas
What Determines Gas Price
Gas price is set by market demand. More users wanting transactions = higher prices.
- Base fee: Protocol-determined, adjusts based on block utilization
- Priority fee (tip): You set this to incentivize faster inclusion
- Max fee: Maximum you're willing to pay total
Post-EIP-1559, most wallets handle this automatically, but you can adjust for urgency.
Key Insight: You control when you transact (gas price) but not how complex the operation is (gas used). Optimization means timing transactions for low prices and choosing gas-efficient protocols.
Timing Your Transactions
Gas prices follow predictable patterns. Learn them and save money.
Weekly Patterns
- Lowest: Saturday and Sunday, especially early morning UTC
- Medium: Monday-Thursday outside business hours
- Highest: Weekdays during US market hours (2-10pm UTC)
Daily Patterns
- Lowest: 2-6am UTC (Asia sleeping, US late night)
- Rising: 6-12pm UTC (Asia waking, EU morning)
- Highest: 2-10pm UTC (US market hours)
- Dropping: 10pm-2am UTC (US evening)
Event-Driven Spikes
Avoid transacting during:
- NFT mints (gas can spike to 200+ Gwei)
- Major token launches or airdrops
- Market volatility (cascading liquidations)
- Ethereum network upgrades
Setting Up Alerts
Rather than constantly checking, set alerts:
- Determine your target gas price (e.g., <20 Gwei)
- Set up alerts via Thrive, Etherscan, or gas bots
- When alert triggers, execute your queued transactions
- Batch multiple transactions in low-gas windows
| Network | Avg Gas Cost | Speed | Best For | Savings vs Mainnet |
|---|---|---|---|---|
| Ethereum | $5-50+ | 12-60s | Large trades, NFTs | Baseline |
| Arbitrum | $0.10-0.50 | 2-5s | Most DeFi | 90-95% |
| Optimism | $0.10-0.50 | 2-5s | Most DeFi | 90-95% |
| Base | $0.05-0.25 | 2-5s | Consumer apps | 95-98% |
| Polygon | $0.01-0.05 | 2-5s | Gaming, NFTs | 99%+ |
Migrating to Layer 2s
The single biggest gas optimization: move to L2s. Most DeFi now lives on Arbitrum, Optimism, and Base.
L2 Economics
L2s batch transactions and post compressed data to Ethereum. Users share the cost of data posting, making individual transactions cheap.
Mainnet swap: $15
Arbitrum swap: $0.25
Savings per swap: $14.75
Break-even on bridge: ~1-2 swaps
When to Stay on Mainnet
- Liquidity for your pair is thin on L2s
- Protocol doesn't exist on L2 yet
- Very large trades where slippage on L2 exceeds gas savings
- NFTs that only exist on mainnet
Bridge Strategy
- Bridge during low gas periods (weekends)
- Bridge larger amounts less frequently (amortize bridge costs)
- Use native bridges for security or fast bridges for convenience
- Keep some ETH on mainnet for emergencies
L2 Selection
Arbitrum: Largest DeFi TVL, best liquidity, most protocols
Optimism: Strong ecosystem, OP token incentives, good for newer protocols
Base: Coinbase-backed, growing fast, lowest fees in OP stack
Polygon: Cheapest fees, but technically a sidechain, not true L2
Protocol-Level Optimization
Choose Gas-Efficient Protocols
Not all protocols are equal. Some are heavily optimized:
- Uniswap V3 vs V2: V3 swaps are more gas-efficient for same-pair swaps
- Native swaps vs aggregators: For simple swaps, direct is cheaper
- Permit vs Approve: Permit saves an approval transaction
Batch Operations
Combine multiple actions into single transactions:
- Multicall: Many protocols support multicall for batching
- Flashbots bundles: Bundle multiple transactions together
- Account abstraction: Smart accounts can batch operations
Permit2 and Gasless Approvals
Modern protocols use Permit2 for gasless token approvals:
- Sign an off-chain message instead of on-chain approval
- Saves 46,000 gas per approval
- Used by Uniswap, 1inch, and others
Token Approval Strategy
For frequently used tokens:
- Approve unlimited (once) during low gas
- Save approval gas on every future transaction
- Trade-off: Security risk if protocol is compromised
For infrequent or new protocols:
- Approve exact amounts
- Revoke approvals after use
- Worth the extra gas for security
Advanced Gas Techniques
Flashbots Protect
Using Flashbots Protect RPC:
- Transactions go directly to block builders (skip mempool)
- No front-running or sandwich attacks
- Transactions that revert don't cost gas
- Can be slower (waits for builder to include)
Gas Price Bidding Strategies
For non-urgent transactions:
- Set max fee slightly below current base fee
- Transaction sits in mempool until gas drops
- May take hours/days; cancel if needed urgently
For time-sensitive transactions:
- Set max fee 20-50% above current base fee
- Higher priority fee for faster inclusion
- Use gas now trackers for real-time pricing
Failed Transaction Recovery
If a transaction fails (reverts):
- Understand why it failed before retrying
- Use Tenderly to simulate before submitting
- Failed transactions still cost gas (for computation done)
- Cancel pending transactions by sending 0 ETH to yourself with same nonce
Gas Cost Tracking
Track your gas spending:
- Export transaction history from Etherscan
- Calculate total gas spent monthly
- Identify high-gas activities to optimize
- Factor gas into trade P&L calculations
Frequently Asked Questions
What determines Ethereum gas fees?
Gas fees = Gas Used × Gas Price. Gas used depends on transaction complexity (simple transfers use less than complex DeFi operations). Gas price depends on network demand. When Ethereum is busy, gas prices spike as users compete for block space.
What is the best time to transact for low gas?
Weekends and early mornings (UTC) typically have lowest gas. US business hours and weekday evenings see highest demand. Use gas trackers to find optimal times. Set gas price alerts at your target level and transact when triggered.
How much can I save by timing transactions?
Gas prices can vary 5-10x between peak and low periods. A $50 transaction during high gas could cost $5-10 during low gas. Over many transactions, timing saves hundreds or thousands of dollars annually.
Should I use Layer 2s instead of Ethereum mainnet?
For most DeFi activities, yes. L2s like Arbitrum and Optimism offer 90-95% gas savings with comparable functionality. Use mainnet only when L2 liquidity is insufficient or for specific mainnet-only protocols. Bridge costs once; save on every transaction after.
What is EIP-1559 and how does it affect gas?
EIP-1559 introduced base fee (burned) and priority fee (to validators). Base fee adjusts automatically based on block fullness. You can set max fee and max priority fee. This makes gas more predictable and reduces overpaying, but doesn't lower average fees.
How do I estimate gas for a transaction?
Wallets estimate gas automatically, but often overestimate to ensure success. For manual estimation, simulate the transaction (Tenderly), check similar recent transactions, or use protocol documentation. Complex DeFi can use 300K-1M+ gas.
What are gas tokens and do they still work?
Gas tokens (CHI, GST2) exploited gas refunds by storing data cheaply and deleting it for refunds during high gas. EIP-3529 significantly reduced refunds, making gas tokens largely obsolete. Don't use them—they're no longer effective.
How do aggregators affect gas costs?
Aggregators find better prices but use more gas (complex routing). For small trades, direct swaps may be cheaper overall. For large trades, aggregator savings usually exceed extra gas. Compare total cost (output - gas) not just gas.