---
id: UC0140
title: "Member points statement"
url: https://carbium.sh/library/usecase/member-points-statement
collection: Use cases
category: Loyalty, rewards and memberships
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Member points statement

Turn a points token into a statement a member can read: the current balance, then each movement in the last 30 days, read from the wallet's own transactions with no signing and no database.

## Points live in token accounts

A points program on Solana usually issues a token. Each member holds it in one or more token accounts, and the member's balance is the sum of those accounts. A statement therefore reads the wallet on chain, and nothing has to be kept in step with a second copy of the balance.

The statement has two parts. The first is the balance today. The second is the list of movements that changed it, newest first, each with a UTC time, a signature and the signed change in whole points. Both parts come from the chain, so a member's view and your own records can be compared line by line.

Finding the member is the step that needs care. A transfer into an existing token account lists the token accounts and the sender's authority in its account keys. The receiving wallet is not among them. The member is therefore read from the token balance entries in the transaction metadata, where each entry names its owner. Pass the wallet when you know it. Without one, the script takes the member from up to ten of the newest transactions on the points mint.

## Movements from transaction metadata

The movement list starts with the wallet's signatures. `getSignaturesForAddress` returns them newest first, and its pages come from an [address index](https://carbium.sh/docs/migrate) that keeps up to 30 days. Past that window a page comes back empty, so the statement covers 30 days and stops there.

For each signature the script asks for the transaction with `maxSupportedTransactionVersion` set to 1. Mainnet carries v1 transactions, and a call without that setting answers -32015 for one. The script then adds the points-mint amounts held by the member's token accounts before the transaction and after it. The difference is the movement. A zero difference is skipped, so a transaction that leaves the balance alone does not appear, and a move between two accounts the member owns nets to zero.

| Call | Cells | Used for |
|---|---|---|
| getSignaturesForAddress | 50 | the wallet's newest signatures, within the 30-day index |
| getTransaction | 50 | one read per signature, for its balance entries and block time |

The balance is one read with `getTokenAccountsByOwner`, filtered to the points mint and parsed. The amounts are added as BigInt, so large point counts and many accounts stay exact.

## The statement in one file

