services
Get a key

library / Use cases / Loyalty, rewards and memberships / UC0135

Holding period eligibility

Decide which wallets held an SPL token through a recent window. You get a Node script that reads each wallet's balance, finds the newest move on its token accounts, and reports held or moved, with the limits of a 30-day index.

By Carbium · Loyalty, rewards and memberships · UC0135 · updated 2026-11-23

01

What a holding period needs

A holding period is a claim about time, and RPC answers about the present. A token account's current balance is one read, and its newest signature shows when it last moved. Together they test a narrower claim: this wallet has a positive balance now, and nothing has touched its token account for the last N days. If no transfer moved the account in that window, the balance was the same at every point in it, so the current balance is the balance throughout.

The first read, getTokenAccountsByOwner, returns the token accounts a wallet holds for the mint. Each account then gets one signature read for its newest movement. The two calls that show up in the cost table are the signature read and the transaction read used for wallet discovery.

CallUsed forCells per callFree req/sDev req/sBusiness req/sPro req/s
getSignaturesForAddressNewest movement on a token account500.241.2100500
getTransactionFee payer of a recent mint transaction500.241.2525

Both calls cost 50 cells, so a list costs one signature read per token account, plus the transaction reads when the script finds wallets itself. Check the per-method rates for your plan before you size a run.

02

The eligibility test

A wallet is eligible when all three tests pass across its token accounts for the mint.

  • Balance: the token amounts read from its token accounts, summed, are above zero. Amounts are raw base units.
  • Quiet: each token account's newest signature is older than the window, or the account has no signature in the 30-day index.
  • Known: no newest signature lacks a block time. A missing block time makes the wallet ineligible.

A wallet can own more than one token account for one mint, so the script sums them and checks each one. A wallet that sent part of its balance out and got it back is marked moved, which is the conservative answer. The index also holds failed transactions, and the script does not read the err field, so a failed attempt on the account counts as movement too.

03

The check in one file

The script takes the mint as its first argument and the window from HOLD_DAYS, capped at 30. An optional second argument is a comma-separated wallet list. Without it, the script finds wallets from the mint's newest transactions. A wallet that fails is printed and skipped, so one bad read does not end the run.

main.ts
// UC0135 · Holding period eligibility// https://carbium.sh/library/usecase/holding-period-eligibility// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: which wallets held an SPL token unchanged for HOLD_DAYS.// A positive balance now and no movement on the token account in that window means the wallet held through it.import { 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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const mint = process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";const walletArg = process.argv[3];const holdDays = Math.min(30, Number(process.env.HOLD_DAYS ?? 7));const cutoff = Date.now() / 1000 - holdDays * 86_400;const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));type Parsed = { parsed: { info: { tokenAmount: { amount: string } } } };type Loose = { transaction: { message: { accountKeys: unknown[] } } } | null;// No wallet list: the fee payers of the mint's newest transactions, read at version 1 so v1 transactions are not refused.async function recentWallets(limit: number): Promise<string[]> {  const sigs = await rpc.getSignaturesForAddress(address(mint), { limit }).send();  const out: string[] = [];  for (const s of sigs) {    try {      const tx = (await rpc.getTransaction(s.signature, { maxSupportedTransactionVersion: 1, encoding: "json" }).send()) as unknown as Loose;      const first = tx?.transaction.message.accountKeys[0];      const pk = typeof first === "string" ? first : (first as { pubkey?: string } | undefined)?.pubkey;      if (pk) out.push(pk);    } catch (e) { console.error(`getTransaction failed: ${(e as Error).message}`); }  }  return Array.from(new Set(out));}async function check(owner: string): Promise<void> {  const { value } = await rpc.getTokenAccountsByOwner(address(owner), { mint: address(mint) }, { encoding: "jsonParsed" }).send();  let raw = 0, newest = 0, unknown = false;  for (const a of value) {    raw += Number((a.account.data as unknown as Parsed).parsed.info.tokenAmount.amount);    const [s] = await rpc.getSignaturesForAddress(a.pubkey, { limit: 1 }).send();    if (!s) continue;    if (s.blockTime == null) unknown = true;    else newest = Math.max(newest, Number(s.blockTime));  }  const held = raw > 0 && !unknown && newest <= cutoff;  const when = newest ? new Date(newest * 1000).toISOString() : "none in the 30-day index";  console.log(`${owner} raw ${raw}, newest movement ${when}, held ${holdDays} days: ${held}`);}let wallets: string[] = [];try {  wallets = walletArg ? walletArg.split(",") : await recentWallets(3);} catch (e) { console.error(`wallet list failed: ${(e as Error).message}`); }console.log(`mint ${mint}, window ${holdDays} days, ${wallets.length} wallets`);for (const w of wallets.slice(0, 5)) {  try { await check(w); } catch (e) { console.error(`${w} failed: ${(e as Error).message}`); }}

