Gas Cost Model
What costs gas.
Why Gas Exists
Every operation on the Ethereum Virtual Machine (EVM) costs gas. Gas is a unit that measures the computational work required to execute a transaction.
Gas exists to:
- Pay validators for the resources they spend
- Prevent infinite loops and denial-of-service attacks
- Price scarce on-chain resources fairly
The total fee you pay equals gasUsed * gasPrice, denominated in wei.
Gas, Gas Price, and Gas Limit
Three numbers matter for every transaction:
- gasUsed — how much computation actually happened
- gasPrice (or maxFeePerGas under EIP-1559) — how much you pay per unit
- gasLimit — the maximum gas you allow before the transaction reverts
If execution exceeds the gas limit, the transaction reverts with an out of gas error, but you still pay for the gas consumed.
// Fee calculation
// totalFee = gasUsed * effectiveGasPrice
// Example: 50000 gas * 20 gwei = 1,000,000 gwei = 0.001 ETH