Gas fee

On this page 7

A gas fee is the amount a user pays to have a transaction or smart contract call executed on a blockchain, calculated as the units of gas consumed multiplied by the price per unit. In smart contracts on Ethereum and other networks built on the EVM, gas measures computational and storage work, and the fee compensates the network for processing it while protecting the chain from spam and endless loops.

Gas separates two questions that are easy to confuse: how much work an operation requires and how much each unit of work costs at a given moment. The first is fixed by the code and the protocol rules; the second rises and falls with demand for block space.

How gas measures computation

Every instruction the virtual machine executes has a fixed gas cost set by the protocol. Adding two numbers costs a few units, reading a storage slot for the first time in a transaction costs about two thousand, and writing a new non-zero value to storage costs about twenty thousand units, because permanent state burdens every node forever. A transaction declares a gas limit, the maximum units it may consume, and execution stops when that budget runs out.

When a call runs out of gas, the state changes are reverted, but the gas already consumed is still charged. This rule makes failed transactions costly and is the reason wallets estimate gas before sending. Unused gas below the limit is not charged, so a generous limit is safe as long as the code does not fail.

Typical consumption on Ethereum varies widely with the operation, as the following rough ranges show.

OperationTypical gas usedWhy it costs that much
Plain ether transfer21,000Fixed base cost of any transaction
Token transferAbout 35,000 to 65,000Two balance updates in contract storage
Token approvalAbout 45,000One allowance written to storage
Swap on an exchange contractAbout 100,000 to 250,000Several contracts and storage writes
Contract deploymentHundreds of thousands to millionsBytecode stored permanently on-chain
Typical gas consumption by operation

How the gas price is set

Since the EIP-1559 upgrade in 2021, the Ethereum gas price has two parts. The base fee is set by the protocol for each block and is burned, removing that ether from supply. The priority fee, or tip, goes to the validator who includes the transaction and rewards faster inclusion when blocks are busy.

The base fee follows a target block size of half the gas limit. When a block uses more than the target, the next base fee rises by up to 12.5 percent; when it uses less, the fee falls by up to the same amount. A sustained surge therefore doubles the base fee in roughly six full blocks, about a minute and a quarter. Prices are quoted in gwei, one billionth of an ether.

ParameterWho sets itEffect
Gas limitSender or walletCaps the units the call may consume
Base feeProtocol, per blockBurned; tracks demand for block space
Max priority feeSenderTip offered to the block proposer
Max fee per gasSenderCeiling on base fee plus tip combined
Effective gas priceResult at inclusionBase fee plus actual tip, never above max fee
Fee parameters in an Ethereum transaction

The sender pays gas used times effective gas price, and any difference between the declared maximum and the actual price is never charged. Setting a high max fee per gas therefore protects a transaction against a rising base fee without overpaying in a calm market.

Gas fees on layer 2 networks and other chains

The gas concept appears across EVM-compatible chains, but the economics differ by network. On a rollup, the fee has an execution component for running the transaction on the layer 2 and a data component for publishing compressed transaction data to Ethereum. Since the 2024 introduction of blob space, a separate fee market for rollup data, these data costs have fallen sharply, and rollup transfers commonly cost a small fraction of a cent to a few cents.

Network typeFee componentsTypical cost profile
Ethereum mainnetBurned base fee plus validator tipHighest; spikes during congestion
Optimistic or ZK rollupLayer 2 execution plus layer 1 dataLow; tied to blob prices
Other EVM layer 1 chainsNative token gas under own rulesUsually low; set by local demand
Non-EVM chainsCompute units or fixed feesDifferent metering, similar purpose
Where the fee goes on different networks

Developers who write contracts for several networks should not assume identical costs. Opcode pricing, block limits and data fees vary, and a pattern that is cheap on a rollup can remain expensive on mainnet.

Reducing gas costs in practice

Users control the price they pay, while developers control the amount of gas their code consumes. Users save most by timing transactions outside peak hours and by moving routine activity to layer 2 networks. Developers apply gas optimization: fewer storage writes, packed variables, events instead of stored history and efficient loops.

SymptomLikely causeFix
Transaction pending for hoursMax fee below current base feeReplace with a higher max fee
Failed transaction still chargedRevert or out-of-gas during executionSimulate before sending
Unexpectedly high feeSent during a demand spikeWait or use a layer 2 network
Contract call costs too muchExcess storage writes in the codeRefactor and cache values in memory
Common gas problems and fixes

Never hard-code gas assumptions into contract logic. Protocol upgrades have repriced opcodes several times, and code that forwards a fixed amount of gas to another contract has broken after such changes.

Misconceptions and security aspects

  • Gas is not a token: it is a unit of work; the fee is paid in the network’s native currency, such as ether.
  • A higher tip does not guarantee success: it speeds inclusion, but a call that reverts still costs gas.
  • Gas price is public: transactions with visible tips in the public mempool can be reordered, which creates room for MEV and front-running.
  • Gas limits protect the network: the block gas limit caps total work per block, which keeps the chain verifiable on ordinary hardware.

In simple terms

A gas fee works like the postage plus processing fee for a blockchain action. A simple payment is a light envelope and costs little; a complex action, such as trading through a program that touches several accounts, is a heavy parcel and costs more.

The price per unit of postage changes with traffic. When many people want their transactions processed at the same time, the price rises, and when the network is quiet it falls. The work stays the same; only the price of the work moves.

A practical example

A developer at a small game studio deploys a contract that issues in-game items as tokens. On Ethereum mainnet, a test mint uses about 90,000 gas; at a base fee of 20 gwei plus a 1 gwei tip, each mint costs about 0.0019 ether, which is too expensive for items players buy for a few cents.

The team rewrites the contract to pack several fields into one storage slot, which cuts consumption to about 55,000 gas, and deploys it on a rollup. There, each mint costs a fraction of a cent, and the studio settles items in batches to mainnet only when players withdraw them. The outcome is a game economy that remains affordable during busy periods.