Crypto glossary

Out of gas error

Definition

An out-of-gas error happens when a transaction uses up its gas limit before finishing; all its changes are undone, but the gas consumed is still charged.

Every Ethereum transaction sets a gas limit, the maximum amount of computation it is willing to pay for. Each operation the EVM performs uses some gas, and if the running total reaches the limit before execution ends, the EVM stops and reverts every state change: no tokens move, no position opens. The sender still pays for all the gas burned up to that point, because validators did the work.

Wallets normally estimate the gas limit by simulating the transaction, so out-of-gas errors usually appear when conditions change between the simulation and inclusion, for example when a pool's state shifts, a loop runs longer than expected or a user manually lowers the limit to save money. Complex DeFi actions, NFT mints and contract deployments are the most common cases, and explorers label them as failed with an out-of-gas warning.

Setting a higher limit is not wasteful in itself, since unused gas is refunded; the cost is the gas actually consumed. A limit that is too low wastes fees. The error is different from a low gas price, which delays a transaction instead of making it fail.

Example

A user lowers the gas limit on a complex swap to save fees; the transaction runs out of gas halfway, reverts, and still costs them the gas already used.

Related terms