Sub topic 13
Pending, stuck and failed transactions
This chapter assumes you know how nonces order an account's transactions, how gas and fees are priced, and the stages of a transaction's life from signing to inclusion. It covers what to do when a transaction does not confirm, and what a failure actually means.
Three different problems
People use "stuck" for several situations that have different causes and fixes. Identify which one you have before you act.
| State | What you see | What it means |
|---|---|---|
| Pending | The explorer shows the hash as pending, or finds nothing | The transaction is waiting in a node's mempool, or no node accepted it |
| Dropped | The hash disappears from the explorer | A node evicted it, usually because the fee was too low |
| Failed (reverted) | Included in a block with status failed | It ran and was rejected, and the fee was still charged |
A failed transaction is final and was included in a block. A pending or dropped transaction has not been included, so you may still be able to change its outcome.
Why a transaction stays pending
The mempool is the pool of valid but unconfirmed transactions that nodes hold. Block producers choose from it, and they prefer transactions that pay the most per unit of gas. A transaction can sit there for these reasons:
- The fee is below the current going rate. On networks with a base fee, a transaction whose max fee is lower than the current base fee cannot be included until the base fee falls.
- The priority fee (tip) is too low. The transaction is valid but unattractive, so producers pick others first.
- An earlier nonce is missing or stuck. Nodes execute an account's transactions in nonce order. If nonce 7 is stuck, nonces 8, 9 and later wait behind it, however high their fees are.
- The transaction never propagated. The RPC endpoint you used may have accepted it and then lost it, or rate-limited it.
The nonce case is the most common source of confusion. One cheap, stuck transaction blocks everything after it from the same account.
Diagnosing a pending transaction
Work through these checks in order.
- Look up the hash in a block explorer for the correct network. Confirm you are on the right chain first, since a hash searched on the wrong explorer looks like it does not exist.
- Check the status. Pending, successful, failed and "not found" lead to different actions.
- Compare the transaction's max fee per gas with the current base fee. If the max fee is lower, the transaction cannot be mined yet.
- Compare the account's pending nonce with its confirmed nonce. If they differ, you have transactions in flight.
The following script reports the nonce gap and the status of a hash.
import { JsonRpcProvider, formatUnits } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const address = process.env.ADDRESS;
const confirmed = await provider.getTransactionCount(address, "latest");
const pending = await provider.getTransactionCount(address, "pending");
console.log("Confirmed nonce:", confirmed);
console.log("Pending nonce:", pending);
console.log("Transactions in flight:", pending - confirmed);
const feeData = await provider.getFeeData();
console.log("Current max fee (gwei):", formatUnits(feeData.maxFeePerGas ?? 0n, "gwei"));
const tx = await provider.getTransaction(process.env.TX_HASH);
if (tx === null) {
console.log("Node does not know this transaction (dropped or never sent)");
} else if (tx.blockNumber === null) {
console.log("Pending. Nonce:", tx.nonce);
console.log("Its max fee (gwei):", formatUnits(tx.maxFeePerGas ?? tx.gasPrice, "gwei"));
} else {
const receipt = await provider.getTransactionReceipt(process.env.TX_HASH);
console.log("Mined in block", tx.blockNumber, "status", receipt.status);
}If pending - confirmed is greater than zero and the first in-flight transaction has a fee below the current one, that transaction is your blocker.
Fixing a pending transaction
You have two tools. Both rely on the rule that a node accepts a new transaction with the same nonce only if it pays meaningfully more.
Speed up
A speed-up resends the same transaction (same recipient, value and data, same nonce) with a higher fee. Whichever version is mined first wins, and the other becomes invalid because its nonce is used. Most nodes require the replacement to raise both the max fee and the priority fee by at least about 10 percent, so a bump of 1 percent is rejected as "replacement underpriced".
Cancel
A cancel sends a new transaction with the same nonce, a higher fee, and a harmless payload: typically zero value sent to your own address. If it is mined first, the original can never run, because that nonce is spent. A cancel is a race, not a guarantee. If the original is mined before the cancel, the original takes effect, and you pay for both attempts only if both are mined, which cannot happen since they share a nonce. You pay for the one that wins.
import { JsonRpcProvider, Wallet } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY, provider);
const stuck = await provider.getTransaction(process.env.TX_HASH);
if (stuck === null || stuck.blockNumber !== null) {
throw new Error("Transaction is not pending; nothing to replace");
}
// Raise both fee fields by 25 percent, above the usual 10 percent minimum.
const bump = (n) => (n * 125n) / 100n;
const cancel = await wallet.sendTransaction({
to: wallet.address,
value: 0n,
nonce: stuck.nonce,
maxFeePerGas: bump(stuck.maxFeePerGas),
maxPriorityFeePerGas: bump(stuck.maxPriorityFeePerGas),
});
console.log("Cancel submitted:", cancel.hash);
await cancel.wait();
console.log("Nonce", stuck.nonce, "is now used");This example assumes an EIP-1559 style transaction. On a network that uses a single legacy gas price, bump gasPrice instead. To speed up rather than cancel, reuse the original to, value and data in place of the self-send.
Dropped transactions
A node may evict a transaction when its mempool is full or after a timeout. Eviction does not cancel anything permanently. Another node may still hold the transaction and mine it later. Do not assume a dropped transaction is dead and resend the same payment with a new nonce. If the original is later mined, the recipient is paid twice. Resend with the same nonce, or wait until the nonce is confirmed as used.
Failed transactions
A failed transaction was included in a block, and its receipt has status 0. The state changes were reverted, so no value or tokens moved, but the gas used was consumed and paid to the network.
Common causes:
- Out of gas. The gas limit was lower than the work needed. The whole limit is consumed.
- A contract revert. A
requirecheck failed, for example insufficient token balance, a missing allowance, or a swap whose price moved past your slippage limit. - Wrong state at execution time. Between signing and inclusion, the state changed, such as a sold-out mint.
To see why, open the transaction in the explorer and read the revert reason or error message. Wallets can often predict a failure through simulation, called gas estimation. If an estimate fails, treat that as a warning and do not force the transaction through with a manual gas limit.
Different networks, different rules
Replacement and nonce behavior differs by chain family.
- Ethereum-style networks use nonces and allow replacement as described above.
- Bitcoin-style networks have no nonces. A stuck transaction can be replaced if it signaled replace-by-fee, or sped up by spending its change output with a high-fee child transaction (child pays for parent).
- Some networks have no public mempool or confirm quickly enough that stuck transactions are rare. Check the network's documentation before assuming the same tools apply.
What not to do
- Do not resend the payment as a fresh transaction while the first is merely pending. This risks paying twice.
- Do not trust a "transaction accelerator" service that asks for your seed phrase or private key. Real acceleration needs only a signed replacement from your own wallet.
- Do not delete a wallet's activity history or "reset" an account in your wallet expecting to change the network. A reset only clears the wallet's local record, and it does not alter what nodes hold.
Exercise
Your account has confirmed nonce 12 and pending nonce 15. The transaction at nonce 12 pays a max fee below the current base fee. You send a new transaction, which the wallet assigns nonce 15, with a very high fee. Will it confirm soon, and what should you do?
Show answer
No. Nonces 12, 13 and 14 are still in flight, and the network processes an account's transactions in nonce order, so nonce 15 waits however high its fee is. Replace nonce 12 first, by resending it with the same nonce and a max fee and priority fee at least about 10 percent higher, and above the current base fee. Once it is mined, nonces 13 and 14 need acceptable fees too, and then 15 can proceed.
Exercise
A swap shows as failed on the explorer, and the wallet's balance of the token you sold has not changed. Did you lose the swap amount, and can you cancel the transaction?
Show answer
You did not lose the swap amount, because a reverted transaction undoes its state changes. You did lose the gas fee, which is paid even on failure. You cannot cancel it, because it is already mined and its nonce is used. Check the revert reason, for example slippage or allowance, fix it, and send a new transaction.