Fees & Gas

Why Did My Transaction Fail but Still Cost Gas?

By HealthShaper Hub · · How we check facts

Why a failed transaction still costs gas: the network did the work, so the fee is kept. See what reverts and out-of-gas errors cost and how to avoid them.

Comparison of a reverted transaction and an out-of-gas transaction, showing how much of the gas limit each is charged

Key takeaways

  • A failed transaction was still processed and recorded in a block, so its gas is charged even though its changes are undone.
  • A revert charges only the gas used up to the failure; running out of gas consumes the entire gas limit.
  • A gas limit below the minimum a transaction needs is rejected before inclusion and costs nothing.
  • Cutting the gas limit backfires: in our example, a failure plus a retry cost 56.25% more than one clean success.
  • Read the error on a block explorer before retrying; a blind retry of a reverting swap usually repeats the same charge.
On this page
  1. Why does a failed transaction still cost gas?
  2. What are the three ways a transaction can fail?
  3. Worked example: one swap, four outcomes
  4. What does the error message mean?
  5. Checklist before you retry a failed transaction
  6. Can you get the gas back?
  7. The bottom line
  8. Frequently asked questions
  9. Sources

Why does a failed transaction still cost gas?

When you send a transaction, a validator includes it in a block and every node on the network executes it. If execution stops partway, because a check failed or the gas ran out, the network reverses the changes your transaction tried to make. What it cannot reverse is the computation already performed, and gas is the payment for that work.

So “failed” on a block explorer does not mean “rejected”. It means the transaction was included, charged and recorded permanently, with its status, gas used and error message visible to anyone. The base-fee part of the payment is burned and the tip still goes to the validator, exactly as it would for a success; our guide to how base fees, tips and gas limits work covers that split.

What are the three ways a transaction can fail?

1. It reverts

Smart contracts check conditions as they run and stop themselves with a REVERT instruction when one fails: the output of a swap is below your minimum, a deadline has passed, or an approval is missing. Since the Byzantium upgrade introduced REVERT through EIP-140, a revert rolls back state changes without consuming all remaining gas. You pay for the gas used up to the revert, and the rest of your gas limit is not charged.

2. It runs out of gas

If execution needs more gas than the limit you set, it halts. The changes are undone, and all the gas you provided is consumed for the work performed. Running out of gas is the most expensive way to fail, because it always charges the full limit.

3. It is rejected before inclusion

Some transactions never reach a block. If the gas limit is below the minimum a transaction needs just to be valid, such as a limit of 20,000 for a plain ETH transfer that needs 21,000, it fails validation and no gas is consumed. The same applies to a transaction your wallet refuses to send, or one that is dropped from the pending pool: nothing was executed, so nothing is charged.

Reverted vs out of gas: what you pay
RevertedOut of gas
Gas chargedGas used up to the revertThe entire gas limit
Rest of the limitNot chargedNothing left
Your intended changesUndoneUndone
NonceUsedUsed
Typical causeA contract check failedGas limit set too low
Example cost$2.53 (47,500 gas)$4.80 (90,000 gas)
Both failures are included in a block and charged. The difference is how much of your gas limit gets consumed.

Worked example: one swap, four outcomes

Suppose a swap needs about 160,000 gas and your wallet sets a gas limit of 220,000. Gas costs a 14 gwei base fee plus a 0.8 gwei tip, or 14.8 gwei per gas, and ETH is at a hypothetical $3,600. If you need a refresher on the units, see how to convert gwei to ETH and USD.

OutcomeGas chargedFee in ETHFee in USD
Success160,0000.002368$8.52
Reverts early (price check fails)47,5000.000703$2.53
Out of gas (limit cut to 90,000)90,0000.001332$4.80
Out of gas, then a successful retry250,0000.0037$13.32

Three lessons come out of the table. First, in the successful case the 60,000 gas left under the limit (0.000888 ETH, or $3.20) is never charged, so the generous limit cost nothing. Second, cutting the limit to 90,000 to save money turned an $8.52 swap into $13.32 of total fees, which is 56.25% more.

Third, retries add up. If the swap keeps reverting at the same check and you try three times without changing anything, you pay 3 × $2.53, or about $7.59, which is 89% of the cost of the successful swap, and you still have not swapped anything.

