library / Integrations / I0070
Wallet transaction CSV export
A Node script lists a wallet's newest signatures from Carbium, reads the newest eight transactions, and writes export.csv with one row per signature: time in UTC, status, fee and the wallet's own SOL change taken from pre and post balances.
The columns and where each comes from
One row per signature is the whole shape of the file. Five columns come from the signature list itself, and two come from a transaction lookup that costs 50 cells a call.
| Column | Source | Note |
|---|---|---|
| signature | getSignaturesForAddress | One row each, newest first. |
| slot | same call | The slot of the block. |
| time_utc | blockTime of the same call | Empty when the node has no block time. |
| status | err of the same call | success when null, failed otherwise. |
| memo | memo of the same call | Quoted, because it is free text. |
| fee_lamports | getTransaction, meta.fee | Newest eight rows only. |
| sol_change_lamports | getTransaction, balances at the wallet's index | Newest eight rows only. |
One list call fills 20 rows while a lookup fills one, so the script looks up the newest eight rows and leaves the fee and change cells of the other twelve empty. An empty cell says the row exists and the number was not read.
Paging the signature list with before
getSignaturesForAddress returns up to limit signatures, newest first, and the script asks for 20. To reach further back, pass the last signature of a page as before in the next call and stop when a page comes back empty. Signature history pagination covers that loop in full.
A page is one 50-cell call, and a class absorbs bursts of 1,024 cells, so a Free key makes about 20 page calls before its 0.24 req/s rate applies. The rate is 1.2 req/s on Dev, 100 on Business and 500 on Pro.
Computing the wallet's own change
getTransaction answers with meta.preBalances and meta.postBalances: one lamport balance for each account key, in the order of the transaction's key list. The wallet's change is the post value minus the pre value at the wallet's index in that list.
The script asks for jsonParsed, where each key is an object with a pubkey. The parsed list already appends the accounts a version 0 transaction loads from lookup tables, so an index found with findIndex is valid for both balance arrays. In the raw encoding you would append meta.loadedAddresses yourself.
When the wallet paid the fee, the fee is already inside the change. A wallet that sends 0.1 SOL and pays the 5,000 lamport base fee shows -100005000, and fee_lamports shows how much of that was the fee. Do not subtract it a second time.
The call carries maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and without that field a lookup of one answers -32015 and is uncharged. Transaction version error -32015 shows that failure by itself.
CSV quoting and time zones
Only the memo needs care. It is free text and can hold commas, quotes and line breaks, so the script wraps it in double quotes and doubles any quote inside it. Every other column is a signature, a number or a fixed word. Rows end in CRLF, the line ending RFC 4180 names.
blockTime is Unix seconds in UTC. The script prints it as 2026-11-22 10:15:30, year first with a space before the time, which spreadsheets usually read as a date and time without a locale setting. The value stays in UTC. For local time, add the offset in a column of your own, for example =C2+TIME(2,0,0) for UTC+2.
Lamports are whole numbers, so a locale that writes a decimal comma causes no trouble. Divide by 1000000000 in a formula to show SOL.
The script
Install @solana/[email protected] and set "type": "module" in package.json. Set CARBIUM_KEY, and CARBIUM_RPC_URL if you use another endpoint. Pass a wallet address as the first argument. With none, the script takes the fee payer of the newest transaction of a busy swap program, so a first run needs no address.
Each of the eight row lookups is one try with 250 ms before it. Eight lookups cost 400 cells, and a class absorbs bursts of 1,024 cells, so even a Free key finishes. The lookup rate is 0.24 req/s on Free, 1.2 on Dev, 5 on Business and 25 on Pro. Finding a wallet adds one signature page and at most five lookups.
// I0070 · Wallet transaction CSV export// https://carbium.sh/library/integrate/wallet-transaction-csv-export// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { type Address, address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";import { writeFileSync } from "node:fs";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));// With no argument: the fee payer of a busy swap program's newest readable transaction.async function busyWallet(): Promise<Address> { const recent = await rpc.getSignaturesForAddress(address("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"), { limit: 5, commitment: "finalized" }).send(); for (const { signature } of recent) { const tx = await rpc.getTransaction(signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment: "finalized" }).send().catch(() => null); const payer = tx?.transaction.message.accountKeys[0]?.pubkey; // the fee payer is always key 0 if (payer) return payer; await sleep(250); } throw new Error("no readable recent transaction to pick a wallet from");}const wallet = process.argv[2] ? address(process.argv[2]) : await busyWallet();const sigs = await rpc.getSignaturesForAddress(wallet, { limit: 20, commitment: "finalized" }).send();const quote = (s: string) => `"${s.replaceAll('"', '""')}"`;const rows = ["signature,slot,time_utc,status,memo,fee_lamports,sol_change_lamports"];const failed: string[] = [];for (const [i, s] of sigs.entries()) { let fee = ""; let change = ""; if (i < 8) { await sleep(250); // one try per lookup, paced inside the burst const tx = await rpc.getTransaction(s.signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment: "finalized" }).send().catch(() => null); const at = tx?.transaction.message.accountKeys.findIndex((k) => k.pubkey === wallet) ?? -1; if (tx?.meta && at >= 0) { fee = String(tx.meta.fee); change = String((tx.meta.postBalances[at] ?? 0n) - (tx.meta.preBalances[at] ?? 0n)); } else { failed.push(`${s.signature.slice(0, 12)}: lookup null or failed`); } } const time = s.blockTime === null ? "" : new Date(Number(s.blockTime) * 1000).toISOString().slice(0, 19).replace("T", " "); rows.push([s.signature, s.slot, time, s.err ? "failed" : "success", quote(s.memo ?? ""), fee, change].join(","));}writeFileSync("export.csv", rows.join("\r\n") + "\r\n");console.log(`wallet ${wallet}`);console.log(rows.slice(0, 4).join("\n"));console.log(`${rows.length - 1} rows written to export.csv`);for (const f of failed) console.error(f);
run: node main.ts
The run prints the wallet, the header and the first rows, then the row count. A lookup that returns null or fails goes to stderr with the first twelve characters of its signature, and its row keeps empty cells. Every call names finalized.
Where it ends
- Thirty days at most. Pages come from an address index that keeps up to 30 days. An empty page past that edge marks the index's age limit, and the address may have older transactions.
- Fee and change fill the newest eight rows. Raising the 8 costs 50 cells a row, and a Free key at 0.24 req/s is held to that rate once the burst is spent.
- Token amounts are left out. The response also carries preTokenBalances and postTokenBalances, but this script reads only lamports, so a token transfer shows up as the fee and any rent it cost.
- Null rows happen. Pages reach below the validator's ledger floor, so getTransaction can answer null for an older signature the list shows. The row stays with empty fee and change cells, and the script lists it.
- The change column sums everything that touched the balance in one transaction: fees, rent deposits, transfers and SOL moved into wrapped accounts. It carries no label for any of them. Transaction explainer decodes what a single transaction did.
- Failed transactions are rows too. Status says failed when err is set, and the fee still left the balance.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The fee and change cells are empty on rows nine to twenty. | Only the newest eight rows are looked up. Raise the 8 in the loop once you have checked the lookup rate of your plan, and expect 50 cells for each added row. |
| stderr shows lookup null or failed for a signature. | Either the node answered null for an older signature that the list returned, or the call failed. The row keeps empty cells. Run again for a failed call, and leave a null row as it is. |
| export.csv holds the header and nothing else. | The wallet has no signature in the 30-day index. Pass an address with recent activity, or drop the argument to let the script find one. |
| A lookup fails with -32015. | The call has no maxSupportedTransactionVersion: 1, or has 0. Restore 1 and run again; the failed call was uncharged. |
| A lookup fails with 429 and a retry-after hint. | The call went over its rate, or a Free key went over its network's shared budget. The script makes one try per call and lists the failure. Run again after the hint, or lower the 8. |
| The time column opens as text in the spreadsheet. | The locale did not accept the year-first form. Import the column as text and split it with a formula, or change the locale of the file. |
Questions
Can I export a year of history?
No. The export reaches back 30 days at most, so page with before until a page comes back empty.
Why does the change differ from the amount I sent?
The column is the whole balance movement of the transaction: the amount, the fee when the wallet paid it, and any rent for accounts the wallet funded. fee_lamports shows the fee part.
Why ask for jsonParsed?
Its key list is objects with a pubkey and already includes lookup-table accounts, so findIndex returns an index that fits both balance arrays in one line.
How would I add token amounts?
The same getTransaction response carries preTokenBalances and postTokenBalances. Match the wallet's token accounts by owner and mint, then subtract the pre amount from the post amount. This script does not do that step, so the token columns would be your own addition.