---
id: I0069
title: "Sentry decoded transaction errors"
url: https://carbium.sh/library/integrate/sentry-decoded-transaction-errors
collection: Integrations
category: Chat and notifications
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Sentry decoded transaction errors

A Node script that decodes a failed transaction's InstructionError into a Sentry event: program id from the instruction index, custom code in hex, the failing program from the logs, and a fingerprint that groups one bug into one issue.

## What the err value holds

A failed transaction carries its reason in one JSON value, `err`. When an instruction caused the failure, it is an object with the single key `InstructionError` and an array of two elements, for example `{"InstructionError": [2, {"Custom": 6001}]}`. The first element is the position of the failing instruction in the transaction's top-level instruction list, counting from 0. The second is the reason.

| Reason shape | Example | What it tells you |
|---|---|---|
| A plain string | `"InvalidAccountData"` | The runtime's own verdict. The string is the whole message. |
| An object with text | `{"BorshIoError": "Unexpected length of input"}` | The variant plus text from the program's serializer. |
| Custom | `{"Custom": 6001}` | A number the program picked. Alone it says almost nothing. |

The same pair appears on each row of getSignaturesForAddress, in `meta.err` of a getTransaction result and in the preflight failure that sendTransaction returns. A signature row holds `err`, a slot and a signature, with no logs and no account list, so a useful title needs a second call for the transaction itself. Other failures, such as `BlockhashNotFound` at preflight, use `err` values with no instruction index, and the script handles those separately.

## From instruction index to program id

The index counts the instructions you sent, in order. A compute-budget instruction in front takes position 0, so a swap that sits second fails at index 1. Each instruction names its program by number, as a position in the message's account key list, so a decode needs two lookups: the failing instruction, then its key.

With the plain `json` encoding you do both yourself. For a v0 message that uses address lookup tables, the full list is the static keys, then the writable addresses loaded from tables, then the read-only ones, which sit under `meta.loadedAddresses`. A decoder that goes on to read the instruction's accounts needs that whole list. The script asks for `jsonParsed` instead, where the node fills in `programId` on every instruction, and the lookup becomes `instructions[index].programId`.

