services
Get a key

library / Blockchain ideas / BI0004

NFT collection transfer feed

One logsSubscribe on a Metaplex Core collection address returns every transfer of every asset in it, so 10,000 NFTs need one subscription. You get the build, the credits and the limits, with a runnable main.ts.

By Carbium · Creator and membership · BI0004 · updated 2026-11-22

01

Who uses it

A membership project needs to know who holds a pass right now. Watching one address per NFT turns a 10,000-pass collection into 10,000 open subscriptions, or 10,000 reads on every refresh. One subscription on the collection brings the roster up to date at the moment a transfer lands.

Holder rewards can skip a wallet that sold its pass an hour ago. A community server can drop a channel role when the pass moves. A hackathon team can demo the feed on any busy collection, since every transfer is public.

02

Why one subscription is enough

The N+1 problem shows up when every NFT has its own address to watch: one call lists the collection, then each item gets a subscription of its own. Metaplex Core takes away the per-item part. Moving an asset that sits in a collection puts the collection account into the transaction's account list, and the mentions filter of a logs subscription matches any account a transaction lists.

One logsSubscribe with the collection address in mentions therefore sees every transfer of every asset in it, sales routed through a marketplace program included, as long as the call reaches Core. The owner is a field inside the asset account, so no token account per holder has to be found first.

$This holds for Core collections. NFTs minted with Token Metadata move through the SPL Token program and their transfers list no collection address, so those collections keep the N+1 problem.
03

The build

The feed is a single file on @solana/kit and the Node 24 standard library. It only reads: no private key, nothing signed or sent.

OutputWhere it comes from
Recent signatures at startgetSignaturesForAddress on the collection, served from the 30-day address index
TRANSFER linea logsNotification with err null and an Instruction: Transfer log line written under the Core program
Assetfirst account of the Core transfer instruction in getTransaction
New ownerfifth account of that same instruction
Minute linethe feed's own counts: seen, transfers, dropped, MiB received
  1. Read the collection address from the first argument and build one RPC client for the whole run.
  2. Fetch the five newest signatures that mention the collection, at commitment confirmed, so there is something on screen before the first live event.
  3. Open one WebSocket to wss://services.carbium.sh, passing the key as ?api-key=.
  4. Send logsSubscribe with { mentions: [collection] } at confirmed. The first reply holds the subscription id, or an error when the subscription is refused, and a refusal is free.
  5. For each logsNotification, drop failed transactions and look for an Instruction: Transfer log line written under the Core program. Transfer lines from SPL Token legs in the same transaction are ignored. A hit is printed and queued.
  6. Every 5 seconds, pop one signature and call getTransaction over https://services.carbium.sh. Search its instructions, top level and inner, for Core calls whose first data byte is 14, and take the asset and the new owner from their accounts.
  7. Once a minute, print notifications seen, transfers, dropped, MiB received and the subscription credits those bytes come to.
