services
Get a key

library / Use cases / UC0047

Game prize pool tracker

See what a game's prize pool holds, how much of it a winner can claim, and which transactions paid in or out. Includes a read-only Node script and the cell cost of each refresh.

By Carbium · Gaming · UC0047 · updated 2026-11-22

01

Locking lamports and paying a winner

Lamports locked to a game sit in an account that your game program owns. The usual shape is a program derived address used as a vault: each player's entry fee is a plain transfer into it, and the program records the match, the entry list and the prize in a state account beside it.

The lock is the program's code. An account that carries data can only be debited by the program that owns it, and a program derived address has no private key, so no person holds a key to the vault. A claim instruction checks that the match is finished and that the signer is the recorded winner, then moves the prize out.

The vault has to stay rent exempt until the program closes it, so a slice of its balance is a reserve that no winner can claim. And anyone can send lamports to any address, so the raw balance can run ahead of what your program thinks is in the pool. Keep the prize counter in your program's state and use the chain balance as a cross-check.

Building the deposit and claim instructions and signing them belongs to your program and your wallets. The script below signs and sends nothing.

02

What a tracker reads

  • getAccountInfo on the vault returns its lamports, its owner program and its data length, all at one slot.
  • getMinimumBalanceForRentExemption for that data length gives the reserve. Balance minus reserve is the most a winner could be paid without closing the account.
  • getSignaturesForAddress lists the newest transactions that touched the vault, and getTransaction shows each one's balances before and after. The change at the vault's position in the account list is the deposit or payout, and its sign tells you which.

The script sets finalized on every call, so the numbers it prints are the ones you can show as paid. Solana commitment levels walks through the three levels.

getTransaction takes maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and with the value absent or 0 the call answers -32015 for one of them, uncharged. The script passes 1.

$A lobby can show the pot at confirmed. Use finalized before a number is called paid out.
03

A pool tracker script

The script takes the pool address as its only argument. It reads the account, works out the reserve, then fetches the 8 newest transactions in parallel and settles each, so one failed call prints a line and the rest still show. If the history call itself fails, it prints one line under the balance it already showed.

main.ts
// UC0047 · Game prize pool tracker// https://carbium.sh/library/usecase/game-prize-pool-tracker// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: a game prize pool's SOL, the prize above its rent reserve, and recent deposits and payouts.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 poolArg = process.argv[2];if (!poolArg) { console.error("Usage: node main.ts <pool-account-address>"); process.exit(1); }const pool = address(poolArg);const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const sol = (l: bigint) => (Number(l) / 1e9).toFixed(9);// kit would fill in confirmed; a payout figure is read at finalized, so say so on every call.const commitment = "finalized";const { context, value } = await rpc.getAccountInfo(pool, { encoding: "base64", commitment }).send();if (!value) { console.log(`pool ${pool} does not exist at slot ${context.slot}`); process.exit(0); }const size = Buffer.from(value.data[0], "base64").length;const reserve = await rpc.getMinimumBalanceForRentExemption(BigInt(size), { commitment }).send();const prize = value.lamports > reserve ? value.lamports - reserve : 0n;console.log(`slot ${context.slot} (${commitment})`);console.log(`pool ${pool} owner ${value.owner} data ${size} bytes`);console.log(`balance ${sol(value.lamports)} SOL, rent reserve ${sol(reserve)} SOL, prize ${sol(prize)} SOL`);// The change at the pool's index in a transaction is a deposit (up) or a payout (down).type Tx = {  blockTime: number | bigint | null;  meta: { err: unknown; preBalances: (number | bigint)[]; postBalances: (number | bigint)[] } | null;  transaction: { message: { accountKeys: { pubkey: string }[] } };};try {  const sigs = await rpc.getSignaturesForAddress(pool, { limit: 8, commitment }).send();  const txs = await Promise.allSettled(sigs.map(async (s) =>    (await rpc.getTransaction(s.signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment }).send()) as unknown as Tx | null));  let deposits = 0n, payouts = 0n;  txs.forEach((r, i) => {    const sig = sigs[i].signature.slice(0, 12);    if (r.status === "rejected") return console.log(sig, "call failed:", String(r.reason).slice(0, 80));    const tx = r.value;    if (!tx?.meta) return console.log(sig, "unavailable (null from getTransaction)");    const at = tx.transaction.message.accountKeys.findIndex((k) => k.pubkey === pool);    if (at < 0) return console.log(sig, "pool not in the account list");    const delta = BigInt(tx.meta.postBalances[at]) - BigInt(tx.meta.preBalances[at]);    const when = tx.blockTime == null ? "no time" : new Date(Number(tx.blockTime) * 1000).toISOString();    const label = tx.meta.err ? "failed" : delta > 0n ? "deposit" : delta < 0n ? "payout" : "no change";    if (!tx.meta.err) { if (delta > 0n) deposits += delta; else payouts -= delta; }    console.log(sig, when, label.padEnd(9), `${sol(delta)} SOL`);  });  console.log(`last ${sigs.length} transactions: deposits ${sol(deposits)} SOL, payouts ${sol(payouts)} SOL`);} catch (e) {  console.log("history unavailable:", String(e).slice(0, 80));}

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <pool-account-address>