The request must carry `maxSupportedTransactionVersion: 1`. Mainnet carries v1 transactions, and with the field absent or set to 0, getTransaction answers [-32015](https://carbium.sh/library/howsolana/transaction-version-error-32015), uncharged, for one of them. kit 8.6.0 types the value as `'legacy' | 0 | 1`, so the 1 needs no cast. kit also fills in `confirmed` when a call leaves commitment out, and both calls in the script run at that level.

> The index names the top-level instruction only. When that instruction is a router that calls a pool and the pool is what failed, the index points at the router. The logs hold the pool's id.

## Custom codes and where their names live

`Custom` holds a decimal number, and the logs print the same number in hex: `Program <id> failed: custom program error: 0x1771` is 6001. Convert once and use the hex form in tags and titles, so an engineer can paste it from a log line into a search box and find the event.

The name behind a code lives with the program that chose it. The transaction carries only the number. Three places hold the name.

- Native programs and the Token program: a Rust error enum in the program's source. In the Token program, 0x1 is `InsufficientFunds` and 0x4 is `OwnerMismatch`.
- Anchor programs: the `errors` array of the IDL, with a code, a name and a message per entry. A program's own errors start at 6000, so 6001 is the second entry, and codes below 6000 belong to the framework, such as the 2000 range for constraint checks.
- Anchor also logs the name before it fails, in a line like `AnchorError thrown in ... Error Code: InsufficientBalance. Error Number: 6001.` When that line is present the name is already in the transaction.

The script ships no name table. It keeps the program id and the hex code as the key for a lookup, and it puts the last three log lines in the event, which is where Anchor's name travels.

## Event shape, tags and fingerprint

Sentry builds an issue title from the exception type and value, so the script sets the type to `InstructionError` and the value to the reason and the failing program, such as `Custom 0x1771 in <program>`.

| Field | Value | Job |
|---|---|---|
| `exception` | type `InstructionError`, value `Custom 0x1771 in <program>` | Issue title |
| `tags` | `program`, `culprit`, `instruction_index`, `error_kind`, `error_code` | Search and filters |
| `fingerprint` | `["InstructionError", culprit, name]` | Grouping |
| `extra` | signature, slot, last three log lines | Detail on one event |

The fingerprint decides whether you read one issue or four hundred. An array of strings replaces Sentry's default grouping for that event, so keep it to what defines the bug: the error class, the failing program and the reason. Leave out the instruction index and the signature. Put a priority-fee instruction in front and the same failure moves from index 1 to index 2, which would split one bug into two issues. Keep amounts out as well, since token and Anchor logs often print them.

`culprit` is the program id from the first `Program <id> failed:` line in the logs. As an error unwinds through nested calls, each frame logs its own failed line, innermost first, so the first one names the program that raised it and the last repeats the top-level program. With no such line the script falls back to the program at the instruction index.

> kit returns `slot` as a bigint, and `JSON.stringify` throws on a bigint. The script passes a replacer that turns each one into a string. Convert before you print or send.

To send the event, pass the same object to `Sentry.captureEvent` in the Node SDK. The script stops at printing it.

## The script

Install with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`; Node 24 strips the types. `CARBIUM_KEY` is required, `CARBIUM_RPC_URL` is optional, and the first argument is a program address that defaults to the Token program. The script reads the newest 100 signatures of that program, takes the newest row whose `err` is set and decodes it.

`main.ts` (run: `node main.ts`)

```ts
// I0069 · Sentry decoded transaction errors
// https://carbium.sh/library/integrate/sentry-decoded-transaction-errors
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

const apiKey = process.env.CARBIUM_KEY;
if (!apiKey) {
  console.error("CARBIUM_KEY is not set.");
  process.exit(1);
}
const client = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": apiKey },
  }),
);

// JSON.stringify throws on bigint, so every bigint becomes a string
const dump = (value: unknown) => JSON.stringify(value, (_k, x) => (typeof x === "bigint" ? x.toString() : x), 2);

type Decoded = { index: number; kind: string; code: string | null };

function decode(err: unknown): Decoded | null {
  const pair = (err as { InstructionError?: unknown } | null)?.InstructionError as [number | bigint, unknown] | undefined;
  if (!Array.isArray(pair)) return null;
  const [index, reason] = pair;
  if (typeof reason === "string") return { index: Number(index), kind: reason, code: null };
  const body = (reason ?? {}) as Record<string, unknown>;
  if ("Custom" in body) return { index: Number(index), kind: "Custom", code: "0x" + BigInt(body.Custom as number).toString(16) };
  return { index: Number(index), kind: Object.keys(body)[0] ?? "Unknown", code: null };
}

function failingProgram(logs: readonly string[]): string | undefined {
  for (const line of logs) {
    const hit = line.match(/^Program (\S+) failed:/);
    if (hit) return hit[1]; // innermost frame logs first
  }
  return undefined;
}

