services
Get a key

library / AI and blockchain / SI0054

Program behavior summary

Turn a program's newest 20 signatures and four fetched transactions into a short behavior sheet: failure rate, distinct callers, instruction names and which way tokens and SOL moved. A model can then answer what the contract does from numbers.

By Carbium · Plain-English chain queries · SI0054 · updated 2026-11-22

01

The sample and its size

A model asked what a contract does guesses from the name unless it gets something recent to read. A short behavior sheet built from the program's newest activity fits in a prompt and gives the model numbers it can quote, each with the size of the sample behind it.

The sample starts with one getSignaturesForAddress call for the program id, limited to 20, at confirmed commitment. It returns the newest signatures with their slot and an err field, which is null for a transaction that succeeded. That field gives the failure rate with no further call. The call costs 50 cells, and its pages come from an address index that keeps up to 30 days, so "lately" here means the last 30 days at most. A program that has been quiet for longer returns a short or empty page.

Only four of the 20 are fetched in full. getTransaction costs 50 cells a read, so the list call plus four reads comes to 250 cells. Twenty signatures are enough for a failure count and four transactions are enough to see which instructions run and which way value moves. Neither is enough for a percentage of anything else, so the sheet prints counts and the sample size beside them.

QuantityWhere it comes fromSample
Failure rateerr in the signature list20 signatures
Distinct fee payersFirst account key of each transaction4 transactions
Instruction namesProgram log lines written while the program runs its own frame4 transactions
Token and SOL flowBalances before and after4 transactions
02

What is read from each transaction

Each fetch is a getTransaction call with encoding: "json", maxSupportedTransactionVersion: 1 and commitment: "confirmed". Mainnet carries v1 transactions, and with the version field absent or 0 the call answers -32015 for one. Transaction version error -32015 walks through that error.

  • The fee payer is the first account key in the message. It is the wallet that paid for the transaction and usually the one that started it. The count of distinct payers tells you whether one wallet or many callers sit behind the activity.
  • Instruction names come from log lines shaped like Program log: Instruction: Name. Every program in a transaction can write them, so the code follows the call stack through the invoke [n] line that opens each frame and the success or failed line that closes it, and counts a name only while the sampled program is the innermost frame. Names written by the token program or by a program the sampled one calls stay out of the count. Many Anchor programs write one name per instruction. A program that writes none gives an empty list, and the sheet says so. Inner instruction tree covers reading the inner instructions of a transaction when the logs are silent.
  • The SOL change of every account is its balance after the transaction minus its balance before, in lamports. The balance arrays also cover accounts loaded from address lookup tables, which the message's own key list leaves out, so the code appends the loaded writable addresses and then the loaded readonly ones to the key list before it indexes the balances.
  • The token change is the same subtraction on uiTokenAmount.amount, kept per mint and per owner. That amount is a raw integer string with no decimals applied.

getTransaction can answer null for a signature the list returned. The index reaches below the validator's ledger floor, so a listed signature can be older than anything the node still holds. The code prints that line and moves on, and the newest signatures are the likeliest to resolve, so the sample takes the first four. Every read sits in its own try, so one failed read leaves the other three intact and the sheet is built from whatever came back.

03

Turning counts into sentences

One file on @solana/kit 8.6.0 and Node 24. Set CARBIUM_KEY before running it. It takes an optional program id as its argument and has a busy program built in for when you give none. CARBIUM_RPC_URL overrides the default endpoint, https://services.carbium.sh.