What does the error message mean?

A block explorer shows the status of every transaction and, for most failures, a reason. Wording varies by contract, but most messages fall into a few families:

What you seeWhat usually happenedWhat to check before retrying
Out of gasThe gas limit was too lowRestore your wallet’s estimate
Too little received, or insufficient outputThe price moved beyond your slippage limitTrade size, pool depth and tolerance
Exceeds allowanceThe approval is missing or too smallApprove only the amount you need
Expired, or deadlineThe transaction waited too longCurrent fees, then resubmit
Exceeds balanceNot enough tokens after feesYour balance and any token transfer fee

Price-related reverts are covered in how slippage works and how to limit it. If you need to grant an approval, keep it to the amount you need, and review old ones with our guide to reviewing and revoking token approvals. A transaction that expired after sitting unconfirmed is a sign your fee settings were too low, which speed-ups and replace-by-fee help you handle next time.

Warning: If buying a token works but every attempt to sell it reverts, stop retrying. That pattern is the signature of a honeypot token designed so you can buy but not sell.

Checklist before you retry a failed transaction

  1. Open the transaction on a block explorer and read its status and error message.
  2. Compare gas used with the gas limit. If they are equal, it ran out of gas.
  3. Fix the cause first: the gas limit, the approval, the slippage setting, the deadline or the balance.
  4. Check the current base fee so the retry does not sit pending while conditions change again.
  5. If your wallet’s simulation says the transaction will fail, investigate instead of forcing it through.
  6. Do not retry a second time without a new piece of information.

Before you resend, it helps to know what one more attempt costs at today’s prices. Enter the gas limit, base fee and tip in the calculator below.

Can you get the gas back?

No. Once a transaction is in a block, its fee is final: the base fee has been burned and the tip has been paid, so there is no one to reverse it. That is also why anyone offering to recover gas or lost funds for an upfront payment deserves suspicion; the promise is a common hook in recovery scams.

What you can control is the next attempt. Keep the wallet’s gas estimate, fix the cause, and send once.

The bottom line

A failed transaction costs gas because the network executed it before it stopped. A revert charges the gas used up to the failure, while running out of gas charges the whole limit. Read the error, fix the cause, and never cut the gas limit to save money: it only makes failures more expensive.

Frequently asked questions

Why do I have to pay for a failed transaction?

Because the network did the work. A validator included your transaction and every node executed it until it stopped, and that computation cannot be taken back even though the state changes are reversed. Charging for work performed is also what stops people from flooding the network with transactions designed to fail. The base-fee part of your payment is burned and the tip goes to the validator.

Can I get a refund for gas spent on a failed transaction?

No. Fees on Ethereum are final once the transaction is in a block: the base fee has been burned and the tip has been paid to the validator, so there is no one to refund it. Be wary of anyone who offers to recover gas or lost funds in exchange for an upfront payment; that promise is a common pattern in recovery scams.

What does execution reverted mean?

It means a smart contract stopped itself because one of its checks failed, for example a price moved beyond your slippage limit, a deadline passed, an approval was missing or a balance was too low. The contract's changes are undone. You pay for the gas used up to the point of the revert, and the rest of your gas limit is not charged.

Does a failed transaction use up my nonce?

Yes. Once a transaction is included in a block, its nonce is used whether it succeeded or failed, and your next transaction takes the following number. A transaction that is never included, such as one that was dropped from the pending pool, does not use its nonce, which is why a replacement with the same nonce can take its place.

Why did my wallet warn that my transaction would fail?

Most wallets simulate a transaction against the current state of the chain before sending it. If the simulation reverts, the wallet warns you, and forcing the transaction through will usually produce an on-chain failure that you pay for. A clean simulation is not a guarantee either, because prices, balances and approvals can change between the simulation and the block that includes it.

Sources

  1. Gas and fees — ethereum.org
  2. EIP-140: REVERT instruction — Ethereum Improvement Proposals
  3. Transactions — ethereum.org

This content is for education only and is not financial, investment, tax or legal advice. Crypto assets are volatile and you can lose money. Examples use hypothetical numbers. See our disclaimer and editorial policy.