Skip to the workspace
Pebellslearn by building
Smart Contracts  ›  Lesson

Gas — Paying for Computation

Ethereum 12 minEvery EVM operation costs gas, the sender pays gas used times the price per gas in the native coin, and running out of gas reverts the call while the gas is still spent.

blockchain / Gas — Paying for Computation

Explore each scene at your own pace.

01 · The rule

The rule

Gas — Paying for Computation

Asha's call to release is executed by thousands of nodes. If contract calls were free, anyone could send one containing an endless loop, and every node would spin forever. Gas is how Ethereum and the other EVM chains prevent that: every step of computation has a price, and the sender pays it.

The rule

Every step costs gas; the fee is gas used times the price per gas.

  • Gas units measure work. Each EVM operation has a fixed gas cost: adding two numbers is cheap, writing to storage is expensive. A plain ETH transfer between two ordinary accounts costs exactly 21,000 gas.
  • Gas limit. The sender sets the most gas the transaction may use. If execution needs more, it stops with out of gas: every change reverts, and the whole gas limit is spent.
  • Gas price. The native coin paid per unit of gas, quoted in gwei, one billionth of an ETH. On Ethereum it has two parts: a base fee set by the protocol, which rises when blocks are busier than a target and is burned, plus a priority fee, or tip, which goes to the validator.
  • Unused gas is refunded. When a call finishes, or fails a require check, you pay for the gas actually used, not the whole limit.

Each block has a gas limit too, so gas also measures how much of the scarce space in a block you take up. When demand is high, the base fee climbs and cheaper transactions wait.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.