library / Use cases / Analytics and research / UC0120
Failed transaction rate by program
A failure rate for any program from its newest 100 signatures, with the error mix, the program that rejected each sampled failure, and the fees those failures paid, so you can see which callers waste sends.
Why failed transactions still land
A landing service that bills only when a transaction succeeds removes the fee for the failures it filters out. Whatever never reaches the chain costs nothing. A transaction that does land and then fails still pays its base fee of 5,000 lamports per signature, plus any priority fee. The failures you can see on chain are the ones that arrived by another route.
Several habits keep that route busy.
- Plain sends. Wallets, scripts and older clients call sendTransaction and wait. The leader runs whatever arrives, and the signer pays for the outcome.
- Skipped preflight. Simulation before a send catches a transaction that would fail, and switching it off lets that transaction reach the chain. On Carbium the send with preflight costs 70 cells against 20 without, which gives a script a reason to skip it.
- State that moved. A simulation passes at one slot and the transaction runs a few slots later. A pool shifted, a slippage limit was crossed or an account was closed, and the program returns its own error.
- Duplicate intent. An app that builds two different transactions for one action, say one per route, sees the second fail once the first has changed the balances it needs.
- Tips. A pay-on-success route charges a tip on top of the fees when the transaction lands. A sender that fires many attempts for one outcome can spend more on tips than on the base fees of its failed attempts, so it accepts the failures.
- A guessed compute limit. Set too low, it stops the program with ComputationalBudgetExceeded, and the fee is still charged. Compute unit limit from simulation sets it from a measurement.
A base fee of 0.000005 SOL is small enough that a failed send rarely gets fixed. Across a busy program it adds up, and the failure rate says as much about the callers as about the program's code.
Failure rate from the signature list
getSignaturesForAddress lists transactions newest first, and each entry carries an err field: null for a success and an error object for a failure. One call with limit 100 gives a failure rate with no transaction reads. The list covers every transaction that names the program among its account keys, including callers that reach it through another program. A router's list therefore holds transactions where it did the work and ones where it was a passenger.
| Call | Cells | In one run |
|---|---|---|
| getSignaturesForAddress | 50 | one |
| getTransaction | 50 | up to 5 |
A run spends at most 300 cells: 50 for the list and 250 for five reads. Cells are the admission charge per call, and each call class has its own rate on every plan. Five reads sent together stay under the 1,024 cells a class absorbs as a burst.
The window is the newest 100 entries, which on a busy program covers a short stretch of time. Treat it as a sample of the present. The rate moves with the hour and with who is calling, so run it on a schedule if you want a trend, and keep the slot range printed beside each rate.
Every call reads at confirmed commitment, so a signature the list returns can be read by getTransaction at once.
Reading the error
A landed failure is almost always an InstructionError, which holds the index of the instruction that failed and the reason. Group on that reason first.
| Reason | What it usually means | Who fixes it |
|---|---|---|
| Custom 6000 and up | An Anchor program's own error codes start at 6000; the program's IDL names each one | The caller, or the program's authors |
| Custom 1 in the token program | Insufficient funds in the source token account | The caller, who skipped a balance check |
| ComputationalBudgetExceeded | The compute limit was set below what the instructions used | The sender, with a limit taken from simulation |
| Custom 0 in the System Program | An account created at an address already in use | The caller |
The number alone does not say whose code returned it. Custom 1 from the token program is insufficient funds, and Custom 1 from another program means something else. The program id of the failing instruction narrows it down, and the script reads that id for a sample. When that instruction called other programs, the logs name the one that returned the code.
Transactions rejected before inclusion leave nothing on chain: an expired blockhash or a failed preflight never shows in this list. The rate counts failures that landed, so it understates what clients attempted.
The failure report script
Pass a program id as the only argument. With none, the script reads a heavily used swap router program, so the run shows a real mix. The key comes from CARBIUM_KEY, and the script exits with a message when it is unset.
// UC0120 · Failed transaction rate by program// https://carbium.sh/library/usecase/failed-transaction-rate-by-program// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: failure rate, error mix and failing programs for the newest transactions that name a program.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const program = process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";const text = (v: unknown) => JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));function label(err: unknown): string { if (typeof err === "string") return err; const [name, body] = Object.entries(err as Record<string, unknown>)[0] ?? ["unknown", null]; return name === "InstructionError" && Array.isArray(body) ? `InstructionError ${text(body[1])}` : name;}const listed = await rpc.getSignaturesForAddress(address(program), { limit: 100, commitment: "confirmed" }).send() .catch((e) => { console.error("getSignaturesForAddress failed:", String(e)); return process.exit(1); });const failed = listed.filter((s) => s.err !== null);const pct = listed.length ? Math.round((1000 * failed.length) / listed.length) / 10 : 0;console.log(`${program}: ${failed.length} failed of ${listed.length} newest (${pct}%), slots ${listed[listed.length - 1]?.slot} to ${listed[0]?.slot}`);const mix = new Map<string, number>();for (const s of failed) { const l = label(s.err); mix.set(l, (mix.get(l) ?? 0) + 1); }for (const [l, n] of [...mix].sort((a, b) => b[1] - a[1])) console.log(` ${n} x ${l}`);type Tx = { transaction: { message: { instructions: { programId: string }[] } }; meta: { fee: bigint | number } | null };const cfg = { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 } as const;const probe = failed.slice(0, 5);const reads = await Promise.allSettled( probe.map(async (s) => (await rpc.getTransaction(s.signature, cfg).send()) as unknown as Tx | null),);const who = new Map<string, number>();let fees = BigInt(0);reads.forEach((r, n) => { const tag = probe[n].signature.slice(0, 12); if (r.status === "rejected") { console.error(` ${tag} failed:`, String(r.reason)); return; } if (!r.value) { console.log(` ${tag} no transaction behind the signature`); return; } const body = (probe[n].err as unknown as { InstructionError?: [number, unknown] }).InstructionError; const prog = body ? (r.value.transaction.message.instructions[body[0]]?.programId ?? "unknown") : "outside an instruction"; who.set(prog, (who.get(prog) ?? 0) + 1); fees += BigInt(r.value.meta?.fee ?? 0); console.log(` ${tag} ${label(probe[n].err)} in ${prog}`);});for (const [p, n] of who) console.log(`failing program ${p}: ${n} of ${probe.length} sampled`);console.log(`fees paid by the sampled failures: ${fees} lamports`);
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts [program-address]
The script prints the failed count against the listed count, the slot range and the error mix. It then reads the first five failed transactions with jsonParsed encoding and maxSupportedTransactionVersion: 1, which mainnet needs because it carries version 1 transactions. For each it names the program of the failing instruction, and it adds up the fee those five paid. Each read settles on its own, so a failed read prints a line and the rest still count, and a null result is reported and skipped. Nothing is signed or sent.
Turning the rate into a finding
Read three things together: the rate, the leading error and the failing program. A high rate led by the program's own Custom code, with the queried program as the one that failed, means callers keep hitting its checks. That is usually stale quotes or tight slippage, and the fix sits in how callers quote and send. A mix led by ComputationalBudgetExceeded points to compute limits set by guess. A token program as the failing program, with Custom 1 as the reason, points to callers sending amounts their accounts do not hold.
The fee line sizes the waste. The fee field holds base and priority fee together, so the sum is what those five failures cost their signers. Multiply the mean by the failed count in the window for a rough price of the failures among those 100 transactions, and repeat at a few different hours before you quote it. Failed transaction fee tally keeps that sum over time.
A rate that sits high across every window is a finding about the callers. A rate that spikes once is usually one sender in a retry loop, which shows as one repeated error and, when you open the sampled signatures, one fee payer behind them.
Where it ends
- Landed only: a transaction that expired, or failed preflight, or was dropped, is not in the list. Dropped transaction detector covers that side.
- Sample: five reads name the failing program for five transactions out of up to 100. A skewed sample can mislead, so raise the slice size before acting on a split.
- Window: the list is the newest 100 entries. For more, page back with before, as Signature history pagination shows. The list comes from an address index that keeps up to 30 days, so paging stops there, and an older listed signature can return null from getTransaction.
- Nesting: the failing instruction index is a top-level one. A program called by another program that fails shows as the outer instruction's program, so the logs are needed to see the inner one.
- Cause: the error says where a transaction failed and says nothing of why the caller sent it. The logs and the caller's own records answer that.
- Path: the list cannot tell which landing route delivered a transaction, so it cannot split failures between plain sends and any pay-on-success route.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction answers -32015 for a failed transaction. | The transaction is version 1 and the request left out maxSupportedTransactionVersion. Set it to 1 and name an encoding, as the script does. |
| getTransaction returns null for a signature the list just gave. | The address index reaches below the validator's ledger floor, so an older signature can list with no transaction behind it. The script reports the null and moves on; test it on the newest signatures. |
| The run shows 0 failed out of 100 on a program you expect to fail. | Failures cluster in time, and a window of 100 can fall in a quiet stretch. Rerun later, or page back and count a larger window before you conclude the rate is low. |
| Every sampled failure shows outside an instruction. | The error is not an InstructionError, so it has no failing instruction to name. Read the error label line for the reason. |
| The failing program is the router, but the cause sits in a token program. | The error index points at the top-level instruction, and an inner call that fails is reported under the outer program. Read the transaction logs for the inner program. |
| The run stops with getSignaturesForAddress failed. | Check that the argument is a base58 program address and that the key is set in CARBIUM_KEY. The report cannot continue without the list. |
Questions
Does a failed transaction cost the sender anything?
Yes. It pays the base fee per signature and any priority fee it set, and the program's changes are undone. The fee line in the report adds up what the sampled failures paid.
Why not read a block to get the rate?
A block holds every program's transactions, so one program's rate means reading many and filtering them. The address list already holds only the transactions that name the program.
Why does another dashboard show a different rate for the same program?
Windows differ, and so does the counting rule. Some tools count transactions that invoke the program, and this list counts every transaction that names it, passengers included. Commitment level shifts the newest entries too.
What failure rate counts as high?
No fixed line applies. Callers that simulate and send fresh state sit low, and callers that fire stale quotes sit high. Judge a program against its own windows over days.