const target = address(process.argv[2] ?? "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
const recent = await client.getSignaturesForAddress(target, { limit: 100 }).send();
const bad = recent.filter((row) => row.err).at(0);
if (!bad) {
  console.log(`No failure among ${recent.length} recent signatures of ${target}.`);
  process.exit(0);
}

const tx = await client.getTransaction(bad.signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send();
if (!tx) {
  console.log(`getTransaction answered null for ${bad.signature}`);
  process.exit(0);
}
const d = decode(tx.meta?.err);
if (!d) {
  console.log("Not an InstructionError:", dump(tx.meta?.err));
  process.exit(0);
}

const ixs = tx.transaction.message.instructions as unknown as { programId: string }[];
const atIndex = ixs[d.index]?.programId ?? "unknown";
const logs = tx.meta?.logMessages ?? [];
const culprit = failingProgram(logs) ?? atIndex;
const name = d.code ? `${d.kind} ${d.code}` : d.kind;

console.log(
  dump({
    level: "error",
    exception: { values: [{ type: "InstructionError", value: `${name} in ${culprit}` }] },
    tags: { program: atIndex, culprit, instruction_index: String(d.index), error_kind: d.kind, ...(d.code && { error_code: d.code }) },
    fingerprint: ["InstructionError", culprit, name], // index, signature and amounts stay out
    extra: { signature: bad.signature, slot: bad.slot, logTail: logs.slice(-3) },
  }),
);
```

If none of the 100 rows failed, the script says so and exits with status 0, and a later run reads a fresh set. An `err` that is not an InstructionError prints raw and stops.

## What a decode costs

A run makes two calls, getSignaturesForAddress and getTransaction, at [50 cells each](https://carbium.sh/docs#rpc), so 100 cells. getSignaturesForAddress allows 0.24 req/s on Free, 1.2 on Dev, 100 on Business and 500 on Pro. Your application already holds the signature of what it sent, so in production only getTransaction runs, once per failed signature. Caching the decoded event by signature keeps a retry loop from paying twice.

## Where it ends

- No IDL lookup. A `Custom` code outside Anchor's log line stays a hex number. Mapping it to a name needs the program's source or its IDL, which you fetch yourself.
- Top-level instruction and log text only. The script does not walk inner instructions; [Inner instruction tree](https://carbium.sh/library/howsolana/inner-instruction-tree) shows that walk. A program that logs nothing leaves the culprit at the top-level program.
- Logs can be cut short. The runtime limits the log buffer and writes `Log truncated`, and the failed line may be missing then.
- One failure per transaction. A transaction stops at its first failing instruction, so there is one event per signature. Errors with no instruction index, such as `InsufficientFundsForRent`, need their own mapping.
- History is 30 days. getSignaturesForAddress comes from an [address index that keeps up to 30 days](https://carbium.sh/docs#migrate), and its pages reach below the validator's ledger floor, so getTransaction can answer null for a signature the list returned. The script prints that and stops.
- It prints and does not send. Delivery and sampling toward Sentry stay with your SDK.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| getTransaction answers -32015 for a signature the list returned. | The call left out `maxSupportedTransactionVersion` or set it to 0. Pass 1 in the config object; a config held in a variable needs `as const`. |
| The script prints `getTransaction answered null`. | The signature sits below the ledger floor that the address index reaches past. Run it again; the script always starts from the newest failed row. |
| `TypeError: Do not know how to serialize a BigInt` when the event prints. | A bigint reached `JSON.stringify`. Slots arrive as bigint. Pass a replacer that returns `v.toString()` for them. |
| One bug opens many Sentry issues. | Something that varies is in the fingerprint: the index, the signature, a slot or an amount from a log line. Keep the error class, the failing program and the reason. |
| Every issue shows the same aggregator program for unrelated bugs. | The fingerprint used the program at the instruction index. Take the program id from the first `Program <id> failed:` log line, as the script does. |

## Questions

### Why does the log show hex when err shows a decimal?

The runtime prints the code in hex in the log and serializes the same number as decimal in `err`. 0x1771 and 6001 are one code.

### Does the same decode work for a sendTransaction preflight failure?

The preflight error carries the same `InstructionError` pair in its `err`, and the simulation logs ride on the error response, so the parsing applies. There is no signature to fetch.

### Which commitment do the calls use?

The script leaves commitment out, so kit 8.6.0 fills in `confirmed` for both calls. The JSON-RPC server's own default is `finalized`.

### Should the instruction index be a tag?

Yes, as a tag it stays searchable. Keep it out of the fingerprint, since the index shifts whenever someone adds an instruction in front.

## Related

- [Transaction version error -32015](https://carbium.sh/library/howsolana/transaction-version-error-32015) (How to use Solana, HS0012)
- [Inner instruction tree](https://carbium.sh/library/howsolana/inner-instruction-tree) (How to use Solana, HS0035)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
