Between 2020 and 2022, Ethereum gas fees cost DeFi users an estimated $5–10 billion in transaction overhead. At peak network congestion, a simple Uniswap swap cost $200 in gas. A more complex DeFi interaction — entering a leveraged yield farming position, for instance — could exceed $500. While Layer 2 networks have transformed the economics for most retail activity, Ethereum mainnet fees remain significant for large transactions, and gas optimisation skills pay real dividends for anyone using Ethereum seriously. This guide covers every lever available to both users and developers.
Understanding What You're Paying: EIP-1559 Mechanics
Since August 2021's London upgrade, every Ethereum transaction pays two components. The base fee is set algorithmically by the protocol based on how full recent blocks were — it rises when blocks exceed 50% utilisation and falls when blocks are less than 50% full, adjusting by up to ±12.5% per block. Critically, the base fee is burned entirely: it does not go to validators. This makes ETH deflationary during high-usage periods and creates a self-regulating fee mechanism. The priority fee (tip) goes directly to the validator including your transaction. Your wallet asks you to set a max fee (the most you'll ever pay in total) and max priority fee (your tip). The actual fee is: base fee + min(your priority fee tip, your max fee minus the base fee). Any unused portion is refunded.
In practice: when MetaMask or Rabby shows you "Low / Medium / High" gas options, it's estimating the base fee trajectory over the next few blocks and suggesting priority fee levels. You can override these manually. During low-congestion periods, a priority tip of 0.1–0.5 gwei above base fee is sufficient to get included in the next block; at peak congestion, tips of 2–10 gwei may be needed to compete. The key insight: the base fee is the large component and varies by 10–50x across the day; the priority fee is small and relatively constant.
Timing: The Free Gas Optimisation
Ethereum network utilisation follows consistent daily and weekly patterns driven by global user activity. The cheapest periods: Sunday mornings UTC through Monday morning (US users asleep, Asian sessions less active), and weekday nights UTC (00:00–08:00 UTC). The most expensive: weekday afternoons UTC (12:00–20:00 UTC) when European afternoon and North American morning sessions overlap, and during any major news events, token launches, or NFT mints that generate surge demand.
During off-peak hours, base fees routinely fall below 5 gwei on Ethereum mainnet — sometimes as low as 1–2 gwei during very quiet periods. Compared to peak hours at 30–100+ gwei, the cost differential for a non-urgent transaction is 10–50x. A complex DeFi transaction costing $50 at peak times costs $1–5 during off-peak hours. For any transaction that doesn't need to execute immediately — routine DCA purchases, moving funds to cold storage, harvesting yield positions, governance votes — scheduling during off-peak hours is the single highest-impact gas optimisation with zero trade-off cost.
Tools: Etherscan Gas Tracker (etherscan.io/gastracker) shows current base fee and a 7-day hourly average chart, making it easy to identify recurring low-fee windows for your timezone. The Chrome extension Blocknative Gas Estimator overlays current and predicted gas costs in your browser.
The Primary Solution: Move to Layer 2
For most DeFi activity — swaps, lending, yield farming, NFT trading — moving to Layer 2 is the most impactful gas optimisation by far. Arbitrum, Optimism, Base, and zkSync Era offer transaction fees of $0.01–0.10, representing a 99%+ reduction versus Ethereum mainnet for equivalent operations. All major DeFi protocols are deployed on at least one major L2: Uniswap (all L2s), Aave (Arbitrum, Optimism, Base), Curve (Arbitrum, Optimism), Compound (multiple L2s), GMX (Arbitrum, Avalanche).
The one-time cost of bridging from Ethereum mainnet to an L2 (one mainnet transaction, typically $5–15 in gas) is amortised within a few transactions on L2. After bridging $1,000 of assets to Arbitrum, the first 10 Arbitrum swaps at $0.05 each cost $0.50 total versus $500+ on mainnet — the bridge cost is recovered within the first interaction. The workflow is simple: use Arbitrum Bridge (bridge.arbitrum.io), Optimism Bridge, or a third-party bridge aggregator like Li.fi or Across Protocol. Assets appear on the L2 within minutes; bridge back to mainnet when needed (note: Optimistic Rollup bridges have a 7-day challenge period for native bridge withdrawals — use fast bridge services like Across Protocol for same-day mainnet withdrawal if needed).
Choosing between L2s in 2026: Arbitrum for deepest DeFi liquidity, Optimism/Base for Coinbase users and OP Stack ecosystem, zkSync Era for immediate withdrawal finality without fast bridge services. For day-to-day DeFi, any of the top L2s provides equivalent cost savings — pick the one where your preferred protocols are deployed.
Approval Management: From Two Transactions to One
A frequently overlooked gas cost: ERC-20 token approvals. Before any DeFi protocol can spend your tokens, you must first send an approval transaction granting permission — a separate transaction costing gas before you even do the intended operation. The traditional flow is: approve (one transaction) + execute (one transaction) = two gas payments for every new token/protocol pair. At $10/transaction this is $20 overhead per new interaction — substantial for small positions.
EIP-2612 Permit signatures solve this: instead of an on-chain approval transaction, you sign an off-chain message authorising the spending, and this signature is included directly in the execution transaction. No separate approval transaction needed. The result: approve + execute collapses to a single transaction. Uniswap v3 Permit2, Aave v3, and most modern DeFi protocols support this. Always choose permit-based flows when your wallet and protocol offer them — look for "Sign and Swap" or "Permit" options in the UI rather than "Approve and Swap."
For existing approvals: audit your outstanding approvals using Revoke.cash or Etherscan's token approval checker. Revoking unlimited approvals to protocols you no longer use is both a gas management improvement (fewer attack vectors) and security hygiene — exploited protocols can drain any wallet that has granted unlimited approval.
Transaction Batching and Smart Contract Wallets
Every Ethereum transaction pays 21,000 gas as a flat base cost for the transaction itself, regardless of what it does. If you need to perform three operations (three separate transactions), you pay 21,000 × 3 = 63,000 gas in base overhead alone. Batching these into a single transaction via a multicall or smart contract wallet pays the 21,000 overhead once. Safe (formerly Gnosis Safe) multisig wallets batch multiple operations in a single transaction. Uniswap's Universal Router batches permit approvals and swaps. Aave's paraSwap integration batches multi-hop routes. For frequent DeFi users, structuring operations as batches where possible meaningfully reduces cumulative gas overhead.
For Developers: Solidity Gas Optimisation Essentials
If you're deploying smart contracts, gas optimisation benefits every user who interacts with your code. The most impactful patterns:
Storage packing: Solidity stores state variables in 32-byte (256-bit) slots. Packing multiple variables into a single slot (e.g., a uint128 + uint128 pair occupies one slot vs two for two uint256 variables) reduces storage writes from multiple SSTORE operations to one. SSTORE costs 20,000 gas for writing a new slot and 5,000 gas for updating an existing one — packing correctly can save 15,000+ gas per transaction that modifies multiple packed variables.
Memory caching of storage reads: SLOAD (reading from storage) costs 100 gas for a "warm" slot and 2,100 gas for a "cold" slot. If you read the same storage variable multiple times in a function, cache it in memory (uint256 cachedValue = storageVar;) and read memory instead. Memory reads cost 3 gas. For functions that read storage variables in loops, caching before the loop saves (2,100 - 3) × (loop count - 1) gas.
Custom errors vs require strings: Solidity 0.8.4 introduced custom errors: error InsufficientBalance(uint256 available, uint256 required). Custom errors cost less gas than require("Insufficient balance") because they don't store the string in deployed bytecode or in revert data. Replace all require(condition, "string") with if (!condition) revert CustomError(params); for meaningful gas reduction at both deployment and revert time.
Unchecked arithmetic: Post-Solidity 0.8.0, all arithmetic is checked for overflow/underflow by default, adding gas overhead. In loops with mathematically guaranteed bounds (e.g., incrementing a counter from 0 to array length), wrapping the increment in unchecked { ++i; } eliminates the overflow check overhead — saving roughly 30–60 gas per loop iteration.
These patterns are not micro-optimisations for academic interest — they are concrete, quantifiable improvements that Hardhat Gas Reporter can measure precisely in your test suite. For high-traffic protocols (hundreds of thousands of daily interactions), optimised contracts save users millions of dollars in aggregate gas costs over their lifetime.
Practical Action Plan
For regular DeFi users: (1) Move routine activity to an L2 immediately — this alone saves 99% of mainnet gas costs; (2) Time non-urgent mainnet transactions for off-peak UTC hours; (3) Switch to permit-based token approvals wherever available; (4) Check and revoke unnecessary token approvals quarterly via Revoke.cash. For developers: (5) Run Hardhat Gas Reporter on every PR; (6) Apply storage packing to all struct definitions; (7) Replace require strings with custom errors throughout. These six actions implemented consistently represent the highest-return gas optimisation available to each respective audience.
0 Comments
Leave a Comment
Your email won't be published. After submitting, you'll receive a quick verification email — click the link to publish your comment.