run: CARBIUM_KEY=$CARBIUM_KEY HOLD_DAYS=7 node main.ts

Each output line gives the raw balance, the newest movement in UTC across the wallet's token accounts, and whether the wallet held through the window. The key comes from the environment and is never printed.

04

Where the wallet list comes from

This method does not enumerate every holder of a mint. getTokenLargestAccounts and getProgramAccountsV2 answer -32601 on Carbium, and a retry cannot change that. Take the list from your own records, such as the wallets that bought, claimed or registered, and pass it as the second argument.

Without a list, the script reads the newest transactions that touch the mint and takes the first account key of each, which is the fee payer. Transactions are read at version 1 because mainnet carries v1 transactions, and a call without that setting answers -32015. A fee payer is usually the sender. A token transfer to an existing token account lists the token accounts and the sender's authority, never the receiving wallet, so the receiver is missed. The discovered list is a sample of active senders. It is not the holder set.

05

Where it ends

  • The window is the 30 days ending now. The address index behind getSignaturesForAddress keeps 30 days, so a window that ended 60 days ago is not answered by this check. An empty page past 30 days marks the index's age limit, and the address may have older transactions.
  • A null answer is possible. getTransaction can answer null for an older signature the index lists, because the index reaches below the ledger floor. The script skips it, and a discovery run finds fewer wallets.
  • The test proves no movement, not a balance history. It does not give the balance on each day, and a wallet that moved and came back shows as moved.
  • Amounts are raw base units. Divide by 10 to the power of the mint's decimals to read them as tokens.
  • The calls leave commitment out, so @solana/kit sends confirmed. The newest movement may trail the chain by a moment. A window measured in days is not affected by that.
  • The signature read runs at 0.24 req/s on the Free plan, 1.2 on Dev and 100 on Business, so a long list needs the plan whose rate fits it.
06

When it goes wrong

what goes wrongwhat to do
The wallet list is taken as the mint's whole holder set.No call here returns every holder. Feed in the list from your own records, and read a discovered list as a sample.
A wallet is reported as moved although it only sent a failed transaction.The script counts failed attempts as movement. Read err on the newest signature in your own copy and skip the failed ones.
getTransaction answers -32015 for a discovered transaction.Keep maxSupportedTransactionVersion at 1. An absent or 0 setting is refused for a v1 transaction.
A call answers -32601 and is retried in a loop.Treat -32601 as final. getTokenLargestAccounts and getProgramAccountsV2 are not served, so take the list from your records instead.
A receiving wallet is missing from the results.The discovered wallets are fee payers, mostly senders. Supply the receiving wallets in the second argument.
07

Questions

Can this show who held the token for all of last month?

No. The address index keeps 30 days, and the script checks only the window that ends now. History older than the index is outside this check.

Does a wallet that sold part and bought back still count as held?

No. Any movement on its token account in the window marks it moved, so the answer is conservative. A wallet that never moved keeps its balance and passes.

Do I need a wallet list before I run this?

For the full holder set, yes, because no call here enumerates holders. Without a list, the script samples the fee payers of recent mint transactions, which are mostly senders.