library / How to use Solana / History and parsing / HS0160
Failed transaction history filter
One TypeScript file pages through an address's newest signatures, keeps the ones whose err field is set, and reads the program logs of the first few. It only reads, with no keypair and no transaction sent.
What the signature list holds
Solana keeps a failed transaction on the ledger like any other. It was included in a block, so it has a signature, a slot and a block time, and its fee was taken. The field that separates it is err on each row returned by getSignaturesForAddress. A successful row carries null there. A failed row carries an object that names the failing instruction index and the error the program returned.
That means the failure list can be built from one RPC method. The job does not need to fetch each transaction to know that it failed. The call pages back through the address's newest signatures, 100 at a time, using limit and before, and the filter keeps the rows whose err is set. Only the reason needs a second call, getTransaction, and this file makes that call for the first three failures only, because each lookup costs more than a list page.
The list call passes commitment: "confirmed" explicitly. @solana/kit 8.6.0 fills in confirmed when a call leaves commitment out, while the JSON-RPC server defaults to finalized. Passing it keeps the read the same whichever client runs the file. If a record of failures feeds accounting, read the same addresses again at finalized before you keep the record.
The code
Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24, which strips the types on load. The first argument is the address. The optional second argument is the number of pages, from 1 to 5. The default run reads the newest 100 signatures.
// HS0160 · Failed transaction history filter// https://carbium.sh/library/howsolana/failed-transaction-history-filter// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature,} from "@solana/kit";type SigRow = { signature: Signature; slot: bigint; blockTime: bigint | null; err: unknown };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 [addrArg, pagesArg = "1"] = process.argv.slice(2);if (!addrArg) { console.error("Usage: node main.ts <address> [pages, 1 to 5]"); process.exit(1);}const target = address(addrArg);const pages = Math.min(Math.max(Number(pagesArg) || 1, 1), 5);// Each page holds up to 100 signatures, newest first. Walk back with `before`.const failed: SigRow[] = [];let total = 0;let before: Signature | undefined = undefined;for (let page = 0; page < pages; page++) { const batch: readonly SigRow[] = await rpc .getSignaturesForAddress(target, { limit: 100, before, commitment: "confirmed" }) .send(); const last: SigRow | undefined = batch[batch.length - 1]; if (!last) break; total += batch.length; for (const row of batch) { if (row.err !== null) failed.push(row); } before = last.signature;}async function readTx(sig: Signature) { try { const tx = await rpc .getTransaction(sig, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed" }) .send(); return { ok: true as const, tx }; } catch (error) { return { ok: false as const, error }; }}const shown = failed.slice(0, 3);const details = await Promise.all(shown.map((f) => readTx(f.signature)));console.log(`${target}: ${total} signatures in ${pages} page(s), ${failed.length} failed`);if (failed.length === 0) console.log("No failed signatures in the pages read.");shown.forEach((f, i) => { const d = details[i]; const when = f.blockTime === null ? "no blockTime" : new Date(Number(f.blockTime) * 1000).toISOString(); console.log(f.signature); console.log(` slot ${f.slot} at ${when}`); console.log(` err ${JSON.stringify(f.err, (_k, v: unknown) => (typeof v === "bigint" ? v.toString() : v))}`); if (!d.ok) { console.log(` getTransaction failed: ${String(d.error)}`); return; } if (!d.tx) { console.log(" getTransaction returned null: the node no longer holds this transaction"); return; } const logs: readonly string[] = d.tx.meta?.logMessages ?? []; for (const line of logs.slice(-2)) console.log(` ${line}`);});
run: node main.ts <address> [pages]
The transport sends every call to https://services.carbium.sh with the key in the x-api-key header, and the client is created once. The loop stops early when a page comes back empty. readTx wraps each getTransaction in its own try, so one failed lookup does not hide the others. Mainnet carries v1 transactions, so the file passes maxSupportedTransactionVersion: 1 on every lookup.
Reading a failure
| Field | Where it comes from | Meaning |
|---|---|---|
| signature | list row | The transaction id, in base58. |
| slot | list row | The slot the transaction landed in. |
| blockTime | list row | Unix seconds, or null when the node has none. |
| err | list row | null on success, the error object on failure. |
| logMessages | getTransaction meta | The program log lines in order, or null. |
The logs are where the reason shows. A program that fails with a custom code writes its own line before the error, and the last line before the failure usually names the program that stopped. The file prints the last two lines for each failure. That is enough to separate a slippage limit from a missing account in many cases. Read the whole log when the fix depends on the order of the instructions.
On Carbium
getSignaturesForAddress costs 50 cells per call. Its rate is 0.24 requests a second on Free, 1.2 on Dev, 100 on Business and 500 on Pro. One call returns a page of up to 100 rows, so a busy address and a quiet one cost the same per page. getTransaction costs 50 cells as well. The default run of one page and three lookups therefore spends 200 cells.
The rate limits and the cell costs for each method are in the RPC methods list, and the limits page explains the wait. A call over its rate waits once and is served if its cells refill within one second. Past that, Carbium answers 429 with a retry-after hint. The file does not retry, so a 429 on the list call ends the run, and a 429 on a lookup prints as a failed lookup.
The key goes in the x-api-key header from the endpoints page. The file reads the endpoint from CARBIUM_RPC_URL and falls back to the production host.
Where it ends
The address index reaches back 30 days at most. getSignaturesForAddress pages come from Carbium's own address index, which keeps up to 30 days, and older history is not served. A page that comes back empty past 30 days shows the index's age limit, and the address may still have older failures. This file cannot list last quarter's failures for an address.
The list can name a signature whose transaction the node no longer returns. The index reaches below the validator's ledger floor, so a signature it lists can be older than the transaction data kept on the node. getTransaction then answers null. The file prints that case as a line of its own and keeps the signature and its err from the list.
The file reads the first few failures only, so the logs cover three transactions at most. It prints total and failed for the pages it read and does not turn them into a rate. A failure rate needs a complete count for the same window, and the file does not produce one.
The file does not decode instruction data or map a custom error code to a name. The number is the program's own, and the program's error table gives its meaning. The file prints the number and leaves the name to that table.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The list is empty for an address you know transacted. | Check whether its newest signature is older than 30 days. An empty page past 30 days shows the index's age limit, so older history is not served. Use a window that starts within the last 30 days. |
| getTransaction answers null for a failed signature that the list returned. | The index reaches below the ledger floor. Keep the signature and its err from the list row, and read the logs only where the node still holds the transaction. |
| Error -32015 on a lookup. | The transaction is version 1. Pass maxSupportedTransactionVersion: 1 on the call. Without it, the node answers -32015 for a v1 transaction or a block that holds one. |
| HTTP 429 with a retry-after hint. | Wait the number of seconds in the header, then run again with fewer pages. A call that refills within one second is served after one wait. Past that, Carbium answers 429. |
| Counts differ between two runs a few minutes apart. | New transactions land at the top of the list. Save the last signature of a run and pass it as before in the next run to read only what is new. |
Questions
Does a failed transaction appear in getSignaturesForAddress?
Yes. The row is there with err set to the error object, and its signature, slot and blockTime are filled in like any other row. Only err tells the two apart.
Does a failed transaction cost a fee?
Yes. The fee is charged for a transaction that was included, even when one of its instructions failed. A failure list is therefore also a list of fees spent.
Why not call getTransaction for every signature?
The list already says which rows failed, and getTransaction costs 50 cells per signature. The file reads logs for the first three failures only, and you can raise that limit in the code if you need more.
Can this find failures from last month?
No. The address index on Carbium reaches back 30 days at most, so older history is not served through this method.