services
Get a key

library / Use cases / UC0017

Token holder tracker

Holder changes of a mint show in the owner balances inside its transactions. Read only the new ones, turn each into joined and left wallets in a local SQLite file, and size the reads against your plan's rate limits.

By Carbium · Token issuer operations · UC0017 · updated 2026-11-22

01

Holders are owners

A holder is a wallet that owns tokens of a mint. The chain stores those tokens in token accounts, and a wallet can own more than one account for the same mint. A count of the mint's token accounts overstates the holders by every wallet with a second account, and an emptied account stays on chain with an amount of 0 until its owner closes it. The number you want is the count of distinct owners whose balances for the mint add up to more than zero.

The direct way to get it is to list every token account of the mint, or to ask for its largest accounts. Carbium does not serve getTokenLargestAccounts or getProgramAccountsV2. Both are among eight methods that answer -32601, and -32601 is final: do not retry, check the method. getTokenAccountsByOwner works from the wallet side and answers what one wallet holds, as Wallet token holdings shows. It cannot list the wallets of a mint.

That leaves the change feed. The balances recorded in each transaction of the mint's signature list give joins and leaves, which follow the holder count with no scan. Bring the starting number yourself, for example from your allocation list. The tracker keeps it current.

02

Read the balances inside transactions

A transaction's metadata carries preTokenBalances and postTokenBalances: for each token account the transaction touched, the mint, the owner wallet and the amount before and after. The owner field is the useful part. A transfer instruction lists the token accounts and the sender's authority and never the receiving wallet, so the metadata is where the receiving wallet shows up.

For one mint, add up the amounts per owner before and after, since an owner may touch two accounts in one transaction. An owner at 0 before and above 0 after joined. An owner above 0 before and at 0 after left. Any other change moved a balance and left the count alone. An account created and funded in the same transaction is absent from the before list, so it counts as a join. Joins minus leaves over many transactions is the net change.

To find the transactions, getSignaturesForAddress on the mint address lists those that include the mint in their account list: mints, burns and transferChecked calls name it. The until parameter takes the newest signature you finished, and the call returns the newer ones, newest first and at most 1,000 to a page. Each transaction is read once, so the cost follows the traffic of the mint.

03

One pass in one file

The script takes a mint address. Each run is one pass. It lists the signatures after the saved cursor (the newest 10 on the first run), reads up to 8 of the oldest of them first with getTransaction, writes each join and leave to a SQLite file named after the mint, moves the cursor to the last signature it finished and prints the totals. It sends its calls to the RPC endpoint, reads CARBIUM_KEY, exits with a message when it is unset, and signs and sends nothing. Run it again to read the next transactions.

When a page comes back full with 1,000 signatures, older ones may sit between it and the cursor, and reversing it would move the cursor past them. So the script calls again with before set to the oldest signature listed, repeats until a page comes back under 1,000, and works through that oldest page first. Every list call costs 50 cells, one per 1,000 signatures of backlog.

main.ts
// UC0017 · Token holder tracker// https://carbium.sh/library/usecase/token-holder-tracker// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: tracks which wallets join or leave a mint's holders, from the token balances in its newest transactions.import { DatabaseSync } from "node:sqlite";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, 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";if (!process.argv[2]) { console.error("Usage: node main.ts <mint>"); process.exit(1); }const mint = address(process.argv[2]); // throws on anything that is not an addressconst MAX_TX = 8; // transactions read per pass: stays inside the 1,024-cell burst// One client, reused for every call.const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const db = new DatabaseSync(`${mint}.db`);db.exec("CREATE TABLE IF NOT EXISTS cursor (sig TEXT); CREATE TABLE IF NOT EXISTS changes (sig TEXT, owner TEXT, kind TEXT, PRIMARY KEY (sig, owner))");const saved = db.prepare("SELECT sig FROM cursor").get();const cursor = saved ? String(saved.sig) : undefined;type Bal = { mint: string; owner?: string; uiTokenAmount: { amount: string } };type Meta = { preTokenBalances?: Bal[]; postTokenBalances?: Bal[] };// Signatures that name the mint, newest first: the newest 10 on a first run, else those after the cursor.const fail = (e: Error) => { console.error(`list failed: ${e.message}`); return process.exit(1); };const list = (before?: string) => rpc  .getSignaturesForAddress(mint, { commitment: "confirmed", limit: cursor ? 1000 : 10, until: cursor ? signature(cursor) : undefined, before: before ? signature(before) : undefined })  .send();let listed = await list().catch(fail);let total = listed.length;// A full page may hide older signatures above the cursor: page back until one comes back short, then work its oldest page first.while (cursor && listed.length === 1000) {  const older = await list(listed[999].signature).catch(fail);  total += older.length;  if (!older.length) break;  listed = older;}let read = 0, touched = 0, done: string | undefined;for (const s of [...listed].reverse()) { // oldest first, so the cursor never skips work  if (!s.err) {    if (read === MAX_TX) break;    read++;    try {      const tx = (await rpc        .getTransaction(s.signature, { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 })        .send()) as unknown as { meta: Meta | null } | null;      if (!tx?.meta) throw new Error("answered null");      // Per owner: [balance before, balance after], summed over that owner's accounts the transaction touched.      const sums = new Map<string, bigint[]>();      [tx.meta.preTokenBalances ?? [], tx.meta.postTokenBalances ?? []].forEach((list, i) => {        for (const b of list) {          if (b.mint !== mint || !b.owner) continue;          const t = sums.get(b.owner) ?? [0n, 0n];          t[i] += BigInt(b.uiTokenAmount.amount);          sums.set(b.owner, t);        }      });      for (const [owner, [pre, post]] of sums) {        const kind = pre === 0n && post > 0n ? "joined" : pre > 0n && post === 0n ? "left" : "";        if (kind) db.prepare("INSERT OR IGNORE INTO changes VALUES (?, ?, ?)").run(s.signature, owner, kind);      }      touched += sums.size;    } catch (e) {      console.error(`stopped at ${s.signature}: ${(e as Error).message}`);      break; // the cursor stays before this signature    }  }  done = s.signature;}if (done) { db.exec("DELETE FROM cursor"); db.prepare("INSERT INTO cursor VALUES (?)").run(done); }const count = (kind: string) => Number(db.prepare("SELECT COUNT(*) AS n FROM changes WHERE kind = ?").get(kind)?.n);console.log(`${mint}: ${total} signatures listed, ${read} transactions read, ${touched} wallets touched`);console.log(`joined ${count("joined")}, left ${count("left")}, net ${count("joined") - count("left")} since this database began`);

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <mint>

A cursor that moves only past finished work, over signatures taken oldest first, means a pass that stops early skips nothing. A call that fails or answers null ends the pass with the signature printed, since stepping past it would drop a change for good. Failed transactions get no lookup because they moved no tokens. Amounts are base-unit strings from the RPC and are summed as BigInt.

The getTransaction call passes maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and with the field absent or 0 the call answers -32015 for one.

04

Spending the rate limit

Both calls are charged 50 cells at admission, at these requests per second by plan.

CallCellsFreeDevBusinessPro
getSignaturesForAddress500.24/s1.2/s100/s500/s
getTransaction500.24/s1.2/s5/s25/s

A class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. At 50 cells that is 20 calls. One pass reads at most 8 transactions for that reason: a first run on a Free key stays inside the burst. After the burst Free refills at 0.24 calls per second and Dev at 1.2. An account's keys share one budget, so a second key adds nothing.

The cursor reads each transaction once, and the script reuses one client for every call. When a call does come back 429, the script stops and leaves the rerun to your scheduler.

A JSON-RPC post can carry up to 100 calls, sized to the rates in the table. The kit client sends one call per request, so a batch means posting it yourself to the same URL with your key.

To hear about new transactions without listing, open `logsSubscribe` with a mentions filter on the mint. Each notification carries a signature, and the same lookup follows. The subscription opens at 25 credits for the logs-mentions weight, then costs 20 credits per MiB sent, and Free carries 5 sockets. Push replaces the list calls and leaves the lookups as they were, so on a busy mint the lookup rate in the table is still the ceiling. For a similar watcher over deposit addresses, see Multi-address deposit monitor.

05

Where it ends

  • Coverage follows the account list. A plain transfer instruction does not name the mint, so a transaction that moves tokens only that way may never appear in the mint's signatures, and its joins and leaves are missed. Compare the net against a snapshot of your own now and then and read a gap as missed transactions.
  • A second funded account skews the count. The metadata lists only accounts a transaction touched, so a wallet that empties one account while another still holds tokens is recorded as left, and one that funds a fresh account while holding another is recorded as joined, though neither changed status.
  • Window: the address index keeps up to 30 days, and an empty page past that marks the index's age limit while the address may have older transactions. A tracker sees changes from its first pass on, and the baseline is yours to bring.
  • Throughput: a mint with more transactions per second than your plan's lookup rate (Business 5, Pro 25) outruns the tracker. The cursor keeps the count correct while the tracker falls behind, and each pass pages back through the whole backlog. Free and Dev rates (0.24 and 1.2) suit a mint with little traffic.
  • Holders here are owners of token accounts. A liquidity pool's vault or an exchange's account counts as one holder like any wallet. Filter those owners out of the report if your definition excludes them.
  • Balances are not kept. The file stores joins and leaves. A top-holder list needs the balance of every owner, which this tracker does not collect.
06

When it goes wrong

what goes wrongwhat to do
The holder count runs higher than your snapshot.Count owners with a total above 0 for the mint, never token accounts. One wallet can own several accounts. The script sums per owner over the accounts one transaction touches. A second account the transaction left untouched still skews the count, so reconcile against your snapshot.
The net count drifts below a snapshot over time.A plain transfer instruction does not name the mint, so some transactions never reach the mint's signature list. Reconcile against your own snapshot and restart the baseline from it.
getTransaction answers -32015.Pass maxSupportedTransactionVersion: 1 with an encoding. Mainnet carries v1 transactions and the call fails for one when the field is absent or 0.
A pass ends with 429.Rerun later. Keep a pass at or under 20 lookups and at or under 20 list pages, since each rate class has its own burst of 50-cell calls, read each transaction once through the cursor, and remember that an account's keys share one budget.
getTokenLargestAccounts or getProgramAccountsV2 answers -32601 and the client retries it.Treat -32601 as final and remove the call. Count changes from transaction balances instead.
getTransaction answers null for a signature the list just returned.The index reaches below the validator's ledger floor, so an old signature can list and still answer null. The script stops without moving the cursor. Start the database again from newer signatures.
07

Questions

Can one call return the current holder count?

No. getTokenSupply gives the total supply and says nothing about holders, and the two reverse-lookup methods are not served. Bring a baseline count from a snapshot you hold and let the tracker add the changes.

How often should a pass run?

A pass reads at most 8 transactions, so pick the interval from your mint's transactions per pass against your plan's lookup rate in the table. When a pass leaves a backlog, the next one continues from the cursor and loses nothing.

Does it work for Token-2022 mints?

The transaction metadata lists token balances with the same mint and owner fields for both token programs, so the same code applies. Check a transfer-fee mint against your snapshot, since fees change the amounts that arrive.

Can I run two trackers on one account?

Yes, and they draw on one budget: an account's keys share it. Give each tracker its own pass cap so the pair stays inside your plan's rate.