main.ts
// SI0054 · Program behavior summary// https://carbium.sh/library/si/program-behavior-summary// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Program behavior summary: a behavior sheet for a program from its newest signatures and four transactions.// Run: CARBIUM_KEY=... node main.ts [program-id]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";type Bal = { accountIndex: number; mint: string; owner?: string; uiTokenAmount: { amount: string } };type Meta = { logMessages?: string[] | null; loadedAddresses?: { writable?: string[]; readonly?: string[] } | null; preBalances: (bigint | number)[]; postBalances: (bigint | number)[]; preTokenBalances?: Bal[] | null; postTokenBalances?: Bal[] | null };type Tx = { meta: Meta | null; transaction: { message: { accountKeys: string[] } } };const sigs = await rpc.getSignaturesForAddress(address(program), { limit: 20, commitment: "confirmed" }).send();const failed = sigs.filter((s) => s.err !== null).length;console.log(`${program}: ${sigs.length} newest signatures, ${failed} failed (${Math.round((100 * failed) / Math.max(sigs.length, 1))}%)`);const txs: Tx[] = [];for (const s of sigs.slice(0, 4)) {  try {    const t = await rpc.getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed" }).send();    if (t === null) console.log(`${s.signature.slice(0, 8)} | getTransaction answered null`);    else txs.push(t as unknown as Tx);  } catch (e) {    console.log(`${s.signature.slice(0, 8)} | ${(e as Error).message}`);  }}const payers = new Set<string>();const names = new Map<string, number>();const sol = new Map<string, bigint>();const tok = new Map<string, bigint>();const bump = (m: Map<string, bigint>, k: string, d: bigint) => m.set(k, (m.get(k) ?? 0n) + d);for (const t of txs) {  const keys = [...t.transaction.message.accountKeys, ...(t.meta?.loadedAddresses?.writable ?? []), ...(t.meta?.loadedAddresses?.readonly ?? [])];  payers.add(keys[0] ?? "unknown");  const stack: string[] = [];  for (const l of t.meta?.logMessages ?? []) {    const call = /^Program (\w+) invoke \[\d+\]/.exec(l);    if (call) stack.push(call[1] ?? "");    else if (/^Program \w+ (success|failed)/.test(l)) stack.pop();    else if (stack[stack.length - 1] === program) {      const n = /^Program log: Instruction: (\w+)/.exec(l)?.[1];      if (n) names.set(n, (names.get(n) ?? 0) + 1);    }  }  keys.forEach((k, i) => bump(sol, k, BigInt(t.meta?.postBalances[i] ?? 0) - BigInt(t.meta?.preBalances[i] ?? 0)));  for (const [list, sign] of [[t.meta?.preTokenBalances, -1n], [t.meta?.postTokenBalances, 1n]] as const)    for (const b of list ?? []) bump(tok, `${b.mint}|${b.owner ?? keys[b.accountIndex]}`, sign * BigInt(b.uiTokenAmount.amount));}const top = [...names].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([n, c]) => `${n} x${c}`).join(", ");console.log(`${txs.length} transactions read, ${payers.size} distinct fee payers.`);console.log(`Instruction names in the program's own logs: ${top || "none logged"}.`);const short = (k: string) => (k.split("|")[1] ?? k).slice(0, 8);for (const mint of [...new Set([...tok.keys()].map((k) => k.split("|")[0] ?? ""))].slice(0, 3)) {  const rows = [...tok].filter(([k]) => k.startsWith(`${mint}|`)).sort((a, b) => (a[1] < b[1] ? -1 : 1));  const out = rows[0];  const into = rows[rows.length - 1];  if (out && into && out[1] < 0n && into[1] > 0n)    console.log(`Mint ${mint.slice(0, 8)}: raw ${-out[1]} left owner ${short(out[0])} and ${into[1]} arrived at owner ${short(into[0])}.`);  else console.log(`Mint ${mint.slice(0, 8)}: balances did not move in opposite directions.`);}const s = [...sol].sort((a, b) => (a[1] < b[1] ? -1 : 1));const lo = s[0];const hi = s[s.length - 1];if (lo && hi) console.log(`SOL: largest net drop ${Number(lo[1]) / 1e9} at ${lo[0].slice(0, 8)}, largest net rise ${Number(hi[1]) / 1e9} at ${hi[0].slice(0, 8)}.`);

run: node main.ts

The output is a header line followed by plain sentences. The header gives the program, how many signatures came back and how many of them failed. Next come the number of transactions fetched, the count of distinct fee payers, the three most frequent instruction names with their counts, and one sentence for each of up to three mints and one for SOL.

Counts are kept as counts. A line such as "Route x3" tells a model that one instruction appeared three times in four transactions, and the transaction count sits in the line just above it. A prompt that hands over these lines and asks the model to answer only from them gets answers like "in the four sampled transactions", where a bare summary invites "usually" and "always".

The four reads run one after another, and the class burst of 1,024 cells admits them: a run spends 50 list cells and 200 transaction cells. On Free the transaction class refills slowly, so that burst runs out after about five back-to-back runs. Limits are per account and an account's keys share one budget, so a scheduled run competes with everything else on the account.

