Crypto
4 min read

Gas

The unit measuring the computational work required to execute an Ethereum transaction or smart-contract operation. Each opcode has a fixed gas cost, and users pay validators per unit of gas consumed.

How gas accounting works

Each EVM operation has a defined gas cost:

  • Simple addition — 3 gas
  • Storage write to a fresh slot — 20,000 gas
  • Updating existing storage — 5,000 gas
  • Sending ETH between accounts — 21,000 gas baseline
  • Calling a contract function — variable, depending on the work performed

A complex DeFi swap might consume 200,000-300,000 gas. A simple transfer uses 21,000.

When you submit a transaction, you specify a "gas limit" — the maximum gas you're willing to consume. If the transaction completes within that limit, you only pay for what's used. If it exceeds the limit, the transaction reverts but you still pay for the gas consumed.

Gas price and fees

Gas is consumed in units, but you pay validators in ETH. The conversion:

Transaction Fee = Gas Used × Gas Price

Gas price is denominated in gwei (one billionth of an ETH). At 30 gwei gas price and 200,000 gas used:

Fee = 200,000 × 30 gwei = 6,000,000 gwei = 0.006 ETH

At an ETH price of $3,000, that's $18.

EIP-1559 mechanism

Since the August 2021 EIP-1559 upgrade, gas pricing has two components:

  • Base fee — algorithmically set per-block based on network demand. Burned (removed from supply) rather than paid to validators.
  • Priority fee (tip) — voluntary additional payment to incentivize validators to include your transaction.

The base fee adjusts up when blocks are full and down when they're empty, targeting roughly 50% block utilization on average. This keeps gas prices more predictable than the previous first-price-auction model and burns ETH proportional to network usage.

Why gas exists

Gas serves multiple purposes:

  • Spam prevention. Without gas, attackers could submit infinite transactions for free, congesting the network.
  • Resource pricing. Some operations are computationally expensive; gas costs reflect that.
  • Validator compensation. Priority fees compensate validators for processing transactions.
  • Deflationary pressure on ETH. Burning base fees removes ETH from supply, sometimes making total supply decline during high-activity periods.

Estimating gas before transacting

Wallets and tools estimate gas costs before users sign:

  • Simulation — running the transaction against current chain state to see what it does.
  • Historical patterns — same contract calls from prior transactions provide gas estimates.
  • Static analysis — examining bytecode for typical execution paths.

Most modern wallets show estimated cost in both gas and dollar terms. Major changes (gas spikes, contract bugs) can cause estimates to be wrong; gas limits should include some buffer.

Why some operations are expensive

A few commonly-expensive patterns:

  • Storage operations. Writing data to chain state is the most expensive opcode. Contracts that update many storage slots cost a lot.
  • Computational complexity. Loops, large data structures, certain cryptographic operations.
  • External calls. Calling other contracts triggers their gas costs too.
  • Returning large data. Reading lots of data into a transaction's return value.

Optimizing gas costs is a core skill for Solidity developers. Production-quality DeFi contracts often have meaningfully lower gas costs than naive implementations of the same logic.

Gas on different chains

The "gas" concept has been adopted across most EVM-compatible chains, though the absolute costs vary widely:

  • Ethereum mainnet — most expensive. Simple swap can cost $5-20 in normal conditions, $50+ during congestion.
  • Arbitrum, Optimism, Base — typically $0.05-1 for similar transactions.
  • BNB Chain, Polygon — typically pennies per transaction.
  • Solana — uses different mechanics; transactions cost fractions of a cent.

The cost difference dramatically affects user experience. Many crypto applications that are uneconomical on Ethereum mainnet thrive on cheaper chains.

Gas in user experience

Gas cost is one of the most-cited friction points in crypto adoption:

  • New users don't understand why transactions cost money or why prices fluctuate.
  • "Gas" itself is jargon that doesn't intuitively translate.
  • Failed transactions still cost gas, which feels unfair.
  • Gas-token requirements (you need ETH to send anything on Ethereum, even non-ETH transactions) are confusing.

Several mitigations:

  • Layer 2s — dramatically lower fees.
  • Account abstraction — gas sponsorship, paying gas in any token, batching multiple operations.
  • Gas estimators in wallets — show users predicted cost in dollars rather than just gas units.
  • Transaction simulation — preview what will happen before signing, including gas cost.

Gas and MEV

Gas pricing intersects with MEV extraction:

  • Searchers competing for arbitrage opportunities bid up gas prices to ensure their transactions get included first.
  • Priority gas auctions historically saw bots paying enormous priority fees to capture profitable opportunities.
  • Flashbots and similar services introduced "private order flow" — submitting transactions through channels that don't trigger gas auctions.

These dynamics affect typical users — when MEV bots are active, gas prices for everyone rise. Private RPC services partially shield users from this competition.

What individuals should know

For active users:

  • Plan transactions during low-gas periods. Weekends and off-hours typically have lower gas. Tools like ETH Gas Station show current prices.
  • Use Layer 2s when possible. Most user activity doesn't need mainnet's specific properties.
  • Set gas limits with buffer. Underestimating gas causes failed transactions; overestimating just means the unused gas is refunded.
  • Watch for unexpectedly expensive operations. Some contract calls are genuinely expensive; some are cheap but wallets sometimes overestimate.

For developers:

  • Profile contract gas usage during development.
  • Optimize storage access patterns — the largest source of gas savings.
  • Consider gas costs in protocol design. Operations users do frequently should be cheap; rare operations can be expensive.
  • Use libraries like OpenZeppelin that have already been gas-optimized rather than reimplementing primitives from scratch.