Skip to content
Beta
Research · Learn Crypto

What Is a Gas Limit and Why Do Transactions Fail?

Ethereum & Smart Contracts · 7 Outubro 2026 · 5 min read · By admin

The gas limit caps how much computation an Ethereum transaction may use. See how gas fees are calculated, why transactions run out of gas and failure costs.

What Is a Gas Limit and Why Do Transactions Fail? — OTCN Research cover

A gas limit is the maximum amount of computation, measured in gas units, that you allow an Ethereum transaction to use. If the transaction needs more than that, it stops, its changes are undone, and you still pay for the gas it used. Transactions also fail when a smart contract rejects them, for example because a price moved too far.

Gas, gas price and gas limit

Every operation on Ethereum has a fixed cost in gas units. A simple ETH transfer costs 21,000 gas; interacting with a smart contract costs more, depending on what the code does. The fee you pay is:

Fee = gas used × (base fee + priority fee)

The base fee is set by the network and burned. The priority fee is a tip to the validator. Both are quoted in gwei, where 1 gwei is 0.000000001 ETH. The gas limit is the cap on gas used: your wallet estimates it, and you rarely need to change it.

A worked example

You swap tokens with a gas limit of 100,000. The swap actually uses 65,000 gas, and the base fee plus tip is 20 gwei.

  • Fee = 65,000 × 20 gwei = 1,300,000 gwei = 0.0013 ETH
  • The unused 35,000 gas costs nothing.

Now the same swap with a gas limit of 50,000:

  • The swap needs 65,000 gas, so it runs out after 50,000.
  • The transaction fails and the swap does not happen.
  • You still pay 50,000 × 20 gwei = 1,000,000 gwei = 0.001 ETH.

The figures are illustrative; real fees change with network demand.

Two transactions compared: with a 100,000 gas limit the swap uses 65,000 gas and costs 0.0013 ETH; with a 50,000 limit it runs out of gas, fails, and still costs 0.001 ETH.
Figure: The worked example at 20 gwei. Illustrative values; real fees change with demand.

Max fee, priority fee and what you actually pay

Modern Ethereum wallets ask for two prices rather than one. The max fee is the most you are willing to pay per unit of gas in total; the priority fee is the tip you offer the validator. When the transaction is included, you pay the current base fee plus your tip, and anything left between that and your max fee is never charged.

Suppose you set a max fee of 30 gwei and a priority fee of 2 gwei, and the base fee when your transfer is included is 18 gwei. You pay 20 gwei per unit: 21,000 × 20 gwei = 0.00042 ETH. Your wallet briefly reserved up to 0.00063 ETH, but the 10 gwei per unit you did not need was never spent. (Example values.) A generous max fee therefore protects you against a rising base fee without making you overpay.

Why transactions fail

Out of gas. The limit was set too low for what the transaction needed, often because it was edited manually or the contract’s state changed after the estimate.

The contract reverted it. Smart contracts check conditions before acting. A swap reverts if the price moves beyond your slippage setting, a transfer reverts if the balance is too low, and a mint reverts if the sale is sold out. Gas used up to that point is still charged.

Fee too low to be included. If the maximum fee you allowed is below the current base fee, the transaction waits in the queue rather than failing, and may need to be replaced with a higher fee.

Speeding up or canceling a stuck transaction

A pending transaction can be replaced while it waits. Wallets offer “speed up,” which resubmits the same transaction with a higher fee, and “cancel,” which sends a zero-value transaction to yourself using the same sequence number, called a nonce, with a higher fee. Whichever version a validator includes first wins, and the other is dropped. Replacement only works before the original is included in a block; once confirmed, a transaction cannot be canceled.

Why gas estimates sometimes miss

Your wallet estimates gas by simulating the transaction against the current state of the blockchain. If that state changes before your transaction is included, for example because other trades moved a pool’s price or a sale sold out, the real path through the contract can differ and use more gas, or revert entirely. Contracts that loop over lists whose length changes are especially prone to this.

The block gas limit is different

Each block also has a gas limit that caps the total gas of all transactions inside it. It is set by the network’s validators and determines how much activity fits into every 12-second block. When demand exceeds that space, the base fee rises until some users wait. Your transaction’s gas limit only controls your own transaction.

Gas on layer 2 networks

Rollups built on Ethereum use the same concepts: transactions have gas limits, fees are usually paid in ETH, and a transaction that runs out of gas or reverts still costs the gas it used. The difference is scale. Fees on most layer 2 networks are a small fraction of those on the main chain, so a failed transaction there costs little, though the same habits of checking errors before retrying still apply. See what Ethereum rollups are.

Reading a failed transaction on a block explorer

Look up the transaction hash on a block explorer. The status line shows whether it succeeded or failed. Compare gas used with the gas limit: if they are equal, the transaction ran out of gas, and raising the limit may fix it. If gas used is below the limit and the status says the execution reverted, the contract refused the action, and the reason, when shown, explains why: insufficient balance, slippage exceeded, sale closed. In that case, raising the gas limit only makes the next failure more expensive.

How to avoid failed transactions

  • Let your wallet estimate the gas limit unless you know why it is wrong.
  • Read the error on a block explorer: “out of gas” and “execution reverted” have different fixes.
  • For swaps, set a slippage tolerance that fits how fast the market is moving.
  • Before retrying, find out why the first attempt failed, or you may pay twice for the same result.

For how fees work across networks, read blockchain transaction fees. For the programs that consume gas, see what a smart contract is, and for the network itself, what Ethereum is.

This article is educational content and does not constitute financial, investment, legal or tax advice. Digital assets are volatile and you may lose the amount you invest.

Sources

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *