---
id: I0011
title: "Wallet watch list at scale"
url: https://carbium.sh/library/integrate/wallet-watch-list-at-scale
collection: Integrations
category: Document and key-value stores
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Wallet watch list at scale

A Node watcher keeps wallets in a SQLite table, reads their SOL balances from Carbium in batches, and prints a line when a balance moves. Quiet wallets back off to an hourly check, so calls go to the active ones.

## What the watcher does

The watcher keeps a list of wallets in a SQLite file and reads their SOL balances from Carbium in batches of 100 pubkeys by default. Every wallet has a due time. A wallet whose balance moved is checked again after 20 seconds. A wallet that stays still waits twice as long after each quiet read, up to an hour. A balance change prints one line with the old and new lamports and the slot of the read.

That one rule carries the efficiency. A watch list of millions is mostly idle addresses, and a read of an idle address returns the number you already hold. The backoff spends calls where balances move and lets a quiet wallet cost one read an hour.

| Read result | Next check |
|---|---|
| First read of a wallet: the balance is stored as a baseline. | After 20 seconds. |
| The balance differs from the stored one: a line is printed. | After 20 seconds. |
| The balance equals the stored one. | After twice the previous gap, up to 3,600 seconds. |

The watcher prints to the console and delivers nowhere else. Sending a line to a webhook or a queue is the next step, and the table is what that step reads.

## The Solana side: one batched read

