Tokenized asset monitor
A Node script that watches the mint accounts of tokenized assets on Solana, stores a snapshot in SQLite and prints a line when supply, an authority or the extension data changes, plus what each change means and what the polling costs.
What there is to watch
A tokenized real-world asset on Solana is an SPL token. Its issuer decides how much exists, who may mint more and whether a holder's token account can be frozen. Those rules sit in the mint account, which anyone can read. A holder, an integrator or a risk team can watch that account without the issuer's help.
- Supply: the total in base units, with the mint's decimals beside it. Supply moves when the issuer mints or when the issuer or a holder burns, which for a fund token follows subscriptions and redemptions. A jump you did not expect is the first thing to look at.
- Mint authority: the key allowed to create new supply. A new key, or a key where there was none, changes who controls issuance. A mint authority of none means supply is fixed.
- Freeze authority: the key allowed to freeze a holder's token account. Issuers of regulated assets often keep one. A change here changes what a holder can rely on.
- Owner program and extension data: the owner says whether the mint lives under the original token program or Token-2022. Token-2022 mints carry extensions after the first 165 bytes, such as a permanent delegate, a transfer hook or a default account state. An edit there changes how transfers behave.
The script compares the base fields one by one and hashes the bytes after the first 82 on their own. An extension edit therefore raises an alert even when supply moves in the same poll.
One call reads the whole list
Every mint is read with a single getMultipleAccounts call. It charges 10 cells per pubkey and takes up to 300 pubkeys, though below Pro the 1024-cell burst caps a call at 100. A list of 20 mints costs 200 cells per poll, and a list over 100 needs Pro. Account reads are limited to 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro, so size the list and the interval against your plan's figure.
The call goes to https://services.carbium.sh, and the script builds one RPC client at start and keeps it for the whole run. It reads at finalized, set in the call. The reply carries the slot of the read, and the script prints it with every poll.
The monitor in one file
Pass the mint addresses as arguments. The script reads CARBIUM_KEY, an optional CARBIUM_RPC_URL, an optional POLL_MS (10 seconds by default, and a value that is not a positive number falls back to that) and an optional DB path for the SQLite file (monitor.db by default). The run line uses the USDC and wrapped SOL mints as stand-ins, so swap in the mint of your asset.
// UC0015 · Tokenized asset monitor// https://carbium.sh/library/usecase/tokenized-asset-monitor// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only monitor: polls token mint accounts and prints a line when supply, an authority or extension data changes.import { createHash } from "node:crypto";import { DatabaseSync } from "node:sqlite";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder } 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 mints = process.argv.slice(2);if (!mints.length || mints.length > 300) { console.error("Usage: node main.ts <mint> [<mint> ...] (1 to 100 mints, up to 300 on Pro)"); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const ms = Number(process.env.POLL_MS);const pollMs = Number.isFinite(ms) && ms > 0 ? ms : 10_000;const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";type Row = { owner: string; supply: string; decimals: number; auth: string; freeze: string; ext: string };const db = new DatabaseSync(process.env.DB ?? "monitor.db");db.exec("CREATE TABLE IF NOT EXISTS mint (addr TEXT PRIMARY KEY, owner TEXT, supply TEXT, decimals INT, auth TEXT, freeze TEXT, ext TEXT)");const find = db.prepare("SELECT owner, supply, decimals, auth, freeze, ext FROM mint WHERE addr = ?");const save = db.prepare("INSERT OR REPLACE INTO mint VALUES (?, ?, ?, ?, ?, ?, ?)");const last = (mint: string) => find.get(mint) as unknown as Row | undefined;const decoder = getAddressDecoder();// SPL mint layout: COption mint authority (0), supply u64 (36), decimals (44), COption freeze authority (46).const option = (b: Buffer, at: number) => (b.readUInt32LE(at) ? decoder.decode(b.subarray(at + 4, at + 36)) : "none");async function poll() { let events = 0; const emit = (mint: string, slot: bigint, event: string) => { events++; console.log(JSON.stringify({ at: new Date().toISOString(), slot: String(slot), mint, event })); }; // A missing or non-mint address prints once: its event text is kept as a marker in the owner column. const once = (mint: string, slot: bigint, event: string) => { if (last(mint)?.owner === event) return; save.run(mint, event, "", 0, "", "", ""); emit(mint, slot, event); }; // Explicit finalized: kit would fill in confirmed, the server default is finalized. const { context, value } = await rpc.getMultipleAccounts(mints.map(address), { commitment: "finalized", encoding: "base64" }).send(); value.forEach((acc, i) => { const mint = mints[i]!; if (!acc) return once(mint, context.slot, "account missing"); const b = Buffer.from(acc.data[0], "base64"); // Token mints are 82 bytes; a Token-2022 mint with extensions has account type 1 at offset 165. const shape = b.length === 82 || (acc.owner === TOKEN_2022 && b.length > 165 && b[165] === 1); if (!(acc.owner === TOKEN || acc.owner === TOKEN_2022) || !shape) return once(mint, context.slot, "not a mint: owner or data layout is not a token mint"); const now: Row = { owner: acc.owner, supply: b.readBigUInt64LE(36).toString(), decimals: b[44]!, auth: option(b, 0), freeze: option(b, 46), ext: createHash("sha256").update(b.subarray(82)).digest("hex") }; const was = last(mint); save.run(mint, now.owner, now.supply, now.decimals, now.auth, now.freeze, now.ext); if (!was?.supply) return emit(mint, context.slot, `baseline: supply ${now.supply} base units, ${now.decimals} decimals, auth ${now.auth}, freeze ${now.freeze}, owner ${now.owner}`); const diff = (["owner", "supply", "decimals", "auth", "freeze"] as const).filter((f) => was[f] !== now[f]).map((f) => `${f} ${was[f]} to ${now[f]}`); if (was.ext !== now.ext) diff.push("other mint data changed (extension data)"); for (const d of diff) emit(mint, context.slot, d); }); console.log(`poll at slot ${context.slot}: ${value.length} mints, ${events} events`);}for (;;) { await poll().catch((e) => console.error("poll failed:", e instanceof Error ? e.message : e)); await new Promise((r) => setTimeout(r, pollMs));}
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v So11111111111111111111111111111111111111112
Each poll first checks that the owner is the Token or Token-2022 program and that the data has a mint's shape: 82 bytes, or for Token-2022 an account type byte of 1 at offset 165. It then decodes the standard 82-byte layout: mint authority, supply, decimals and freeze authority. The result is compared with the row saved for that mint, and one JSON line prints for a baseline, a change, a missing account or an address that is not a mint. After the mints, one line gives the slot and the number of events.
The state sits in SQLite, so a restart keeps its memory. A change that happens while the script is down shows up on the first poll after it starts. A missing or non-mint address leaves a marker in the same table, so its line prints once, when the state first appears, and later polls stay quiet. The script is read-only: it signs nothing and sends nothing.
Turning a change into an alert
The script prints one JSON line per event and leaves the routing to you.
| Event starts with | What it means | First action |
|---|---|---|
| baseline | First read of this mint, or the first read since the address became a mint. It lists supply, decimals, both authorities and the owner program. | Check the figures against what the issuer publishes and keep the line as the starting point. |
| supply | Tokens were minted when the value rises and burned when it falls. | Match it against the issuer's published issuance or redemption records. |
| auth | Control of minting moved, or was given up when the new value is none. | Page at once and read the transaction behind it. |
| freeze | Control of freezing moved. | Page at once and read the transaction behind it. |
| owner | The program that owns the mint account changed. | Page at once and read the transaction behind it. |
| decimals | Decimals are fixed when a mint is created, so a new value means a different mint now sits at the address. | Check the address and the issuer's notices before you trust the old figures. |
| other mint data changed | Extension data was edited. | Read the account and compare the extensions with the last read. |
| account missing | The address is wrong or the mint was closed. | Check the address, then the issuer's notices. |
| not a mint | The address holds an account of another kind, such as a token account or a wallet. | Check the address and swap in the mint itself. |
Supply changes are routine on a live asset. Send them to a channel people read and keep the pager for auth, freeze and owner. A one-line filter on the event text does that in whatever consumes the output.
Find the transaction behind a change
A supply change tells you that something happened. The transaction behind it tells you who did it. logsSubscribe streams transaction logs, all or by mention, so a subscription that mentions the mint sees each transaction that names it. A subscription opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent.
For a change that already printed, getSignaturesForAddress on the mint address lists its recent signatures at 50 cells a call, and getTransaction reads each one at 50 cells. Treat both as the second step: poll first, and fetch transactions only when a change line prints. For the balance of one holder, see SPL token balance.
Where it ends
- The script sees the chain only. Net asset value, reserves, custody and the legal status of the asset are off-chain. Checking supply against the issuer's records is a job you run with their data.
- It decodes the SPL mint layout. Allowlists or transfer rules that an issuer keeps in its own program accounts have other layouts. Keep the list to mints.
- Polling sees the state at each interval. A mint authority that changes and changes back between two polls leaves no trace, though minted supply would. Shorten the interval, or watch the mint with logsSubscribe, when that matters.
- Holder concentration through getTokenLargestAccounts is not available: the method is not served and answers -32601. Do not retry it. To follow named holders, read their token accounts with getTokenAccountBalance, an account read at 10 cells.
- getSignaturesForAddress pages come from Carbium's own address index, which keeps up to 30 days. Past 30 days the index returns an empty page, even for a mint that is older.
- Limits are per account, so every key on the account shares one budget. A call over its rate gets 429 with a retry-after hint, and the script logs the failure and tries again at the next poll. For alerting on that, see RPC rate-limit alerts.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Every poll logs a failure that mentions 429. | The list times 10 cells per mint costs more than your plan's account-read rate allows. Lengthen POLL_MS, shorten the list or move up a plan. The script retries at the next interval. |
| A mint prints "account missing" or "not a mint". | "account missing" means the address is mistyped or the mint was closed. "not a mint" means the address holds a token account, a wallet or another kind of account. Check the address on an explorer; the line comes back only if the address becomes a mint or switches between missing and not a mint. |
| An alert says other mint data changed and you cannot tell what. | Read the account again with getAccountInfo and compare the bytes after offset 82 with the previous read. Add a column for the raw bytes in the SQLite table if you want the diff printed. |
| Supply lines arrive all day on an active asset and get ignored. | Filter in the consumer. Page only on a supply change above a share of total supply, and send the rest to a quiet channel. Keep auth, freeze and owner on the pager. |
| Every mint prints a baseline again after a restart. | The database was in memory or the file was removed. The default monitor.db is relative to the working directory, so starting the script from another directory also makes a fresh file. Point DB at an absolute path on persistent storage so the last snapshot survives. |
| getTokenLargestAccounts returns -32601. | The method is not served. -32601 means method not found, so do not retry. Read the token accounts of the holders you care about with getTokenAccountBalance. |
Questions
Can I watch a token that is not an SPL mint?
The script reads the SPL mint layout, which covers tokens under the original token program and under Token-2022. An asset that lives in a custom program has its own account layout and needs its own decoder.
Why poll when a subscription exists?
A mint changes rarely, and a poll needs one call and no reconnect logic. A push channel fits when you need the transaction behind a change, and logsSubscribe by mention streams those.
How many mints can one call cover?
A call takes up to 300 pubkeys on Pro and 100 below it, at 10 cells each, so 100 pubkeys cost 1000 cells, or 1001 over a 4 KiB body. Check the list against the account-read rate of your plan.