05. ETH.BUILD: Gas
Overview
Section titled “Overview”Running a contract means running code on a computer that thousands of people share and that no one owns. Gas is how that shared computer is metered and paid for. Every operation costs a little gas; you pay for the gas your transaction uses. Understanding gas is what lets you reason about why a transaction costs what it does and why one failed.
Key concepts
Section titled “Key concepts”- Gas — a unit that measures computational work. Each low-level operation (a storage write, an addition, a hash) has a fixed gas cost. A simple ETH transfer is 21,000 gas; a complex contract call can be far more.
- Gas limit — the maximum amount of gas you allow the transaction to consume. It is a safety cap, not the price. Set it too low and the transaction runs out of gas and reverts; set it high and unused gas is simply not charged.
- Gas price — how much you pay per unit of gas, denominated in gwei (1 gwei = 10⁹ wei). This is set by supply and demand for block space: when the network is busy, gas price rises.
- Fee = gas used × gas price — the actual cost is the gas your transaction actually consumed multiplied by the price per gas. This is the single most important formula in the lesson.
- EIP-1559 fee model — on modern Ethereum the price splits into a protocol-set base fee (burned) plus a priority fee / tip (paid to the block producer to prioritize you). Wallets usually estimate both for you.
- Out of gas reverts everything — if execution exhausts the gas limit, all state changes are rolled back as if nothing happened — but you still pay for the gas that was burned trying. Failure is not free.
Common pitfalls
Section titled “Common pitfalls”- Confusing gas limit (how much work is allowed) with the fee (what you pay). Raising the limit does not raise your cost unless the transaction actually uses more gas.
- Assuming a failed transaction is free. A revert still consumes gas, so it still costs ETH.
- Setting a gas limit too low to “save money.” That just makes the transaction run out of gas, revert, and waste the fee.
Check yourself
Section titled “Check yourself”- Write the formula for what a transaction actually costs.
- If you double the gas limit but the transaction uses the same amount of gas, does your fee change?
- A transaction fails with “out of gas.” Did the state change? Did you still pay?
Watch the Video
Section titled “Watch the Video”
ETH.BUILD: Gas
Video credit: Austin Griffith · Duration: 23 minutes