The watcher talks to the [RPC endpoint](https://carbium.sh/docs#endpoints) at `https://services.carbium.sh`. The code builds one client at start and reuses it for every call.

`getMultipleAccounts` takes up to 300 pubkeys and [charges 10 cells per pubkey](https://carbium.sh/docs#rpc), but the [1024-cell burst](https://carbium.sh/docs#limits) caps a call at 100 pubkeys below Pro. A batch of 100 costs about 1,000 cells and fits every plan, so `BATCH` defaults to 100. Pro can set `BATCH=300`, which costs about 3,000 cells a call. The call asks for `base64` with a `dataSlice` of length 0. The reply still carries lamports for each address, and no account data travels, which is all a wallet balance needs. An address that does not exist comes back as `null`. The code stores 0 lamports for it, so a wallet that is funded later shows up as a change.

Subscriptions do not reach this size. On Carbium `accountSubscribe` stays silent for a plain SOL wallet, and the route that works is [`logsSubscribe` with mentions plus `getBalance`](https://carbium.sh/docs#websocket). The standard `mentions` filter names one address per subscription, subscription counts are capped per account by tier, and Free carries 5 sockets. A million wallets cannot each hold a subscription.

## The store: one table and a due time

The list lives in SQLite through `node:sqlite`, which needs no dependency. The table `wallet` has four columns: `addr` (the primary key), `lamports` (the last balance seen), `gap` (the last wait used, which the next quiet read doubles up to 3,600 seconds) and `due` (the Unix time of the next check), with an index on `due`. Lamports are stored as text because total supply in lamports is larger than the largest integer a JavaScript number holds exactly.

Seeding takes addresses on the command line, or one per line from the file named in `WALLETS_FILE`, which suits a list too long for a command line. All of it goes in one transaction with `INSERT OR IGNORE`, so a restart with the same list keeps every stored balance and gap. `address()` from `@solana/kit` checks each line, and a malformed one stops the start before anything commits.

Each round picks `due <= now ORDER BY due` with a limit of one batch. The index answers that without a scan, so the work of picking a batch follows the number of wallets that are due and ignores the size of the list. The database path is `WATCH_DB`, default `watch.db`.

## The watcher

Install the one dependency with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types on load. `CARBIUM_KEY` is required and the file exits with a message when it is unset. `CARBIUM_RPC_URL`, `WATCH_DB`, `WALLETS_FILE` and `BATCH` are optional. `BATCH` defaults to 100, which every plan accepts, and Pro can set `BATCH=300`.

`main.ts` (run: `node main.ts WALLET_1 WALLET_2`)

```ts
// I0011 · Wallet watch list at scale
// https://carbium.sh/library/integrate/wallet-watch-list-at-scale
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isSolanaError,
  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,
} from "@solana/kit";
import { readFileSync } from "node:fs";
import { DatabaseSync } from "node:sqlite";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY.");
  process.exit(1);
}
const MIN_S = 20; // gap after a first read or a change
const MAX_S = 3600; // longest gap for an idle wallet
const BATCH = Number(process.env.BATCH ?? 100); // pubkeys per call: 100 fits every plan, Pro can set 300
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

// One client, built once at start.
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const db = new DatabaseSync(process.env.WATCH_DB ?? "watch.db");
db.exec("CREATE TABLE IF NOT EXISTS wallet (addr TEXT PRIMARY KEY, lamports TEXT, gap INTEGER NOT NULL, due INTEGER NOT NULL)");
db.exec("CREATE INDEX IF NOT EXISTS wallet_due ON wallet (due)");

const input = (process.env.WALLETS_FILE ? readFileSync(process.env.WALLETS_FILE, "utf8").split("\n") : process.argv.slice(2))
  .map((s) => s.trim())
  .filter(Boolean);
const add = db.prepare("INSERT OR IGNORE INTO wallet (addr, gap, due) VALUES (?, ?, 0)");
db.exec("BEGIN");
for (const a of input) add.run(address(a), MIN_S); // address() rejects a malformed line
db.exec("COMMIT");

type Row = { addr: string; lamports: string | null; gap: number };
const pick = db.prepare("SELECT addr, lamports, gap FROM wallet WHERE due <= ? ORDER BY due LIMIT ?");
const save = db.prepare("UPDATE wallet SET lamports = ?, gap = ?, due = ? WHERE addr = ?");
console.log(`watching ${(db.prepare("SELECT count(*) AS n FROM wallet").get() as { n: number }).n} wallets`);

for (;;) {
  const now = Math.floor(Date.now() / 1000);
  const rows = pick.all(now, BATCH) as Row[];
  if (rows.length === 0) {
    await sleep(1000);
    continue;
  }
  // The read comes first: a failed call leaves every row untouched and no transaction open.
  const res = await rpc
    .getMultipleAccounts(rows.map((r) => address(r.addr)), { commitment: "confirmed", encoding: "base64", dataSlice: { offset: 0, length: 0 } })
    .send({ abortSignal: AbortSignal.timeout(10_000) })
    .catch(async (e: unknown) => {
      const limited = isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && e.context.statusCode === 429;
      const wait = limited ? Number(e.context.headers.get("retry-after")) || 1 : 10;
      console.error(`${limited ? "429" : "read failed"}: ${e instanceof Error ? e.message : e}; next call in ${wait} s`);
      await sleep(wait * 1000);
      return null;
    });
  if (!res) continue;
  const { context, value } = res;
  let fresh = 0;
  let moved = 0;
  db.exec("BEGIN");
  rows.forEach((r, i) => {
    const lamports = String(value[i]?.lamports ?? 0n); // a missing account counts as 0
    const isNew = r.lamports === null;
    const changed = !isNew && r.lamports !== lamports;
    if (changed) console.log(`${r.addr} ${r.lamports} -> ${lamports} lamports at slot ${context.slot}`);
    fresh += isNew ? 1 : 0;
    moved += changed ? 1 : 0;
    const gap = isNew || changed ? MIN_S : Math.min(r.gap * 2, MAX_S);
    save.run(lamports, gap, now + gap, r.addr);
  });
  db.exec("COMMIT");
  console.log(`read ${rows.length} wallets at slot ${context.slot}: ${fresh} new, ${moved} changed`);
}
```

Run it with wallet addresses as arguments, or with `WALLETS_FILE=wallets.txt`. The first batch prints how many wallets it read and how many are new. Later rounds print a line for each balance that moved.

## What a sweep costs

One read of a million wallets is about 10 million cells: 10,000 calls of 100 pubkeys, or 3,334 calls of 300 on Pro. At the 3,600 second ceiling a million idle wallets need about 278 wallet reads a second. That is about 2.8 `getMultipleAccounts` calls a second at 100 pubkeys (0.93 at 300) and about 2,778 cells a second, before any wallet that moved is counted. A list of 5,000 idle wallets needs about 1.4 wallet reads, 0.014 calls and 14 cells a second.

Every wallet starts at a 20 second gap and takes about eight reads (20, 40 ... 2,560, then 3,600 s) before it settles hourly, so the first pass costs about eight sweeps of the list before the steady rate applies.

Account reads have their own [rate class](https://carbium.sh/docs#rpc) at 10 cells each: 0.5, 15, 50 and 400 req/s on Free, Dev, Business and Pro. In cells that is 5, 150, 500 and 4,000 a second. Set against those, the million-wallet list at 2,778 cells a second fits only Pro, and the 5,000-wallet list at 14 cells a second fits Dev and above but not Free. Pro can set `BATCH=300` to cut the same load to about 0.93 calls a second.

Limits are [per account](https://carbium.sh/docs#limits), so every key on the account draws on one budget. When a call is refused, the watcher sleeps for the hint it gets back and sends the same batch again, with every row untouched.

## Where it ends

- Polling sees a balance at the moment of the read. A wallet that receives and sends the same amount between two reads shows no change.
- It reads SOL balances only. The lamports of a token account stay put when its token amount moves, so token balances need the account data.
- A change line does not name the transaction. `getSignaturesForAddress` can, at 50 cells a call, and Carbium serves it from its own [address index](https://carbium.sh/docs#migrate), which reaches back 30 days at most. Call it only for wallets that moved.
- A wallet that wakes after a long quiet spell is noticed up to 3,600 seconds late, because its gap has grown to the ceiling.
- Polling does not give prompt news for the whole of a very large list. For that, the [gRPC stream](https://carbium.sh/docs#stream) at `https://services.carbium.sh:9443` carries chain activity with the key in the `x-token` header, and it opens on Dev, Business and Pro. A consumer there would look each transaction's accounts up in this same table.
- One process owns the file. SQLite takes one writer at a time, so run one watcher per file.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The start exits with an address error from `@solana/kit` and nothing is read. | A line in the list is not a valid 32-byte base58 address, often a cut or merged line. Fix the line and start again. Nothing was committed, so the table is as it was. |
| The log repeats a line that starts `read failed: HTTP error (401)` and ends `next call in 10 s`. | An unknown key gets 401 at the door, so attach the whole key. Check that `CARBIUM_KEY` holds the key itself and that nothing else sets `CARBIUM_RPC_URL`. The key goes in the [`x-api-key` header](https://carbium.sh/docs#auth). The batch is retried each time with its rows untouched. |
| The log shows `429 ... next call in N s` and the same batch repeats. | The commonest cause below Pro is a `BATCH` over 100 pubkeys: it passes the [1024-cell burst](https://carbium.sh/docs#limits) and is refused every time, so set `BATCH` to 100 before anything else. If `BATCH` is already 100, the account's budget is spent, often by traffic on other keys, since limits are per account. Shrink the list, raise the 3,600 second ceiling, or move to a plan with a higher account-read rate. |
| A `getMultipleAccounts` call fails after you raised `BATCH` above 300. | The method takes up to 300 pubkeys. Keep `BATCH` at 300 or below, and at 100 or below unless you are on Pro. |
| A wallet you removed from `WALLETS_FILE` is still being read. | Seeding only adds rows. Remove it with `DELETE FROM wallet WHERE addr = ?` in the SQLite file, or start with a new `WATCH_DB`. |
| A second watcher on the same file stops with a `database is locked` error. | SQLite allows one writer. Run one watcher per file, or split the list into two files and two processes. |

## Questions

### Why not one subscription per wallet?

Carbium caps subscription counts per account by tier, and `accountSubscribe` stays silent for a plain SOL wallet. The workable [subscription route](https://carbium.sh/docs#websocket) is `logsSubscribe` with mentions, which names one address each. A batched read has no such count to run into.

### Why SQLite and not a networked key-value store?

One watcher needs one writer, and a single file holds millions of small rows with an index on the due time. If several watchers must share the list, move the same four columns to a store that can serve a sorted range by due time.

### Can it watch token balances?

Not as written, because the lamports of a token account stay put when its token amount moves. Add the token accounts as rows, set `dataSlice` to offset 64 and length 8 (the amount field), and compare those bytes. [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) reads one such balance.

### What does one pass over a million wallets cost?

About 10 million cells, since each pubkey costs 10 cells: 10,000 calls of 100 pubkeys, or 3,334 calls of 300 on Pro. Idle wallets settle at one read an hour once their gap reaches 3,600 seconds.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts) (How to use Solana, HS0016)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#stream](https://carbium.sh/docs#stream)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
