services
Get a key

library / Use cases / Gaming / UC0126

Randomness fulfilment monitor

See whether a randomness account is still being written to, which transactions failed and with what error, and how old the last good one is. Includes a read-only Node script and the cell cost of each check.

By Carbium · Gaming · UC0126 · updated 2026-11-23

01

Where a request stalls

Most on-chain randomness schemes run in two steps. Your client or program sends a transaction that names a randomness account and commits to it. A second transaction then writes the result into that account. In some schemes the oracle sends it. In on-demand schemes your client fetches the oracle's signed reveal and sends it itself, often in the same transaction as your settle instruction. A request that is never fulfilled is a gap between those two steps, and the chain can show you which side of the gap is stuck.

  • No second transaction ever lands. The oracle never sent one, your client never fetched or sent the reveal, or the transaction was dropped before inclusion. The account's history ends at your own request.
  • The second transaction lands and fails. It shows in the account's history with an error, and the data stays as it was.
  • The result is written but your settle transaction fails. The data changed, and your program's own transactions carry the error.
  • Your settle transaction runs before the result exists. It fails on whatever error your program or the oracle's program raises for an unready account.

The script below leaves the oracle's account layout undecoded, and it does not need it. It reads what any account shows: a fingerprint of its data, and the list of transactions that named it with their outcome and time. Those two answer most of the question during an incident.

02

What the monitor reads

  • getAccountInfo on the randomness account returns its owner program, its lamports and its data. The script hashes the data into a short fingerprint and saves it, so the next run can say whether the data changed.
  • getSignaturesForAddress lists the newest transactions that named the account. Each entry already carries an error field, a block time and a slot, so the script needs no getTransaction call, which would add 50 cells for every signature.
  • getSlot gives the tip of the chain, so the age of the newest good transaction shows in slots as well as seconds.

The three calls run in parallel and are settled one by one, so a failed call prints a line and the others still show. All three read at confirmed commitment, so the slot gap compares two values from the same view of the chain.

At about 200 ms a slot, 600 slots behind the tip is about two minutes of quiet. Pick the stale threshold from the gap you expect between a request and its fulfilment, then add margin.

03

A fulfilment monitor script

The script takes the randomness account address and, optionally, the number of seconds after which a quiet account counts as stale. The default is 120.

main.ts
// UC0126 · Randomness fulfilment monitor// https://carbium.sh/library/usecase/randomness-fulfilment-monitor// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: is a randomness account still moving? Newest good and failed transactions, their age, and a data fingerprint.import { createHash } from "node:crypto";import { existsSync, readFileSync, writeFileSync } from "node:fs";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 arg = process.argv[2];if (!arg) { console.error("Usage: node main.ts <randomness-account> [max-age-seconds]"); process.exit(1); }const maxAge = Number(process.argv[3] ?? 120);const target = address(arg);const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));// kit would fill in confirmed anyway; name it so the three reads agree.const commitment = "confirmed";const [acct, sigs, slot] = await Promise.allSettled([  rpc.getAccountInfo(target, { encoding: "base64", commitment }).send(),  rpc.getSignaturesForAddress(target, { limit: 25, commitment }).send(),  rpc.getSlot({ commitment }).send(),]);if (acct.status === "rejected") console.log("account read failed:", String(acct.reason).slice(0, 80));else if (!acct.value.value) console.log(`account ${target} does not exist at slot ${acct.value.context.slot}`);else {  const { data, owner, lamports } = acct.value.value;  const print = createHash("sha256").update(Buffer.from(data[0], "base64")).digest("hex").slice(0, 12);  const file = `fingerprint-${target}.txt`;  const before = existsSync(file) ? readFileSync(file, "utf8") : "";  writeFileSync(file, print);  const moved = before === "" ? "first run" : before === print ? "unchanged since last run" : "CHANGED since last run";  console.log(`owner ${owner} lamports ${lamports} data fingerprint ${print} (${moved})`);}if (sigs.status === "rejected") { console.log("history failed:", String(sigs.reason).slice(0, 80)); process.exit(0); }const list = sigs.value;const good = list.filter((s) => !s.err);const errors = new Map<string, number>();for (const s of list) {  if (!s.err) continue;  const e = JSON.stringify(s.err, (_k, v) => (typeof v === "bigint" ? String(v) : v)).slice(0, 70);  errors.set(e, (errors.get(e) ?? 0) + 1);}console.log(`last ${list.length} transactions: ${good.length} succeeded, ${list.length - good.length} failed`);for (const [e, n] of errors) console.log(`  ${n}x ${e}`);const newest = good[0];if (!newest) console.log("VERDICT: no successful transaction in this window");else {  const age = newest.blockTime == null ? null : Math.round(Date.now() / 1000 - Number(newest.blockTime));  const behind = slot.status === "fulfilled" ? `, ${slot.value - newest.slot} slots behind the tip` : "";  console.log(`newest success ${newest.signature.slice(0, 12)} ${age ?? "?"} s ago${behind}`);  console.log(age != null && age > maxAge ? `VERDICT: STALE, no success for over ${maxAge} s` : "VERDICT: moving");}

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <randomness-account-address> [max-age-seconds]

