What is gas limit?
The maximum amount of computation you authorize a transaction to use, counted in gas units and set separately from the price paid per unit.
Not yet verifiedHow we verify
3 min read
In this entry
The maximum amount of computation you authorize a transaction to use, counted in gas units and set separately from the price paid per unit.
A plain transfer of ether costs 21,000 gas, while contract calls cost more and fail with the gas spent if the limit is too low. Wallets estimate it for you, and the estimate is usually right, which is why most people never touch the setting.
The confusion worth clearing up is between the limit and the price. The limit is how much work you allow. The price is what you pay per unit of work. Raising the limit does not make you pay more if the transaction does not use it, and raising it does not make the transaction faster.
How it works
Every operation the evm performs has a fixed gas cost, and the total consumed is what you are charged for. The limit you set is a ceiling on that total, and it exists to protect you: without it, a bug or a malicious contract could consume everything in your wallet.
Two outcomes are possible when a transaction runs:
- It completes within the limit. You pay for the gas actually used, at the gas price in effect. The unused portion of the limit is not charged.
- It hits the limit. Execution stops, all state changes revert, and the gas consumed up to that point is kept. You paid for work that achieved nothing.
That second case is why setting the limit too low is worse than setting it too high. A limit that is too high costs nothing extra; a limit that is too low costs the full amount and delivers no result.
Reference points are stable. A plain transfer of the native asset is 21,000 gas (source: the Ethereum Yellow Paper). A token transfer typically costs several times that because it writes contract storage. A swap through a decentralized exchange costs considerably more again.
Blocks also have a gas limit, which caps total computation per block and is what eip 1559 targets when adjusting the base fee.
Example
Illustrative arithmetic. You send ether with a limit of 21,000 and a total fee of 20 gwei per gas. Cost is 21,000 multiplied by 20 gwei, which is 0.00042 ETH. Now set the limit to 100,000 for the same transfer: the transaction still uses only 21,000 and you still pay 0.00042 ETH, because the unused 79,000 was never consumed. Set it to 20,000 instead and the transfer fails, having consumed the full 20,000, and you pay 0.0004 ETH for nothing.
Why it matters when you buy
Withdrawing from an exchange to a wallet, or moving a token between wallets, costs gas set this way, and a failed transaction still costs money. Leave the wallet's estimate alone unless you have a specific reason, and factor the network fee into whether a small purchase is worth withdrawing at all. Compare network characteristics at the chain pages.
Related terms
gas — the unit being limited, base fee — the price per unit, priority fee — the tip on top, gwei — how the price is quoted, evm — what consumes the gas, eip 1559 — how the block limit is targeted.
Questions
Should I change the gas limit my wallet suggests?
Usually not. Wallets simulate the transaction to estimate it and add a margin. Overriding it downward risks a failed transaction that still costs the full amount used.
Does a higher gas limit cost more?
No, not by itself. You pay for gas consumed, not for gas authorized. A higher limit only means a higher maximum you could be charged if the transaction actually used it.
Why did my transaction fail and still charge me?
Because the network performed the computation before running out. Work done is paid for whether or not it produced a result, which is the same reason any reverted transaction costs gas.