services
Get a key

library / Blockchain ideas / Data products / BI0138

Trending token feed

A script that reads the newest signatures of a busy program, opens each transaction, counts the mints it touched and prints a ranked list with a rising or cooling mark. Spec, costs per plan and a runnable main.ts.

By Carbium · Data products · BI0138 · updated 2026-11-23

01

Who uses it

A wallet wants a Trending tab. A community server wants a daily list of what people are swapping. A hackathon team wants a front page for its token explorer and has an afternoon to build it. All three need a ranked list of tokens that is fresh, and all three can build it from the chain.

Trending here means activity: how many successful transactions touched a mint inside a busy program's newest window. The program is an input. Point the script at a swap program and the list shows the tokens being swapped. Point it at a launchpad program and the list shows the tokens being seeded into new pools.

The default is a large constant-product swap program, so a plain run prints something with no setup. Pass another program address as the first argument to watch a different venue.

02

How a token gets ranked

One run produces one table. The script splits its sample of transactions into a newer half and an older half, counts the mints in each, and sorts by total.

ColumnMeaning
HitsSuccessful transactions in the sample that touched the mint
NewerHits among the newest half of the sample
OlderHits among the oldest half of the sample
TrendNewer minus Older: positive is rising, negative is cooling

A transaction counts a mint once, however many token accounts it holds for that mint. A wallet can own more than one token account for one mint, and a swap that routes through several pools would otherwise count a mint several times.

Wrapped SOL and two large stablecoins appear in almost every swap, so they would head every list. The script skips them by default through one set at the top of the file. Edit the set when your venue pairs against something else.

Failed transactions are dropped before any call is spent on them. A transaction that errored changed no token balances, so it says nothing about interest in a token.

03

The build

The script is one file that needs @solana/kit and what Node 24 ships.

  1. Create one RPC client at startup against https://services.carbium.sh and reuse it for every call.
  2. Read the newest SAMPLE signatures of the program with getSignaturesForAddress at confirmed commitment.
  3. Fetch each successful transaction with getTransaction in jsonParsed encoding, one call at a time with PAUSE_MS between calls.
  4. Collect the mints from each transaction's post-transaction token balances, skip the quote-side mints, and count each mint once per transaction in its half of the sample.
  5. Print the top ten with hits, newer, older and trend, then print how many reads failed or came back empty.
$The script only reads. It signs nothing, sends nothing and holds no private key.

Run it as node main.ts [program]. The environment takes SAMPLE and PAUSE_MS. Each getTransaction call passes maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and a call without that value answers -32015 for one.

main.ts
// BI0138 · Trending token feed// https://carbium.sh/library/blockchainideas/trending-token-feed// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport } 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 },  }),);// Default: a large constant-product swap program. Pass another program address as the first argument.const PROGRAM = address(process.argv[2] ?? "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");const SAMPLE = Number(process.env.SAMPLE ?? 19); // 19 getTransaction calls at 50 cells fit the 1,024-cell burstconst PAUSE_MS = Number(process.env.PAUSE_MS ?? 600);if ([SAMPLE, PAUSE_MS].some((n) => Number.isNaN(n))) {  console.error("SAMPLE and PAUSE_MS must be numbers.");  process.exit(1);}// Pairing mints in nearly every swap would top every list: wrapped SOL, USDC, USDT.const SKIP = new Set([  "So11111111111111111111111111111111111111112",  "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",  "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",]);const why = (e: unknown) => (e instanceof Error ? e.message : String(e));const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));async function main(): Promise<void> {  const sigs = await rpc.getSignaturesForAddress(PROGRAM, { limit: SAMPLE, commitment: "confirmed" }).send();  const hits = new Map<string, { newer: number; older: number }>();  let failed = 0;  let empty = 0;  for (const [i, s] of sigs.entries()) {    if (s.err) continue; // a failed transaction changed no token balances    try {      const tx = await rpc        .getTransaction(s.signature, { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 })        .send();      if (!tx) {        empty++; // listed by the address index, no longer held by the validator      } else {        const half = i < sigs.length / 2 ? "newer" : "older";        const mints = new Set((tx.meta?.postTokenBalances ?? []).map((b) => String(b.mint)));        for (const mint of mints) {          if (SKIP.has(mint)) continue;          const row = hits.get(mint) ?? { newer: 0, older: 0 };          row[half]++;          hits.set(mint, row);        }      }    } catch (e) {      failed++;      console.error(`read failed: ${why(e)}`);    }    await sleep(PAUSE_MS);  }  const ranked = [...hits.entries()].sort((a, b) => b[1].newer + b[1].older - (a[1].newer + a[1].older));  console.log("mint                                          hits newer older trend");  for (const [mint, r] of ranked.slice(0, 10)) {    const trend = r.newer - r.older;    console.log(`${mint} ${String(r.newer + r.older).padStart(4)} ${String(r.newer).padStart(5)} ${String(r.older).padStart(5)} ${trend > 0 ? "+" : ""}${trend}`);  }  console.log(`${sigs.length} signatures, ${failed} failed reads, ${empty} empty reads`);}main().catch((e) => {  console.error(`run failed: ${why(e)}`);  process.exit(1);});