The output starts with the account line: owner, lamports, the fingerprint and whether it changed since the last run. Then comes a count of succeeded and failed transactions among the newest 25, with each distinct error and how often it appeared. The last two lines give the newest successful transaction, its age and its distance from the tip, then a verdict.

The verdict reports a successful transaction and stops there. Any successful transaction that names the account counts, including a read by another program. The fingerprint line is the proof of a write, so a healthy request shows a recent success and a changed fingerprint together.

04

Reading the output

OutputWhat it meansNext step
Moving, fingerprint changedA transaction succeeded and the data moved since the last run.Read the account with the oracle's decoder and check the value.
Moving, fingerprint unchangedSomething succeeded, but the data did not change.Treat the request as open. Look at who sent the recent successes.
Stale with failures listedThe newest attempts failed with the errors shown.Decode the error against the program that raised it.
No successful transactionNothing good in the last 25.Check that the oracle submits at all, and that your request landed.
Account does not existClosed, never created, or a wrong address.Check the address against your own request record.

A custom program error appears as a number inside the error object. The program's own error table or IDL turns it into a name. Which program raised it is a fact about the failed transaction, so open one failed signature in an explorer or with getTransaction once you know which one to look at.

05

Alerting without polling

A timer that re-checks every open request wastes calls on requests that already finished. WebSocket subscriptions on wss://services.carbium.sh, with ?api-key= in the URL, tell you when something happened.

  • Open logsSubscribe with a mention of the randomness account. Every transaction that names it sends a notification, and the notification carries its signature and error.
  • When you send a request, start a timer for the longest gap you accept. A notification with no error clears it. When the timer fires with no clear, run the monitor once and page someone with its output.

A logs-mention subscription opens at 25 credits, then 20 credits per MiB sent. A quiet randomness account sends very little, so the meter stays low. Free carries 5 sockets and the plan also caps subscriptions, so open one socket per game server with one mention subscription per open request, and close each subscription when its request settles. For paging through older history, Signature history pagination covers the cursor.

06

Cost of a check

Cells are the admission charge per call. One run of the script costs 61 cells.

CallCells eachCalls per runCells
getAccountInfo10110
getSignaturesForAddress50150
getSlot111
Total-361

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. getSlot is a cheap cached read at 5, 30, 100 and 500. A rate class absorbs bursts up to 1,024 cells, so one run fits inside the burst on every plan.

On Free, getSignaturesForAddress allows about one call every four seconds, so a check per open request suits a small game. A game with many open requests should run the monitor from the timer only and read the rest from log notifications.

07

Where it ends

  • The script cannot decode the randomness value or judge whether the oracle's result is valid. The account layout belongs to the oracle's program, so use its own decoder before you settle a game on the value.
  • A transaction dropped before inclusion leaves no trace on the chain. If your request never shows in the history, the fault sits on the sending side, in your client or its RPC path.
  • The fingerprint compares one run with the previous one. Two runs far apart can hide a change followed by a second change that restores the same bytes, which is rare for random data.
  • 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. Keep your own request log for anything older.
  • The script reads only. Resending a request, closing an account and settling a game are your program's job and need your signers.
08

When it goes wrong

what goes wrongwhat to do
The verdict says stale but the oracle is healthy.The threshold is shorter than the real gap between request and fulfilment. Raise the second argument above the longest gap you have seen, and remember 600 slots is about two minutes.
Every recent transaction on the account failed with the same error.The error line shows the program error as a number. Look it up in the table or IDL of the program that raised it, then check what your own settle transaction sends against that.
The account does not exist.Check the address against your request record. Many schemes close the randomness account after use, so a settled game can legitimately show nothing.
The fingerprint changed but the game still waits.Something other than the oracle wrote the account, such as your own commit. Compare the data size and decode the account with the oracle's layout to see whether a result is present.
getSignaturesForAddress returns an empty list for an old request.The address index keeps up to 30 days. An empty page past that is its age limit, and the account may have older transactions. Keep your own log of requests and outcomes.
A check on a Free key returns 429.getSignaturesForAddress runs at 0.24 requests per second on Free, so space checks several seconds apart. Run the monitor from the timer and read the rest from log notifications.
09

Questions

Can the monitor prove the oracle fulfilled my request?

It shows a successful transaction on the account and whether the data changed. It cannot decode the oracle's result. Use the oracle's own account layout to confirm a value is present.

Why not call `getTransaction` for every signature?

The signature list already holds the error, time and slot, and each getTransaction costs 50 cells. Fetch a full transaction only for the one failure you want to inspect.

How often should the monitor run?

Once per open request, after the longest gap you accept, started by a timer that a log notification can cancel. A fixed loop over all requests spends cells on requests that have finished.

Does it work for an oracle I have not used before?

Yes, because it reads only generic account fields: owner, data and the transaction list. It cannot name the program's errors for you.