Gas
Unit measuring computational work in EVM transactions.
Gas is the unit EVM-compatible blockchains use to measure computational and storage work performed by transactions and smart contracts. Every operation consumes a defined amount of gas. Users pay a gas fee based on the amount actually used and the effective price per unit.
Gas separates resource use from the market price of the network's native asset. A token transfer, storage update, and complex decentralized exchange swap require different work, so they consume different gas amounts. The price per gas can change with demand even when the same contract call uses an identical amount. This distinction lets the protocol price computation consistently while fees respond to congestion.
A transaction sets a gas limit, which caps execution. If the contract finishes below the limit, unused gas is not charged. If it exhausts the limit, execution reverts and the sender still pays for work performed. Setting a very high limit does not normally increase the final fee by itself, although the account must be able to cover the maximum potential cost.
Under Ethereum's EIP-1559 mechanism, the protocol calculates a base fee and the sender offers a priority fee. The base fee is burned, while the priority fee generally rewards the block proposer. Wallets also set a maximum fee that leaves room for base-fee changes while the transaction waits. Other EVM chains may use different fee destinations or rules.
Gas matters to users because an action can be economically unreasonable even when technically valid. Frequent claims may cost more than rewards, and a failed swap still uses gas. Layer 2 networks often charge cheap execution plus a data-publication component. Applications should display all estimated fee parts, native fee asset, and likely range before signing.
Developers reduce gas through efficient storage, batching, appropriate data structures, and avoiding unnecessary computation, but optimization must not weaken correctness or readability. Test costs across realistic state, monitor changes after upgrades, and never assume estimates are exact. Users should review transaction purpose and total cost, keep enough native currency for future actions, and avoid blindly increasing gas settings when a contract repeatedly fails.
Block explorers show gas limit, gas used, effective price, and total charge after execution, making them useful for checking wallet estimates against actual results.
Frequently asked questions
- On an EVM network, execution cost is gas used multiplied by the effective price per gas. Under Ethereum's EIP-1559 model, the effective price includes the protocol base fee plus a priority fee, capped by the sender's maximum. Layer 2 transactions may also charge for publishing data to Layer 1, so execution gas alone may not equal the total.
- An out-of-gas failure means execution needed more gas than the transaction allowed. State changes revert, but gas spent on attempted work is charged. Wallet estimation can fail when contract behavior depends on changing state, token logic, or nested calls. Re-estimate current execution and understand the error before raising the limit, since malicious or broken code may consume excessive gas.
- Demand for limited block space, the protocol's fee mechanism, the selected priority tip, and the specific network affect gas price. Ethereum's base fee rises after blocks use more than their target and falls when use is lower. A larger tip may improve inclusion but cannot bypass a blocked nonce, fix invalid execution, or guarantee immediate confirmation.
