library / Use cases / Analytics and research / UC0121
New token creation rate
A confirmed-level log feed filtered for mint initializations tells you about each new token as it appears and gives you a per-minute creation rate. The sample resolves the mint address from the transaction and prints it with its slot.
What counts as a new token
A token on Solana is a mint account. It comes into being in one transaction: the System Program allocates the account, then the Token program (or Token-2022) runs an initialize instruction on it. That initialize instruction is the event to watch. Everything that follows, metadata, a first liquidity pool, a first holder, arrives in later transactions and may never arrive at all.
Two instruction names matter, InitializeMint and InitializeMint2. The second one takes no rent sysvar account and is what most current code calls, so a detector that matches only the first misses most creations. Match both. The Token program and Token-2022 are separate programs with separate addresses, so a complete count watches each of them.
A creation rate is then the number of distinct transactions containing one of those instructions per unit of time. A transaction that creates three mints counts once in the sample below. If your report needs a count of mints, count the parsed instructions instead.
The log feed
logsSubscribe on the WebSocket endpoint streams transaction logs, all or by mention. The sample opens one subscription per Token program address, each with a mention filter at confirmed commitment. Any transaction that invokes the program, directly or through a call from another program, mentions its address, and the Token program writes an Instruction: InitializeMint or Instruction: InitializeMint2 line to the logs when it runs. Matching either line is the whole filter.
Failed transactions arrive on the feed too, with err set. A failed initialize created no mint, so the code drops them. A transaction that mentions both programs arrives twice, once per subscription, so results are keyed by signature.
The socket takes the key as ?api-key= in the URL. The code sets it on a URL object, so the key lives in the environment and never in the source.
// UC0121 · New token creation rate// https://carbium.sh/library/usecase/new-token-creation-rate// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { 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 rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const wsUrl = new URL(process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh");wsUrl.searchParams.set("api-key", key);const PROGRAMS = [ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",];const windowSec = Number(process.argv[2] ?? 20);type Ix = { parsed?: { type?: string; info?: { mint?: string } } };type Tx = { transaction: { message: { instructions: Ix[] } }; meta?: { innerInstructions?: { instructions: Ix[] }[] } | null;};async function mintOf(sig: string): Promise<string> { for (let attempt = 0; attempt < 2; attempt++) { const tx = (await rpc .getTransaction(signature(sig), { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1, }) .send()) as unknown as Tx | null; if (tx) { const inner = (tx.meta?.innerInstructions ?? []).flatMap((i) => i.instructions); const hit = [...tx.transaction.message.instructions, ...inner].find((i) => i.parsed?.type?.startsWith("initializeMint"), ); if (hit?.parsed?.info?.mint) return hit.parsed.info.mint; throw new Error("no parsed initializeMint instruction"); } await new Promise((r) => setTimeout(r, 1500)); } throw new Error("getTransaction answered null");}const created = new Map<string, number>();let seen = 0;const ws = new WebSocket(wsUrl);ws.onerror = () => { console.error("WebSocket error: check CARBIUM_KEY and the plan's socket cap"); process.exit(1);};ws.onopen = () => PROGRAMS.forEach((p, i) => ws.send(JSON.stringify({ jsonrpc: "2.0", id: i + 1, method: "logsSubscribe", params: [{ mentions: [p] }, { commitment: "confirmed" }] })), );ws.onmessage = (ev) => { const msg = JSON.parse(String(ev.data)); if (msg.error) console.error("subscribe failed:", JSON.stringify(msg.error)); if (msg.method !== "logsNotification") return; seen++; const { value, context } = msg.params.result; if (value.err) return; if (value.logs.some((l: string) => /Instruction: InitializeMint2?$/.test(l))) { created.set(value.signature, context.slot); }};await new Promise((r) => setTimeout(r, windowSec * 1000));ws.close();const perMinute = ((created.size / windowSec) * 60).toFixed(1);console.log(`${created.size} mint creations in ${windowSec}s from ${seen} token transactions, about ${perMinute} a minute`);const sample = [...created].slice(0, 3);const results = await Promise.allSettled(sample.map(([sig]) => mintOf(sig)));results.forEach((r, i) => { const [sig, slot] = sample[i]!; console.log(slot, sig, r.status === "fulfilled" ? r.value : `lookup failed: ${r.reason}`);});process.exit(0);
run: node main.ts 20
Reading the mint address
A log line names no accounts, so the code fetches the transaction with getTransaction in jsonParsed encoding and looks for a parsed instruction whose type starts with initializeMint. Its info.mint field is the address. Launch programs call the Token program from inside their own instruction, so the match is usually among the inner instructions, and the code searches both lists.
The call passes maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and a lower value answers -32015 for them. It also names confirmed commitment itself instead of relying on a default. A signature seen on the feed can still be missing from the node for a moment, so the lookup retries once after 1.5 seconds before it gives up.
getTransaction costs 50 cells a call, where cheap cached reads cost 1, and Free runs it at 0.24 calls a second. Resolve a sample, or resolve one mint when a person asks for it, and never every creation. The count needs no lookups at all.
Turning events into a rate
The rate comes from the feed alone: distinct signatures divided by the window in seconds, times 60. The sample runs 20 seconds unless you pass a different number of seconds as its first argument. For a dashboard, keep one counter per minute and hold the signature set only as long as the dedupe needs it, a few minutes at most.
| Output | Source | Cost |
|---|---|---|
| Creation count | Matching log lines on the feed | WebSocket credits only |
| Mint address | getTransaction in jsonParsed encoding | 50 cells a call |
| Slot | context.slot on each notification | None |
Creation arrives in bursts, so a 20 second sample can differ a lot from the next one. Use a 5 to 15 minute average for any number you publish and show the window next to it.
What the feed costs
A logs subscription with a mention filter sits in the middle weight, so each one costs 25 credits to open, then 20 credits per MiB sent. A refused subscription costs nothing. A mention of the Token program matches every transaction that touches a token, which is a large share of chain traffic, so the MiB meter is the line to watch. The sample carries both subscriptions on one socket, inside the 5 sockets a Free account carries.
On Dev, Business and Pro the gRPC stream at services.carbium.sh:9443 is a server-filtered alternative that sends only the transactions you select. Free has no gRPC. Move there when the WebSocket meter becomes your largest line. Chain data streaming covers that path.
Where it ends
- Solana truncates the log output of a transaction that logs a lot. A creation whose line was cut is missed, so the count is a lower bound.
- A creation is only the first step. It says nothing about supply, liquidity or holders, and a mint with zero supply still counts. Read token mint supply and authorities before you treat an address as a live token.
- A dropped socket loses the events in the gap and the sample does not backfill them. Mark that window as incomplete instead of reporting a low rate.
- The sample watches the Token program and Token-2022 only. A program that defines its own token format is outside the count.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The socket errors out or the subscribe call answers an error and no notifications arrive. | The door answers an unknown key with 401, so attach the whole key. Read the error object the code prints, then close idle sockets if the plan's socket cap is reached. |
| The notification counter climbs but the creation count stays at zero. | Widen the window first, since creation is bursty. If it still reads zero, print a few matching log lines and check the match against the exact Instruction: text. |
| getTransaction answers null for a signature that just arrived on the feed. | Retry once after a short wait, as the sample does. If it is still null, keep the signature and resolve it later. |
| getTransaction answers -32015. | Pass maxSupportedTransactionVersion: 1 with the encoding. A value of 0 or none fails for v1 transactions. |
| Mint lookups start returning 429 when you resolve many creations. | Resolve fewer, or queue lookups at the plan's rate. The rate figure does not depend on them. |
| The initialize instruction comes back unparsed, as raw program data. | Log the signature and read the first account of that instruction by hand. In both initialize variants it is the mint. |
Questions
Does this catch Token-2022 mints?
Yes. The second subscription mentions the Token-2022 program and its log line matches the same text.
Can I get the creator and the token name?
The fee payer is the first account key in the transaction and is often the creator. The name and symbol sit in a metadata account that may be written in the same transaction or in a later one, so read it after a short delay.
Why not poll getSignaturesForAddress on the Token program?
Each page costs 50 cells and lists every transaction on the program, so you pay for the lookups and still filter the transfers out yourself.
How do I keep this running as a service?
Wrap the socket in a reconnect loop and flush a counter every minute. WebSocket keepalive and reconnect covers the loop.
Are failed transactions counted?
No. The code skips any notification with err set, because a failed initialize created no mint.