The script takes the points mint as its first argument and the member wallet as the second. Every call goes to the [RPC endpoint](https://carbium.sh/docs/endpoints) through one `rpc` function, which attaches your key and reads the answer or the error. Each movement is read on its own, so one failed read prints a line and the rest of the statement still runs.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY node main.ts EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`)

```ts
// UC0140 · Member points statement
// https://carbium.sh/library/usecase/member-points-statement
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only member points statement: today's balance and the last 30 days of movements for one wallet.
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 [mintArg, ownerArg] = process.argv.slice(2);
// Demo default: USDC, a busy mint with movements to read. Pass your own points mint as the first argument.
const MINT = mintArg ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const COMMIT = "confirmed";
const MAX_TX = 5;

type Amount = { amount: string; decimals: number };
type TokenBal = { mint: string; owner?: string; uiTokenAmount: Amount };
type Sig = { signature: string; blockTime: number | null; err: unknown };
type Tx = { blockTime: number | null; meta: { err: unknown; preTokenBalances?: TokenBal[]; postTokenBalances?: TokenBal[] } | null };
type Reply<T> = { result?: T; error?: { code: number; message: string } };

let nextId = 0;
async function rpc<T>(method: string, params: unknown[]): Promise<T | null> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": key as string },
    body: JSON.stringify({ jsonrpc: "2.0", id: ++nextId, method, params }),
  });
  if (res.status === 429) throw new Error(`${method} throttled, retry-after ${res.headers.get("retry-after") ?? "unknown"} s`);
  const body = (await res.json()) as Reply<T>;
  if (body.error) throw new Error(`${method} ${body.error.code}: ${body.error.message}`);
  return body.result ?? null;
}

// The balance entries name each token account's owner, so a receiving member is read from them.
async function findOwner(mint: string): Promise<string> {
  const sigs = (await rpc<Sig[]>("getSignaturesForAddress", [mint, { limit: 10, commitment: COMMIT }])) ?? [];
  for (const s of sigs.filter((x) => !x.err)) {
    const tx = await rpc<Tx>("getTransaction", [s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: COMMIT }]);
    const owner = tx?.meta?.postTokenBalances?.filter((b) => b.mint === mint && b.owner)[0]?.owner;
    if (owner) return owner;
  }
  throw new Error("no member wallet in the newest transactions on this mint");
}

const held = (list: TokenBal[] | undefined, owner: string) =>
  (list ?? []).filter((b) => b.mint === MINT && b.owner === owner).reduce((n, b) => n + BigInt(b.uiTokenAmount.amount), 0n);
const show = (x: bigint, d: number) => {
  const a = x < 0n ? -x : x;
  const frac = (a % 10n ** BigInt(d)).toString().padStart(d, "0");
  return `${x < 0n ? "-" : "+"}${(a / 10n ** BigInt(d)).toString()}${d ? "." + frac : ""}`;
};

let owner: string;
try { owner = ownerArg ?? (await findOwner(MINT)); }
catch (e) { console.error(`No member found: ${e instanceof Error ? e.message : e}`); process.exit(1); }
console.log(`Points mint ${MINT}`);
console.log(`Member ${owner}`);

const accounts = await rpc<{ value: { account: { data: { parsed: { info: { tokenAmount: Amount } } } } }[] }>(
  "getTokenAccountsByOwner", [owner, { mint: MINT }, { encoding: "jsonParsed", commitment: COMMIT }]);
const amounts = (accounts?.value ?? []).map((a) => a.account.data.parsed.info.tokenAmount);
const decimals = amounts[0]?.decimals ?? 6;
const balance = amounts.reduce((n, t) => n + BigInt(t.amount), 0n);
console.log(`Balance today: ${show(balance, decimals)} points in ${amounts.length} token account(s)`);

const since = Date.now() / 1000 - 30 * 86_400;
const sigs = (await rpc<Sig[]>("getSignaturesForAddress", [owner, { limit: MAX_TX, commitment: COMMIT }])) ?? [];
console.log(`Movements, newest ${MAX_TX} signatures within 30 days:`);
for (const s of sigs) {
  try {
    const tx = await rpc<Tx>("getTransaction", [s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: COMMIT }]);
    if (!tx?.meta) { console.log(`${s.signature.slice(0, 8)} not available from the ledger`); continue; }
    if ((tx.blockTime ?? 0) < since) continue;
    const delta = held(tx.meta.postTokenBalances, owner) - held(tx.meta.preTokenBalances, owner);
    if (delta === 0n) continue;
    const when = new Date((tx.blockTime ?? 0) * 1000).toISOString().slice(0, 19) + "Z";
    console.log(`${when} ${s.signature.slice(0, 8)} ${show(delta, decimals)}`);
  } catch (e) {
    console.log(`${s.signature.slice(0, 8)} failed: ${e instanceof Error ? e.message : e}`);
  }
}
```

Every call names its commitment. The JSON-RPC server answers finalized when a call leaves commitment out, while @solana/kit fills in confirmed. The two clients can therefore show different movements for the same wallet. This script asks for confirmed everywhere, so one run agrees with itself. The balance prints first, so a reader sees the total before the movements.

## Keep the reads within budget

- A statement costs one signature page and one transaction read per movement checked. Five transactions at 50 cells each come to 250 cells, on top of the signature call's 50. `MAX_TX` sets the count, so raise it only where the account has room for it.
- The [budget](https://carbium.sh/docs/limits) belongs to the account. Every key on the account draws on the same cells, so a second key for statements adds no capacity.
- Cache each movement by signature once it is finalized. A finalized transaction does not change. A later statement then reads only the new signatures and the balance, and nothing older.
- Pass the member wallet when you already know it. The owner search reads up to ten transactions on the mint before it finds one.

## Where it ends

- History stops at 30 days. The address index keeps up to 30 days, and an empty page past that is the index's age limit, so older history may still exist. A longer statement needs a copy you keep yourself, filled while the movements are new.
- A signature the index lists can still answer null from getTransaction, because the index reaches below the validator's ledger floor. The script prints it as not available and moves on.
- The statement shows balance changes only. A reward recorded in a memo or in your database, and never moved as tokens, cannot appear on it.
- A member can hold points in several token accounts. The script adds them, and it reads only the accounts the RPC returns for that wallet and mint.
- The script reads five movements by default and does not page. A member with a long history gets the newest five, and the statement says nothing about the rest.
- The mint in the demo is USDC, a busy stand-in so the run has movements to read. It is not a points token. Use your own points mint.
- The [limits](https://carbium.sh/docs/limits) are shared per account. A batch of statements for many members needs a plan whose rate covers it, so check the plan before you run every member at once.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The statement comes back with no movements for a member who has points. | Check the wallet. The script reads a wallet's token accounts, and a token account's own address matches no owner, so it returns nothing. Pass the wallet that owns the account. |
| getTransaction answers -32015 for a movement the member just made. | Keep maxSupportedTransactionVersion at 1. Mainnet carries v1 transactions, and a call without that setting answers -32015. |
| Two runs a few seconds apart show different movements for the same member. | Each read asks for confirmed, and the newest movements can still settle between runs. Cache movements once they are finalized and recompute only the newest signatures. |
| The balance and the movements do not add up. | Sum the balance across every token account the wallet owns for the mint, then compare it with the movements in the window. Movements older than 30 days sit outside the index, so read them from your own copy. |
| A throttled read stops the statement. | Each read is settled on its own. A throttled call prints its retry-after hint, and the other movements still print. Rerun that member after the wait, or lower MAX_TX. |

## Questions

### Can a member's statement show points from before 30 days?

Not from the address index, which keeps up to 30 days. Keep your own copy of movements while they are new, and read the older part from that copy.

### Does a member need to connect a wallet or sign anything?

No. The script reads public balances and transactions for a wallet address and signs nothing. A member view built on these reads needs no signing step.

### Why is the member found in the transaction metadata?

A transfer into an existing token account lists the token accounts and the sender's authority, and the receiving wallet is missing from that list. The token balance entries name each account's owner, so the receiving member appears there.

### Is the USDC mint a points token?

No. It is the default so the demo has a busy mint to read. Pass your own points mint as the first argument.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [Wallet token holdings](https://carbium.sh/library/usecase/wallet-token-holdings) (Use cases, UC0005)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
