# Gas required exceeds allowance: cause and fix

> Gas required exceeds allowance means the gas estimate ran out of gas at its ceiling. Read the number: 0 means no funds, a large one means the call never ends.

Source: https://hashspan.dev/errors/gas-required-exceeds-allowance

## Short answer

Read the number in the error. 0 means the account can't pay for any gas on that network: fund it, or check the wallet is on the right network. A large number means the call needs more gas than allowed, usually because it never finishes: fix the call or the contract. The node runs the call once at its ceiling and reports that ceiling.

## What you will see

- `gas required exceeds allowance`
- `Out of gas: gas required exceeds allowance: 0`
- `Execution reverted with reason: Out of gas: gas required exceeds allowance: 30000000.`
- `gas required exceeds allowance (0)`
- `out of gas: gas required exceeds: 16777216`

## Where does it stop?

Figure: A transaction's path from your code to the node, the mempool, a block and a receipt. The node step is marked in red with the error gas required exceeds allowance, and the later steps are dashed: no hash and no receipt.

The error comes from the gas estimate, before the transaction is signed and sent. Clients estimate gas for you when you leave it out, so a send can fail here too: no hash, no block, no gas spent.

## What does the number mean?

The estimate first runs your call at the highest gas it can allow. In [geth's estimator](https://github.com/ethereum/go-ethereum/blob/master/eth/gasestimator/gasestimator.go), that ceiling starts at the block's gas limit, or at the gas you passed. It is lowered to what the balance, minus the value, can pay at the fee you gave, and to the node's RPC gas cap. On chains with [EIP-7825](https://eips.ethereum.org/EIPS/eip-7825), geth also caps it at 16,777,216, the most one transaction may use. If the call runs out of gas even there, the estimate returns the ceiling in the error.

Figure: The allowance is the lowest of three: the block gas limit or the gas you set, what the balance pays at the fee you gave, and the node's RPC gas cap. An empty account with a 2 gwei fee has an allowance of 0, so the estimate fails with gas required exceeds allowance: 0; without a fee the same estimate passed at 21000. A call to a contract that never stops fails at the block limit, 30,000,000; more gas will not help.

So read the number before anything else:

- **0, or very low:** the balance is the limit. The account can't pay for the gas at that fee.
- **The block's gas limit, 16,777,216 or the node's cap:** the call needs more gas than any transaction may use. It usually never finishes, such as a loop that doesn't end.
- **The gas value you set:** your limit is too low for this call.

## Which ceiling is my number?

Compare it with the chain. On the public Base Sepolia RPC on 2026-10-21, read-only estimates gave:

| Number in the error | What it is | Do this |
|---|---|---|
| 0 | What an empty account can pay | Fund the account on that network |
| 16,777,216 | The most gas one transaction may use ([EIP-7825](https://eips.ethereum.org/EIPS/eip-7825)), 2^24. Base Sepolia's block limit was 1,200,000,000, so this cap came first | Fix the call: an endless loop, or work too big for one transaction |
| The block's gas limit | Where no lower cap applies, as on our Anvil run (30,000,000) | Same: the call never finishes |
| The gas you passed | Your own limit | Raise it, or leave gas out |

Read the block's limit and check the error against it:

```ts
import type { PublicClient } from 'viem';

declare const client: PublicClient;
declare const allowance: bigint; // the number in the error

const { gasLimit } = await client.getBlock();
if (allowance === 0n) console.log('the account has no funds for gas on this network');
else if (allowance === 16_777_216n || allowance === gasLimit) console.log('the call needs more gas than one transaction may use: an endless loop, or work too big for one transaction');
else console.log('a lower cap: your gas value, the balance at this fee, or the node\'s own cap');
```

The wording differs by node. The public Base Sepolia RPC printed "gas required exceeds allowance (0)" for the empty account. For the endless call, it printed "out of gas: gas required exceeds: 16777216".

## Why does it happen?

- **The account is empty on that chain.** On geth and Anvil, an estimate that carries a fee, such as `maxFeePerGas`, gets an allowance of 0. Some nodes still return 21,000 for a plain transfer, as the public Base Sepolia RPC did.
- **The wallet is on another network.** In a dApp, the wallet estimates for you. Allowance 0 there usually means the connected account has no funds on the network the wallet has selected.
- **The call never ends.** A loop without an exit, or a contract that burns all the gas it is given.
- **The gas limit you passed is too low** for what the call does.

## How do I fix it?

1. **If the number is 0, fund the account** on the chain you send to. `getBalance` shows what the node sees.
2. **If the number is 16,777,216 or the block limit, find out why the call doesn't end.** Simulate it with `simulateContract` or `call`, and check the contract.
3. **If the number is your own limit, raise it or leave gas out,** so the client estimates it.
4. **In an agent, check the balance before the tool estimates,** and tell the model "no funds" instead of passing on an error that says reverted.

```ts
import type { Address, PublicClient } from 'viem';

declare const client: PublicClient;
declare const from: Address;

const balance = await client.getBalance({ address: from });
if (balance === 0n) throw new Error(`${from} has no funds on this chain: the gas estimate would fail with allowance 0`);
```

## What does it look like in a trace?

The estimate runs inside the send, so it is the `send` span that fails, with no hash:

Span `send 31337` (error):

| Attribute | Value |
|---|---|
| `error.type` | ExecutionRevertedError |
| `exception.message` | Execution reverted with reason: Out of gas: gas required exceeds allowance: 30000000. |
| `blockchain.tx.hash` | not set |

From the run above: a send to a contract that loops forever. exception.message appears only with errorMessages set to sanitized.

`error.type` says reverted, but no hash means nothing reached the chain. An [execution reverted](https://hashspan.dev/errors/execution-reverted) that was mined has a hash and a `confirm` span. An [out of gas](https://hashspan.dev/errors/out-of-gas) on the chain has a receipt with status reverted.

## FAQ

### Does gas required exceeds allowance cost gas?

No. It comes from the gas estimate, which runs the call without sending anything. Nothing reaches a block, so nothing is paid.

### What does allowance 0 mean?

The sender's balance can pay for 0 gas at the fee in the estimate. In our run, an empty account got allowance 0 when the estimate carried a fee. Without a fee the estimate passed, and the send was then refused with insufficient funds. Either way the fix is to fund the account on that chain.

### Why does viem say execution reverted?

viem files the node's text "gas required exceeds allowance" under ExecutionRevertedError, so its message starts with "Execution reverted with reason". Nothing ran on the chain: the call ran out of gas inside the estimate.

### Will a higher gas limit fix it?

Not when the ceiling is already the block's gas limit or the per-transaction cap: a call that never ends runs out at any limit. It can help if the ceiling came from a low gas value you set, or from the balance, in which case add funds.