Each transaction line gives the signature prefix, its time, a label and the change in SOL. A transaction that failed is labelled failed and left out of the sums. The last line adds up deposits and payouts over the window. A signature that getTransaction answers with null prints as unavailable.

For a game of your own, pass the vault address. The sign of the change is the only classification the script makes, so a refund to a player counts as a payout until you decode the instruction.

04

Staying current

A timer re-reads a pool that did not move. WebSocket subscriptions on wss://services.carbium.sh, with ?api-key= in the URL, tell you when to read.

  • logsSubscribe with a mention of the vault address streams every transaction that includes it. Re-read the pool on each notification.
  • signatureSubscribe sends one confirmation for the claim transaction a winner just signed, then ends. Use it to tell the winner the payout landed.
  • accountSubscribe on a vault that is a plain system-owned SOL account sends nothing, so re-read the pool on logsSubscribe notifications, which covers both vault shapes.

A logs-mention subscription opens at 25 credits and a signature subscription at 5, then 20 credits per MiB sent; a refused one costs nothing. Free carries 5 sockets, so open one socket per game server and filter on your side. For many pools, subscribe once to mentions of your program, then call getTransaction on the signature to see which pools moved.

05

Cost of a refresh

Each call is charged in cells, and getTransaction makes up 400 of the 460 cells in one run.

CallCells eachCalls per runCells
getAccountInfo10110
getSignaturesForAddress50150
getTransaction508400
Total-10460

The run makes one more call, getMinimumBalanceForRentExemption, which the 460 does not include.

Account reads run at 0.5, 15, 50 and 400 requests per second on Free, Dev, Business and Pro, and getSignaturesForAddress at 0.24, 1.2, 100 and 500. getTransaction runs at 0.24, 1.2, 5 and 25, so its 8 calls per run are the limit on repeated refreshes. A rate class absorbs bursts up to 1,024 cells, so one full run fits inside the burst on every plan. The plans run $0 with 500K credits once, $20 with 10M, $250 with 50M and $500 with 200M per month.

For the pot display on a game screen, send only the 10-cell account read and fetch history when a notification arrives. A screen that fetched all 8 transactions on every refresh would pay 460 cells where 10 are enough. When the same loop reads many accounts at once, Game state and player items has the budget table.

06

Where it ends

  • The script reads SOL. A pool that pays in an SPL token keeps the prize in a token account, and its balance comes from getTokenAccountBalance on that account. The lamport change in the history stays near 0 for those pools.
  • It labels a movement by its sign. A deposit and a fee top-up look alike, as do a refund and a prize payout, until you decode the instruction.
  • It cannot see the rules. Who may withdraw, and when, is whatever your program's code says, and the lock holds only while nobody can upgrade the program. Audit that code and check its upgrade authority before real money goes in.
  • History comes from an address index that keeps up to 30 days. An empty page past that is the index's age limit, and the address may have older transactions. A signature the list returns can still come back null from getTransaction, so keep your own events table for a permanent record.
  • getProgramAccountsV2 and getTokenLargestAccounts are not served and answer -32601, which means do not retry, so keep your own list of pool addresses in your database.
07

When it goes wrong

what goes wrongwhat to do
The pool holds more SOL than your program's prize counter says.Anyone can send lamports to any address, so extra SOL can arrive without a deposit instruction. Pay winners from the counter in program state, and show the chain balance beside it as a check.
getTransaction answers -32015 for a recent signature.Pass maxSupportedTransactionVersion: 1 with an encoding. With the value absent or 0, mainnet answers -32015 for a v1 transaction.
getTransaction returns null for a signature that getSignaturesForAddress just listed.Treat null as unavailable and carry on. The index reaches below the validator's ledger floor, so older signatures can list without a transaction behind them. Record events yourself as notifications arrive.
A payout announced from a confirmed read is later questioned.Read at finalized before you call a number paid.
Deposits to a token prize pool leave the SOL balance unchanged.Read the vault's token account with getTokenAccountBalance at 10 cells a call. Token transfers leave the token account's SOL balance unchanged.
A history refresh on a Free key returns 429.The 400 getTransaction cells in one run fit that class's 1,024-cell burst, so a 429 on Free comes from refreshes back to back or from a Free key over its network's shared budget, and both history calls run at 0.24 requests per second on Free. Space the refreshes out, read the account on a log notification and fetch history only when one arrives.
08

Questions

Does the tracker prove that only the winner can withdraw?

No. It reports what the chain holds and what moved. The rule that only the winner can claim lives in your program's code, so read and test that code, then use the tracker to watch what it does.

How do I know the winner's withdrawal landed?

Open a signatureSubscribe on the claim transaction's signature. It sends one confirmation and ends. Then re-read the pool, which now shows the balance after the payout.

Do I need one subscription per pool?

No. Subscribe once per game server to logs that mention your program, then read the transaction behind each notification to see which pools it touched. Free carries 5 sockets, so keep the count low.

Why subtract the rent reserve?

The vault has to stay rent exempt until your program closes it, so that slice is never part of a prize. Balance minus reserve is the most a payout can take while the account stays open.