04

Reading withdrawals from balance deltas

In this sheet a withdrawal is a balance that went down. A log line named Withdraw is the program's own label. The delta shows what happened: one owner's balance for a mint fell by some amount while another owner's rose.

The code adds up token deltas per mint and per owner. A wallet can own more than one token account for the same mint, and summing by owner gives that wallet one row. A token account closed in the transaction has no entry after it and counts as zero. A token account created in it has no entry before and also counts as zero.

Keying by owner matters because the instruction of a token transfer lists the two token accounts and the sender's authority, and never the receiving wallet. The balance records in the transaction metadata carry the owner of each token account, so the receiver shows up in the sheet even though the instruction never named it.

For each mint the sheet prints the largest drop and the largest rise. When one owner's drop and another owner's rise are close in size, that is a transfer between them. A drop with no matching rise can mean the tokens were burned, the rise was split across several owners, it shows up as SOL because a wrapped SOL account closed, or the matching rise sits in a transaction outside the sample. Amounts are raw units. Divide by ten to the power of the mint's decimals, which getTokenSupply returns, before you tell a model a human-sized number.

SOL uses the same arithmetic in lamports, divided by a billion in the output. The fee payer's balance falls by the transaction fee, so the largest SOL drop is often a payer covering fees. Say so in the prompt, or the model will call a fee a withdrawal.

$This file reads. Moving tokens out of a program's vault takes the program's own withdraw instruction, signed by the authority the program names, and nothing here builds, signs or sends one. The sheet shows who lost and gained tokens lately.
05

Where it ends

  • Four transactions are an anecdote. The failure count over 20 signatures is a count, and the other numbers describe four transactions. Raise the slice if you need more, at 50 cells for each extra read.
  • The window is 30 days at most. A claim about what the program did at launch or last year has no source here.
  • Instruction names exist only for programs that log them, and only the program's own frames count: names that programs it calls write are left out. An empty list says the logs are silent and says nothing about the program doing nothing.
  • A signature list for a program id includes transactions that merely name it among their accounts, so some of the 20 are not calls into it.
  • A delta shows direction and size and says nothing about intent. A drop can be a withdrawal, a fee, a burn or one leg of a swap.
  • A failed transaction in the four moves only its fee, so its token section is empty. The code does not filter these out, and the failure rate in the header tells you how many to expect.
06

When it goes wrong

what goes wrongwhat to do
Every getTransaction line says it answered null.The listed signatures are older than the node's ledger. Run it again against a busier program, or when the program has fresh activity. The sheet still prints the failure rate from the list.
A read answers -32015.maxSupportedTransactionVersion is missing or 0 in the call. The file sets it to 1, so restore that value if you edited the config.
Some reads fail with 429 and the sheet shows fewer than four transactions.A run spends 200 cells on the transaction class, whose 1,024-cell burst covers about five runs in a row before the 0.24 req/s refill on Free leaves the next one short. The failed lines name the error. Wait out the retry hint and run again, or move to a plan with more room.
The sheet says no instruction names appear in the logs.The program writes no instruction log lines. Decode the instruction data with the program's IDL, or read the inner instructions of one transaction by hand.
The run stops with 401 UNKNOWN_KEY.Attach the whole key. Check that CARBIUM_KEY has no trailing space or newline from a copy.
07

Questions

Why four transactions and not all twenty?

Each read costs 50 cells, so twenty reads would spend 1,000 cells, almost all of a class's 1,024-cell burst, against 200 for four. Four reads are enough to show which instructions run and which way value moves, and the failure rate already covers all twenty.

Can the sheet tell a model how to withdraw tokens from a contract?

No, it reads recent activity and shows who lost and gained tokens. A withdrawal is an instruction the program defines, found in its IDL or source and signed by the authority it names, and the deltas afterwards confirm what moved.

How do I sample a program that logs no instruction names?

The sheet prints that no names were logged, and the failure rate and token flow still come out. For names, decode the instruction data of one fetched transaction with the program's IDL, or read its inner instructions by hand.

How do I hand the sheet to a model?

Paste the output lines into the prompt with the program id and tell the model to answer only from them and to repeat the sample size with each claim. Ask it to say so when the lines do not cover the question.