main.ts
// BI0004 · NFT collection transfer feed// https://carbium.sh/library/blockchainideas/nft-collection-transfer-feed// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getBase58Encoder, isSolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, type Signature } from "@solana/kit";const key = process.env.CARBIUM_KEY;const collection = process.argv[2] ?? process.env.COLLECTION;if (!key || !collection) {  console.error("Usage: CARBIUM_KEY=<your key> node main.ts <collection address>");  process.exit(1);}const CORE = "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d"; // Metaplex Core programconst WS_URL = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}/?api-key=${key}`;const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);type Ix = { programIdIndex: number; accounts: number[]; data: string };type Tx = {  transaction: { message: { accountKeys: string[]; instructions: Ix[] } };  meta: { innerInstructions?: { instructions: Ix[] }[]; loadedAddresses?: { writable: string[]; readonly: string[] } } | null;};const GAP_MS = 5000; // one getTransaction per 5 s stays under Free's 0.24 req/sconst owners = new Map<string, string>(); // asset -> current ownerconst queue: string[] = [];let seen = 0, transfers = 0, dropped = 0, bytes = 0, pausedUntil = 0;function isCoreTransfer(logs: string[]): boolean {  let program = ""; // program of the latest invoke line, so SPL Token legs do not match  return logs.some((l) => {    if (l.includes(" invoke [")) program = l.split(" ")[1];    return program === CORE && l.includes("Instruction: Transfer");  });}rpc.getSignaturesForAddress(address(collection), { limit: 5, commitment: "confirmed" }).send()  .then((recent) => recent.forEach((s) => console.log(`recent ${s.signature} ${s.err === null ? "ok" : "failed"}`)))  .catch((e) => console.error("recent signatures failed:", e instanceof Error ? e.message : e));function connect(): void {  const ws = new WebSocket(WS_URL);  ws.onopen = () => ws.send(JSON.stringify({    jsonrpc: "2.0", id: 1, method: "logsSubscribe",    params: [{ mentions: [collection] }, { commitment: "confirmed" }],  }));  ws.onmessage = (ev) => {    const text = String(ev.data);    bytes += Buffer.byteLength(text);    const msg = JSON.parse(text);    if (msg.id === 1) {      console.log(msg.error ? `subscribe refused: ${msg.error.message}` : `subscribed, id ${msg.result}`);      return;    }    if (msg.method !== "logsNotification") return;    seen++;    const { signature, err, logs } = msg.params.result.value as { signature: string; err: unknown; logs: string[] };    if (err !== null || !isCoreTransfer(logs)) return;    transfers++; console.log(`TRANSFER ${signature}`);    if (queue.length < 200) queue.push(signature); else dropped++;  };  ws.onclose = () => setTimeout(connect, 2000);  ws.onerror = () => ws.close();}setInterval(async () => {  const sig = Date.now() < pausedUntil ? undefined : queue.shift();  if (!sig) return;  try {    const tx = (await rpc      .getTransaction(sig as Signature, { commitment: "confirmed", encoding: "json", maxSupportedTransactionVersion: 1 })      .send()) as unknown as Tx | null;    if (!tx) {      console.log(`  ${sig} not visible yet, skipped`);      return;    }    const keys = [...tx.transaction.message.accountKeys, ...(tx.meta?.loadedAddresses?.writable ?? []), ...(tx.meta?.loadedAddresses?.readonly ?? [])];    const ixs = [...tx.transaction.message.instructions, ...(tx.meta?.innerInstructions ?? []).flatMap((i) => i.instructions)];    for (const ix of ixs) {      const a = ix.accounts.map((i) => keys[i]);      if (keys[ix.programIdIndex] !== CORE || getBase58Encoder().encode(ix.data)[0] !== 14) continue; // 14 = Core TransferV1      owners.set(a[0], a[4]);      console.log(`  asset ${a[0]} now held by ${a[4]} (${owners.size} tracked)`);    }  } catch (e) {    if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && e.context.statusCode === 429) {      queue.unshift(sig);      pausedUntil = Date.now() + Number(e.context.headers.get("retry-after") ?? 5) * 1000;    } else console.error("getTransaction failed:", e instanceof Error ? e.message : e);  }}, GAP_MS);setInterval(() => {  const mib = bytes / 2 ** 20;  console.log(`--- seen ${seen}, transfers ${transfers}, dropped ${dropped}, received ${mib.toFixed(2)} MiB, about ${(25 + 20 * mib).toFixed(0)} subscription credits`);}, 60_000);connect();

run: CARBIUM_KEY=<YOUR_KEY> node main.ts <COLLECTION_ADDRESS>

Core's transfer instruction puts the asset in the first slot and the new owner in the fifth, and the code reads both from top-level and inner instructions. It accepts an instruction only when its first data byte is 14, the Core transfer discriminator, so an update or plugin call can never write an owner into the roster. The getTransaction read passes maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and at 0 the call answers -32015, so the catch branch would drop the signature and the roster would miss that owner change.

The queue takes 200 signatures. Once it is full, each new transfer is dropped and counted, which means the roster can miss an owner change; the minute line reports the count. When the socket closes, the close handler waits 2 seconds, reconnects and subscribes again.

04

What it costs

Billing for the socket is in credits: a logs-mentions subscription costs 25 credits to open and 20 credits per MiB sent after that. Any notification that mentions the collection counts, whether or not an asset moved. The table assumes 2 KiB per notification; the feed prints the true MiB total.

Notifications per hourMiB per hourSubscription credits per hour
5000.98about 20
5,0009.77about 195
50,00097.7about 1,950

