Token prices and metrics
Both halves of a token price chart: one batched read of the mint account (supply, decimals and authorities), the prices method for the price points, a Node sampler that stores both in SQLite, and the rate on each plan.
Mint state and price samples
Price points exist only if a sampler stored them, because a price changes with every swap on every pool and a chart of it needs the points kept. The metrics (supply, decimals, mint authority, freeze authority) sit in one account on chain, the mint, and change only when someone mints, burns or revokes an authority.
A sampler reads the mint state and the price on each tick and writes a row per mint into each of two tables. The chart joins the two on mint and time. The mint half is one batched read; the price half is the prices method.
The two feeds draw on different plans. The mint reads draw on the RPC plan, where Free is $0 and starts with 500K credits once, at sign-up, and the reads below fit its request rate for a short watchlist. The prices calls draw on the quote plane's own plan, where Free is $0 at 10 requests a second and spends no credits, so the whole chart can run at $0.
Read many mints in one call
A mint is an account owned by a token program. Read with jsonParsed encoding, the node decodes it for you: supply as a string of base units, decimals, and mintAuthority and freezeAuthority, each an address or null once revoked. Token-2022 mints answer with the same four fields.
getMultipleAccounts takes up to 300 pubkeys, but the 1,024-cell burst caps a call at 100 below Pro. It is an account read, priced at 10 cells per pubkey, so a 100-mint call costs 1000 cells, or 1001 once the body passes 4 KiB.
The account-read rate of each plan sets how many mints you can sample. The last column is that rate times 60, a sustained average, with each mint priced as one account read.
| Plan | Per month | Account reads req/s | Mints per minute |
|---|---|---|---|
| Free | $0 | 0.5 | 30 |
| Dev | $20 | 15 | 900 |
| Business | $250 | 50 | 3000 |
| Pro | $500 | 400 | 24000 |
Limits are per account, so every key on the account draws on the same rate. The door absorbs a burst of up to 1,024 cells or one second of the rate, whichever is larger. A single call larger than the burst is refused even when the average is under the rate.
A sizing example: a 50-mint watchlist read once a minute is one 500-cell call per minute, an average of about 8.3 cells a second. That is above Free's 5 cells a second (0.5 req/s at 10 cells) and far under Dev's 150 (15 req/s at 10 cells). The 500-cell call fits Free's 1,024-cell burst, and only the interval brings the average down, so on Free set INTERVAL_S to 100 or more for 50 mints.
A sampler in one file
Install the one dependency with npm i @solana/[email protected]. The script reads CARBIUM_KEY and exits with a message when it is unset. The mint reads go through the kit client. prices goes through a plain fetch POST to the same URL, with the same x-api-key request header, because kit has no method for it. CARBIUM_RPC_URL overrides the URL for both. MINTS is a comma-separated list, SAMPLES and INTERVAL_S default to 3 and 10, and CHUNK sets the mints per call (default and ceiling 64, below the 100-pubkey cap of a mint read), with the calls spaced across the interval. SAMPLES_DB names a file when you want the rows to outlive the process. Without it SQLite runs in memory.
// UC0008 · Token prices and metrics// https://carbium.sh/library/usecase/token-prices-and-metrics// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: samples SPL mint supply, decimals and authorities plus the prices method's price into SQLite, in chunked calls.import { DatabaseSync } from "node:sqlite";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, isAddress } 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";const listed = (process.env.MINTS ?? "").split(",").filter(Boolean).slice(0, 300);// A malformed string would make address() throw and stop the run, so it is reported and dropped here.const mints = listed.filter((m) => isAddress(m) || (console.log(`${m.slice(0, 8)} is not a valid address, skipped`), false));if (!mints.length) { console.error("Set MINTS to a comma-separated list of mint addresses."); process.exit(1); }const samples = Number(process.env.SAMPLES ?? 3), everyMs = Number(process.env.INTERVAL_S ?? 10) * 1000;// This script's own ceiling of 64 mints per call, under the 100-pubkey cap of a mint read. A smaller CHUNK spreads the calls across the interval.const size = Math.min(64, Math.max(1, Number(process.env.CHUNK) || 64));const chunks = Array.from({ length: Math.ceil(mints.length / size) }, (_, i) => mints.slice(i * size, (i + 1) * size));type Mint = { parsed?: { type: string; info: { decimals: number; supply: string; mintAuthority: string | null; freezeAuthority: string | null } } };type Http = { context?: { statusCode?: number; headers?: unknown } };type Row = [string, number | null, number, string];const headers = { "x-api-key": key };const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers }));const db = new DatabaseSync(process.env.SAMPLES_DB ?? ":memory:");db.exec("CREATE TABLE IF NOT EXISTS mint_samples (mint TEXT, ts INTEGER, slot INTEGER, supply TEXT, decimals INTEGER, mint_authority TEXT, freeze_authority TEXT)");db.exec("CREATE TABLE IF NOT EXISTS price_samples (mint TEXT, ts INTEGER, price REAL)");const insert = db.prepare("INSERT INTO mint_samples VALUES (?, ?, ?, ?, ?, ?, ?)");const insertPx = db.prepare("INSERT INTO price_samples VALUES (?, ?, ?)");const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));// Base units stay a string; the decimal point goes in by slicing, never by float division.const whole = (s: string, d: number) => { const p = s.padStart(d + 1, "0"); return d ? `${p.slice(0, -d)}.${p.slice(-d)}` : p; };const tag = (a: string | null) => (a ? a.slice(0, 8) : "revoked");const why = (e: unknown) => (e instanceof Error ? e.message : `HTTP ${(e as Http).context?.statusCode}`);// One retry on a 429, after retry-after read as seconds (1 s when absent).async function retry<T>(call: () => Promise<T>): Promise<T> { for (let attempt = 0; ; attempt++) { try { return await call(); } catch (e) { const c = (e as Http).context; if (c?.statusCode !== 429 || attempt === 1) throw e; const wait = c.headers instanceof Headers ? Number(c.headers.get("retry-after")) : NaN; await sleep((wait || 1) * 1000); } }}// Calls the quote plane's prices method for a chunk of mints and returns its rows.async function priced(batch: string[]): Promise<Row[]> { const body = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "prices", params: { mints: batch } }); const res = await fetch(url, { method: "POST", headers: { ...headers, "content-type": "application/json" }, body }); if (res.status === 429) throw { context: { statusCode: 429, headers: res.headers } }; const j = (await res.json()) as { result?: { rows?: Row[] }; error?: { message?: string } }; if (!j.result) throw new Error(j.error?.message ?? `prices answered ${res.status}`); return j.result.rows ?? [];}async function sample(batch: string[]) { const { context, value } = await retry(() => rpc.getMultipleAccounts(batch.map((m) => address(m)), { commitment: "finalized", encoding: "jsonParsed" }).send()); const px = new Map<string, number | null>(); try { for (const [m, p] of await retry(() => priced(batch))) px.set(m, p); } catch (e) { console.log("prices failed:", why(e)); } const now = Date.now(); value.forEach((acc, n) => { const mint = batch[n]!; const m = (acc?.data as unknown as Mint | undefined)?.parsed; if (m?.type !== "mint") return console.log(`${mint.slice(0, 8)} is missing or not a mint`); const { supply, decimals, mintAuthority, freezeAuthority } = m.info; const p = px.get(mint); if (typeof p === "number") insertPx.run(mint, now, p); insert.run(mint, now, Number(context.slot), supply, decimals, mintAuthority, freezeAuthority); console.log(`${mint.slice(0, 8)} slot ${context.slot} supply ${whole(supply, decimals)} mint authority ${tag(mintAuthority)} freeze authority ${tag(freezeAuthority)} price ${p ?? "none"}`); });}for (let i = 0; i < samples; i++) { for (const [k, batch] of chunks.entries()) { if (i || k) await sleep(everyMs / chunks.length); try { await sample(batch); } catch (e) { console.log(`mint read failed for ${batch.length} mints:`, why(e)); } }}console.table(db.prepare("SELECT m.mint, COUNT(*) AS rows_kept, MAX(m.slot) - MIN(m.slot) AS slot_span, (SELECT COUNT(*) FROM price_samples p WHERE p.mint = m.mint) AS prices_kept FROM mint_samples m GROUP BY m.mint").all());
run: CARBIUM_KEY=$CARBIUM_KEY MINTS=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,So11111111111111111111111111111111111111112 node main.ts
The mint read uses finalized. Supply stays a string of base units in the table, and the decimal point goes in by slicing that string, which keeps large supplies exact. The reply carries the slot it was served at. The script stores it next to the wall-clock time, so every row says which slot it describes.
Each call is retried once after a 429. A second 429 on the mint read skips that chunk, and a second 429 on prices still stores the chunk's mint rows.
A run prints one line per mint per sample with its price, then a table with the rows kept and the slot span for each mint. A null authority prints as revoked. An address that is malformed, missing or not a mint prints a line saying so, and a malformed one is dropped before the call, so it cannot stop the run. A failed mint read prints a line and the run goes on to the next chunk. A failed prices call prints a line and the mint rows are still stored.
Where the price joins
The quote plane answers on the same endpoint as the RPC, as JSON-RPC, with four methods: quote, swap, health and prices. The script calls prices for each chunk of mints and takes the price from the row of each mint that comes back. A key without the QUOTE scope is refused, so give the key that scope.
The script writes each non-null price into a second table, price_samples(mint, ts, price), on the tick that read the mint, and skips a mint with no row or a null price. Build the chart from the two tables:
- Candle: for each bucket, a minute or any width you chart, take the first, highest, lowest and last price.
- Supply: the latest mint_samples row at or before the end of the bucket. Supply moves only when a mint or burn instruction runs, so carrying the last row forward is correct between samples.
- Value at total supply: the price times total supply in whole tokens.
Where it ends
- Top holders and holder counts are out. getTokenLargestAccounts is one of eight methods that are not served. It answers -32601, and a -32601 is final, so do not retry it.
- The mint holds total supply. It subtracts burned tokens and counts locked and treasury tokens, so a circulating figure, or a market cap built on one, needs data the mint does not have.
- Name, symbol and logo live in metadata accounts or a Token-2022 extension. The script reads none of them.
- The script holds no past, so a chart starts at the first sample you store. Rebuilding supply changes from a mint's transactions with getSignaturesForAddress reaches back 30 days at most, because the pages come from the address index, and an empty page past that is the index's age limit.
- Free's account-read rate is 0.5 req/s, which is 30 mints a minute. A longer watchlist needs a longer interval or a bigger plan.
- SQLite lets several writers take turns, so one sampler process per file avoids lock waits. With several samplers, collect the samples in one place.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| A mint prints as not a valid address, missing or not a mint. | A malformed string is dropped before the call and prints a line. Otherwise the address is mistyped, the account is closed, or it is not a mint (a token account or wallet). Check the address on mainnet and keep the skip, so one bad entry does not stop the batch. |
| Supply looks a million times too large or too small. | Supply is in base units. Divide by 10 to the power of decimals as the script does, on the string, and never convert through a float. |
| 429s appear on the Free plan with a long watchlist. | Each pubkey costs 10 cells and Free's account-read rate is 0.5 req/s. Lengthen the interval until the average is at or under 5 cells a second, or move to a plan with a higher rate. Honour the retry-after value before the retry. |
| The prices call prints api key is not enabled for quote. | The key lacks the QUOTE scope and the call answers 401 with -32001. Give the key the QUOTE scope and send the whole key. The mint rows are still stored while it fails. |
| A call to getTokenLargestAccounts returns -32601 and is retried in a loop. | Treat -32601 as final. The method is not served, so drop it and show holder data from your own index if the page needs it. |
| The chart has a hole after the sampler restarted. | SAMPLES_DB must name a file for any rows to survive a restart, because the in-memory default loses every row and leaves no gap to bridge. With a file, each row carries its time and slot, so carry the last supply row forward across the gap. Price rows for the gap are absent, so draw a break or leave the candle empty. |
Questions
Is there a free API for Solana price chart data and mint metrics?
The Free plan is $0 with 500K credits once at sign-up, and it covers the mint half: supply, decimals and authorities through getMultipleAccounts. The price half comes from the prices method on the same endpoint, which runs on the quote plane's own Free plan at $0 and 10 requests a second and spends no credits. A chart needs stored points, so you sample on a schedule and keep the rows yourself.
How many mints can one call read?
Up to 300 pubkeys on Pro and 100 below it, because of the 1,024-cell burst. Each costs 10 cells, and a body over 4 KiB adds 1. Size the list against the account-read rate of your plan.
How do I turn the samples into a market-cap line?
For each time bucket, take the last price_samples price, join the latest mint_samples row at or before it, divide supply by 10 to the power of decimals, and multiply by the price. That gives value at total supply, because the mint holds no circulating figure.
Do I need a WebSocket to track supply changes?
Supply moves only when a mint or burn instruction runs, so a poll about once a minute fits most pages. A subscription opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent, which a short watchlist does not need.