library / AI and blockchain / SI0034
Recent wallet history Q&A
What the three history methods answer, and a script that lists a wallet's newest transactions, reads each one for its fee and SOL change, and checks the newest against its block. It also shows where the 30-day index ends.
What each method answers
The transaction and block reads come from the validator's ledger, and on Carbium the signature list comes from a 30-day address index. They answer different questions, and picking the wrong one is the usual reason a history job runs slowly or comes back empty.
| Method | Question it answers |
|---|---|
| getSignaturesForAddress | Which transactions mentioned this address, newest first? |
| getTransaction | What did this one signature do? |
| getBlock | What happened in this whole slot? |
A wallet's history is the first two in sequence. The list call returns, for each entry, a signature, slot, block time, an error field and a confirmation status. It says nothing about what the transaction did. The transaction call fills that in: the fee, the balances before and after, the logs and the instructions.
Reach for getBlock when the question starts from a slot, such as which transactions landed in slot N. That is the shape of an explorer's block page or an indexer that walks the chain in order. A wallet question can go through getBlock only by scanning every block, which is why the address index exists.
The history walk
The script takes a wallet address as its first argument. With none, it reads the newest signature that mentions the USDC mint and uses that transaction's fee payer, so a run always starts from a wallet with fresh activity. It then lists the five newest signatures, fetches each transaction, and reads the block of the newest slot.
// SI0034 · Recent wallet history Q&A// https://carbium.sh/library/si/recent-wallet-history-q-a// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Recent wallet history: list signatures, read each transaction, check the newest against its block.// Run: CARBIUM_KEY=... node main.ts [wallet]import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature } 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 } }));type Tx = { slot: bigint; blockTime: bigint | null; meta: { err: unknown; fee: bigint; preBalances: readonly bigint[]; postBalances: readonly bigint[] } | null; transaction: { message: { accountKeys: readonly string[] } };};// maxSupportedTransactionVersion 1 keeps a v1 transaction from answering -32015.const getTx = async (signature: Signature) => (await rpc.getTransaction(signature, { maxSupportedTransactionVersion: 1, encoding: "json" }).send()) as unknown as Tx | null;const usdcMint = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";// With no argument: the fee payer of the newest transaction that mentions the USDC mint.async function pickWallet(): Promise<string> { try { const [newest] = await rpc.getSignaturesForAddress(address(usdcMint), { limit: 1 }).send(); const tx = newest ? await getTx(newest.signature) : null; return tx?.transaction.message.accountKeys[0] ?? usdcMint; } catch (e) { console.log("wallet lookup failed, using the mint:", (e as Error).message); return usdcMint; }}const wallet = process.argv[2] ?? (await pickWallet());const page = await rpc.getSignaturesForAddress(address(wallet), { limit: 5 }).send();console.log(`${wallet}: ${page.length} signatures`);if (page.length === 0) console.log("empty page: nothing in the 30-day address index");const reads = await Promise.allSettled(page.map(async (entry) => ({ entry, tx: await getTx(entry.signature) })));for (const read of reads) { if (read.status === "rejected") { console.log("read failed:", String(read.reason?.message ?? read.reason)); continue; } const { entry, tx } = read.value; const head = `${entry.signature.slice(0, 8)} slot ${entry.slot}`; if (!tx?.meta) { console.log(`${head} null (older than the ledger floor)`); continue; } const at = tx.blockTime === null ? "no time" : new Date(Number(tx.blockTime) * 1000).toISOString(); const i = tx.transaction.message.accountKeys.indexOf(wallet); const change = i < 0 ? "n/a" : String(BigInt(tx.meta.postBalances[i]!) - BigInt(tx.meta.preBalances[i]!)); console.log(`${head} ${at} ${tx.meta.err ? "failed" : "ok"} fee ${tx.meta.fee} change ${change}`);}const newest = page[0];if (newest) { try { const block = (await rpc .getBlock(newest.slot, { maxSupportedTransactionVersion: 1, encoding: "json", transactionDetails: "signatures", rewards: false }) .send()) as unknown as { signatures?: string[] } | null; const sigs = block?.signatures ?? []; console.log(`slot ${newest.slot}: block lists ${sigs.length} transactions, newest signature ${sigs.includes(newest.signature) ? "found" : "missing"}`); } catch (e) { console.log("getBlock failed:", (e as Error).message); }}
run: node main.ts
Export CARBIUM_KEY, optionally set CARBIUM_RPC_URL, and start the file with node main.ts, which on Node 24 runs the TypeScript as it is.
Each transaction line shows the first 8 characters of the signature, the slot, the block time in UTC, ok or failed, the fee in lamports and the wallet's net SOL change in lamports. The last line names the slot, says whether the newest signature appears among that block's signatures, and gives how many transactions the block lists.
Reading one line of output
- Status comes from the transaction's own error field. A failed transaction still lands in the ledger and still pays its fee, so it shows up in the list with the same cost as a good one.
- The fee payer, the first account in the message, pays the fee. For a wallet that pays its own fees, the SOL change already includes the fee, so a change of -5000 with fee 5000 means nothing else moved.
- A change of 0 means the wallet was only mentioned, for example as a read-only account, or someone else paid the fee.
- Token movements live in separate token accounts. Reading them needs the token balance fields in the same transaction answer, and a wallet can own several token accounts for one mint.
All three calls leave commitment out, so @solana/kit sends confirmed. The server's own default is finalized.
Paging and the 30-day edge
getSignaturesForAddress returns up to 1,000 entries a call. To go further back, pass the oldest signature of a page as before and read the next page. until stops the walk at a signature you already hold, which is how a poller picks up only what is new.
On Carbium these pages come from an address index that keeps up to 30 days. Older history is not served. An empty page past 30 days marks the index's age limit, and the address may have older transactions.
The index reaches below the validator's ledger floor, so the list can name a signature whose transaction getTransaction no longer holds. That call then answers null. The script prints those lines as null and carries on. The newest signatures resolve, so the script reads those.
Versions and cost
Mainnet carries v1 transactions. getTransaction and getBlock take maxSupportedTransactionVersion: 1 together with an encoding. With the value absent or 0 they answer -32015, uncharged, for a v1 transaction or for a block that holds one, and one such transaction in a block fails the whole block read. @solana/kit 8.6.0 types the value as 'legacy' | 0 | 1, so 1 needs no cast.
getSignaturesForAddress and getTransaction each cost 50 cells. The list call allows 0.24, 1.2, 100 and 500 req/s on Free, Dev, Business and Pro. getTransaction allows 0.24, 1.2, 5 and 25 req/s. A class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger, so at least 20 of these calls can go out at once on any plan. The script's no-argument run makes two list calls, six transaction reads and one block read, and the list calls and the transaction reads each fit inside that. A longer walk on a low plan needs spacing between calls.
When getBlock is the right call
The script asks for transactionDetails: "signatures", which returns the signature list without transaction bodies. That is the light way to ask what a slot held. The full form returns every transaction with its metadata and makes a large answer.
Mainnet blocks carry no vote transactions since Alpenglow, so a block's list holds user and program transactions only. A slot whose leader never produced a block has nothing to read, and the call answers with an error for that slot. Check the slot before treating the answer as a failure of the call.
Where it ends
- Wallet history stops at 30 days. A job that needs older transactions needs its own store, filled while the data is still in range.
- The list shows transactions that mention the address. A token transfer to an existing token account lists the token accounts and the sender's authority, so the receiving wallet may not appear in it. Query the token account for those.
- The SOL change uses the message's account keys. A wallet that reaches a transaction through an address lookup table is not in that list, and the script prints n/a for it.
- The script reads one page of five. A busy wallet has far more, and a real job pages with before and stores the last signature it handled.
- Nothing here signs or sends. The script does not decode instructions, so to learn why a transaction did what it did you still have to read its program logs.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getTransaction answers null for a signature the list just returned. | The index reaches below the ledger floor, so an older signature can be listed without its body. Treat null as a normal answer and work from the newest signatures. |
| getTransaction or getBlock answers -32015. | Send maxSupportedTransactionVersion: 1 with an encoding on both calls. A single v1 transaction in a block fails the whole block read. |
| A wallet with a long past returns an empty page. | The address index keeps up to 30 days, and an empty page past that marks its age limit. The wallet may have older transactions that this call does not serve. |
| A loop over many signatures starts returning 429 on a Free key. | Each getTransaction costs 50 cells at 0.24 req/s on Free. Space the calls, honour the retry-after hint, and read only the signatures you need. |
| The SOL change prints n/a or looks wrong for a wallet that clearly moved funds. | The wallet may sit in an address lookup table, so it is missing from the message's account keys. Read the loaded addresses in the transaction's metadata and search those as well. |
| getBlock for a slot errors although the slot number is recent. | A slot can have no block when its leader never produced one. Pick the slot from a signature's own slot field and the block exists. |
Questions
Are these methods archival?
They read stored history, and how far back depends on the node. On Carbium the address list reaches back 30 days at most, and getTransaction can answer null for an older signature the list names.
Do I need getBlock to see a wallet's history?
No. The signature list plus getTransaction answers a wallet question. getBlock suits a question that starts from a slot.
Why does getSignaturesForAddress not tell me what a transaction did?
It returns an index entry: signature, slot, time, error and confirmation status. The transaction body, with fee, balances and logs, comes from getTransaction.
How do I poll a wallet for only the new signatures?
Keep the newest signature you have handled and pass it as until on the next list call. The call then returns only the entries newer than it, newest first.