Even the busiest row stays below 2,000 credits an hour. The Free grant of 500K credits is paid once, so it drains: at 195 credits an hour it lasts about 2,560 hours, and at 1,950 about 256. Those hours cover the socket only. The limit that bites first is getTransaction, at 50 cells a call and the rate of your plan.

PlanCreditsgetTransaction rateReads per minute at that rate
Free ($0)500K once, at sign-up0.24 req/s14
Dev ($20)10M per month1.2 req/s72
Business ($250)50M per month5 req/s300
Pro ($500)200M per month25 req/s1,500

On Free, one call every 5 seconds is 0.2 req/s, under the 0.24 limit, which gives 12 transfer reads a minute. Limits belong to the account, so other tools using your keys share this budget. Free allows 5 sockets and the feed holds one.

05

What to add next

  • Seed the roster: getMultipleAccounts accepts up to 100 pubkeys per call below Pro (300 on Pro) at 10 cells each, so 10,000 assets from your mint script's list take 100 calls. The owner sits after the one-byte key at the start of the account data.
  • Store the roster in node:sqlite so it survives a restart.
  • Backfill on restart: page getSignaturesForAddress newest first until you hit the last signature you stored. It reaches back 30 days at most.
  • Send every owner change to a webhook or a chat channel with the asset and both owners.
  • A second collection needs a second subscription at 25 credits; de-duplicate by signature.
06

Where it ends

  • Token Metadata NFTs keep the N+1 problem, because their transfers list no collection address. The options are one logsSubscribe per mint, each opening at 25 credits and counting against the subscription cap of your tier, or a sweep of your holders' token accounts with getMultipleAccounts.
  • A subscription on a mint sees only transactions that list the mint. A plain SPL Token Transfer lists the two token accounts and the signer, so it never appears. Checked transfers and Token Metadata instructions do.
  • The usual way to find a mint's holder account, getTokenLargestAccounts, answers -32601 here and is not worth retrying. Take holder accounts from your own snapshot.
  • logsSubscribe accepts one mention per subscription. A feed over two collections opens two subscriptions and de-duplicates by signature, since one transaction can mention both.
  • The feed reports changes and has no idea of the starting state, so seed owners first. A backfill reaches back 30 days at most, and an empty page beyond that is the index's age limit.
  • Failed transactions are skipped, and a transaction rejected in preflight leaves no log at all.
  • The feed carries addresses only. Names, images and traits live elsewhere.
07

When it goes wrong

what goes wrongwhat to do
Nothing prints after subscribed.The collection is quiet, or the address is not a Core collection. The minute line shows seen growing once mentions arrive. To watch the stream move, pass the Core program address as the argument: every Core call on the network mentions it.
The subscribe reply is an error, or the socket closes at once.Check CARBIUM_KEY and that the account is under its socket cap (Free allows 5). A refused subscription is free, so retrying it costs nothing.
getTransaction returns null for a signature the stream announced.The read asks for confirmed, the same level the stream used. If it is still null, the code prints the full signature and moves on; read it by hand later.
getTransaction answers 429.Widen the gap to your plan's rate (0.24 req/s on Free) and check what else on the account is calling, because the limit is shared across its keys.
The roster misses transfers made while the feed was down.On reconnect or restart, read getSignaturesForAddress for the collection and queue every signature newer than the last one you stored. It reaches back 30 days at most.
08

Questions

Does one subscription really cover every NFT in the collection?

For Core collections, yes: transfers list the collection account, and mentions matches it. For Token Metadata collections no address is shared by all transfers, so it does not.

Can accountSubscribe on the collection account do the same job?

No. A transfer lists the collection account without changing it, so an account subscription on it stays quiet. logsSubscribe matches listed accounts, which is why the feed uses it.

How do I get the starting owners?

Read the asset accounts with getMultipleAccounts, up to 100 pubkeys per call below Pro, from the list your mint script wrote. The owner follows the one-byte key at the start of the account data.

Will it run on the Free plan?

Yes. The feed holds one of Free's 5 sockets and its socket credits come out of the 500K grant. The loop keeps getTransaction under 0.24 req/s and reads 12 transfers a minute, queues up to 200 more and counts anything beyond as dropped.