run: CARBIUM_KEY=<YOUR_KEY> node main.ts

Each transaction is read in a try, so a failed call or a null result costs one sample and the run goes on. A null can come back for a signature the address index lists but the validator no longer holds.

04

What it costs

A run makes one getSignaturesForAddress call and one getTransaction call per successful transaction. Both cost 50 cells. With the default sample of 19, the getTransaction calls come to at most 950 cells, under the 1,024 cells a rate class absorbs as a burst. One run therefore passes on every plan. The sustained rate decides how soon the next run can start.

PlangetTransaction per secondShortest pause between calls
Free ($0)0.24about 4.2 s
Dev ($20)1.2about 0.83 s
Business ($250)50.2 s
Pro ($500)250.04 s

The default PAUSE_MS of 600 spreads a run over about twelve seconds. Run it twice in a row on Free and the second run meets an empty bucket: set PAUSE_MS to 4300 before you loop it. Limits are per account, so every other tool on the same keys draws from the same budget.

Credits meter RPC work, so each run spends from the plan's credits. A page that calls the script on every view spends the plan quickly. Run it on a schedule, keep the table, and serve the stored copy to your users. Free's 500K credits come once at sign-up. On a paid plan each month adds credits, and unspent credits stay.

05

What to add next

  • Store each run in a node:sqlite file with a timestamp, so the trend compares this hour with the last one instead of two halves of one sample.
  • Count distinct signers per mint next to hits. One wallet looping swaps lifts a mint's hit count and leaves the signer count at one.
  • Add a price column from the prices method, which answers on the same endpoint. Read the prices page first.
  • Page deeper into the program's history with Signature history pagination, for a bigger sample at the cost of more calls.
  • Compare the ranking with the DEX activity leaderboard, which ranks venues where this entry ranks tokens.
  • Push instead of poll: a logsSubscribe with a mention of the program opens at 25 credits and then costs 20 credits per MiB sent. A busy program sends a great deal, so read the MiB total before you choose it.
06

Where it ends

  • The list ranks activity. It knows nothing about volume in dollars, holders or liquidity, so a mint with many tiny swaps outranks one with a few large ones.
  • One program sees one set of venues. Tokens that move only on other programs never appear.
  • Nineteen transactions on a busy program span a few seconds. The table shows what is hot at this moment. A view over the last hour needs stored runs.
  • The post-transaction token balances list every token account the transaction touched, including a mint that appeared as a side account. A mint can score without being the point of the swap.
  • The list shows mint addresses only. Names and symbols come from a metadata read per mint, which adds a call each.
  • getSignaturesForAddress reaches back 30 days at most, and its pages reach below the validator's ledger floor, so getTransaction can return null for an older signature it lists.
07

When it goes wrong

what goes wrongwhat to do
Every read fails with a 401.An unknown key is turned away at the door. Attach the whole key in CARBIUM_KEY, with no trailing newline or truncation.
Reads fail with a 429 after the first few.The calls outran the plan's getTransaction rate once the burst was spent. Raise PAUSE_MS to the shortest pause for your plan in the cost table, or lower SAMPLE.
Some reads fail with -32015.A v1 transaction answers -32015 when maxSupportedTransactionVersion is absent or 0. Keep the value at 1 in the config, and write the config object as const if you move it into a variable.
The table is empty and the summary shows many empty reads.The program address has little recent activity, or it is not a program. Check the address on an explorer, or run with the default program to confirm the key and the setup.
One mint tops every run and the trend never moves.A pairing token such as a major stablecoin sits in most swaps. Add its mint to the SKIP set, or raise SAMPLE so a single pool cannot fill the sample.
08

Questions

Can I build a trending list without a separate price or analytics API?

Yes, for an activity ranking. The script counts the mints in a program's newest transactions over Carbium RPC, so the Carbium key is the only credential. A price or market cap column needs another read per mint.

How often can I refresh the list on the Free plan?

A run's 19 getTransaction calls at 50 cells each fit inside the burst, and Free sustains 0.24 of them per second, so a second run straight after needs a pause of about 4.2 seconds per call. Refresh on a schedule and serve the stored result.

Why does the script open transactions instead of reading a token list?

A token list tells you what exists. The transaction tells you what people touched just now, and its token balances name the mints. That is the signal a trending view needs.

Can I change what counts as trending?

Yes. Swap the program for a launchpad to rank new tokens, change the skip set, or replace the hit count with distinct signers. The scoring is one small loop in main.ts.