library / Integrations / Search and time series / I0132
OpenSearch wallet activity search
A short Node job lists every signature an account has in Carbium's 30-day address index, reads the first few full transactions, and writes one OpenSearch bulk file you can load and search.
What the job writes
The question names web3.js. This job uses @solana/kit 8.6.0 and two standard RPC calls to Carbium: getSignaturesForAddress to list the account's signatures, and getTransaction for the first few full transactions.
The job writes one file, wallet-activity.ndjson, in OpenSearch's bulk format. Each signature becomes one document with the fields below. The code calls only Carbium and writes only that local file.
| Field | Taken from |
|---|---|
| signature | the signature of each getSignaturesForAddress entry |
| slot | the entry's slot, as a number |
| blockTime | the entry's Unix time as an ISO 8601 UTC string, or null |
| failed | true when the entry's err is set |
| memo | the memo the entry carries, or null |
| confirmationStatus | the commitment the entry reached when read, or null |
The document id is the signature. A second run writes the same ids, so OpenSearch replaces the earlier documents instead of adding copies.
Paging back through the index
getSignaturesForAddress returns the newest signatures first. The job asks for 1000 a page, the most the method takes, and passes the last signature of each page as before to get the page after it. One call costs 50 cells, and the Free plan allows 0.24 req/s of this method, so a busy account takes a while to page through on a small plan. An empty page ends the walk.
Carbium builds this address index from the last 30 days only. A walk that ends on an empty page has reached the edge of the index, and the account may hold older transactions that this job cannot list. An empty page past 30 days marks the index's age limit, so rate and history limits decide what this job can see.
Reading full transactions
A signature shows that a transaction exists, not what it did. For instructions, balances and logs, call getTransaction with the json encoding and maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and without that option the call answers -32015 for a v1 transaction or for a block that holds one. Each read costs 50 cells, so the job reads only the number of signatures you pass as the third argument.
The index can list a signature whose transaction the validator's ledger no longer holds. getTransaction then returns null, and the job prints that line and keeps going. Each read has its own allSettled slot, so one rejected call does not hide the others. The config object is declared as const so the literal 1 matches the kit's version type, and it names confirmed, the commitment @solana/kit sends when a call leaves commitment out.
Run it
Export CARBIUM_KEY and run the file with the address, the number of pages and the number of transactions to read. With no arguments it lists one page of the Token program's newest signatures and reads three transactions. The output names each page and each read, and the file lands in the working directory.
// I0132 · OpenSearch wallet activity search// https://carbium.sh/library/integrate/opensearch-wallet-activity-search// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature } from "@solana/kit";import { writeFile } from "node:fs/promises";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium key."); process.exit(1);}const TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";const target = address(process.argv[2] ?? TOKEN_PROGRAM);const pages = Number(process.argv[3] ?? 1);const details = Number(process.argv[4] ?? 3);const OUT = "wallet-activity.ndjson";const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const iso = (t: bigint | null) => (t === null ? null : new Date(Number(t) * 1000).toISOString());const docs: string[] = [];const sigs: Signature[] = [];let before: Signature | undefined;for (let p = 1; p <= pages; p++) { const page = await rpc .getSignaturesForAddress(target, { limit: 1000, before }) .send() .catch((err: unknown) => { console.error(`page ${p} failed, the file keeps the pages read so far:`, err instanceof Error ? err.message : err); return null; }); if (page === null) break; if (page.length === 0) { console.log(`page ${p}: empty, the index holds nothing older`); break; } before = page[page.length - 1].signature; console.log(`page ${p}: ${page.length} signatures`); for (const s of page) { sigs.push(s.signature); docs.push(JSON.stringify({ index: { _index: "wallet-activity", _id: s.signature } })); docs.push(JSON.stringify({ signature: s.signature, slot: Number(s.slot), blockTime: iso(s.blockTime), failed: s.err !== null, memo: s.memo ?? null, confirmationStatus: s.confirmationStatus ?? null, })); }}const cfg = { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed" } as const;const picks = sigs.slice(0, details);const reads = await Promise.allSettled(picks.map((s) => rpc.getTransaction(s, cfg).send()));reads.forEach((r, i) => { if (r.status === "rejected") console.error(`getTransaction ${picks[i]} failed:`, String(r.reason)); else if (r.value === null) console.log(`${picks[i]}: null, the ledger no longer holds it`); else console.log(`${picks[i]}: ${r.value.meta?.err ? "failed" : "ok"}, fee ${r.value.meta?.fee ?? 0} lamports`);});await writeFile(OUT, docs.join("\n") + "\n");console.log(`wrote ${sigs.length} documents to ${OUT}`);
run: node main.ts
Loading the file into OpenSearch
The file is newline-delimited JSON. Each document line follows an index action line, which is the shape OpenSearch's _bulk API takes. The job does not contact OpenSearch, so post the file yourself from a machine that can reach your cluster: curl -s -H 'content-type: application/x-ndjson' -X POST $OPENSEARCH_URL/_bulk --data-binary @wallet-activity.ndjson
After the load, a range query on blockTime or a match on memo runs inside OpenSearch and returns signatures. Open the ones you need with getTransaction for their bodies, which the job does not store.
Where it ends
- The index reaches back 30 days. Signatures older than that are not listed, and this job reads no older history.
- The file holds six fields per signature. It does not decode instructions, token amounts or inner instructions, and it reads transaction bodies only for the count you pass.
- Each page is one 50 cell call. A wallet with many signatures in 30 days needs many pages, so raise the page count with the rate in mind.
- A failed page stops the walk, and the file keeps the pages already read. The job does not retry a 429: a call over its rate waits once, then fails with a 429 and a retry-after hint.
- The file is written once, after the walk, so a process stopped mid-run leaves no file.
- The commitment is the one the index reported when the job read it. A signature can move to finalized later, and the file keeps the value it had.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The first page is empty for an address you know is busy. | Check the address string. An empty first page means the index holds no signature for that address in the last 30 days, so there is no older page to read either. |
| getTransaction answers null for signatures the page listed. | The validator's ledger no longer holds those transactions. Keep the signature document, which is already written, and skip the body. |
| getTransaction fails with -32015 for a transaction the index listed. | The call is missing maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, so set it as the job does. |
| A page fails with HTTP 429 and the file holds only the first pages. | The account's budget is spent, and all of its keys share it. Wait for the retry-after hint, then run again with a page count that covers the gap. The ids replace the earlier documents. |
| OpenSearch rejects the bulk request with a parse error. | The file must end with a newline, and each document line must follow its action line. Post it unchanged with the application/x-ndjson content type, and do not pretty-print it. |
Questions
Does this return every transaction an account has ever had?
No. The job lists what Carbium's address index holds, which reaches back 30 days. Older history is outside what this job can read from Carbium.
Why store signatures and not full transactions?
A signature document is small and searches well by time, slot and memo. A full read costs 50 cells, so open only the few you need with getTransaction once the search has narrowed them.
Can I run it on a schedule?
Yes. Each run starts at the newest signature, and the signature ids replace earlier documents, so the file holds one document per signature. Pass a page count that covers the time since the last run.
Why does it default to the Token program?
The Token program is busy, so the default runs at once without a wallet address. Pass your own address as the first argument to read its history.