services
Get a key

library / Integrations / Game engines / I0107

Unity reward delivery check

A Node file your game server runs before it pays an SPL token reward. It reads the mint and both candidate token accounts in one call, names the token program the transfer must use, and says whether the player's wallet can receive it.

By Carbium · Game engines · I0107 · updated 2026-11-23

01

What the check answers

A reward transfer fails with an incorrect program id error when the transaction names one token program and the mint belongs to the other. Solana has two of them in everyday use, the original token program and Token-2022, and a game that created its reward mint under one and hardcoded the other in its send code hits this on the first payout. The check runs before the send. Give it the connected player's wallet and one or more mints, and it prints one JSON line per mint.

Each line holds the mint, the slot it was read at, the token program that owns the mint, the mint's decimals, the address of the player's associated token account under that program, and a verdict. A mint that does not exist, or that no token program owns, gets only the mint, the slot and the verdict, and a read that failed prints the mint and the error text.

VerdictWhat the sender does
readySend. The account exists under the right program, belongs to the wallet and is not frozen.
no token accountCreate the associated token account under the printed program in the same transaction as the transfer, or ahead of it.
only the other program's account existsAn account sits at the address derived with the other token program, and none at the printed one. Sending to the other address fails. Create the associated token account at the printed address under the printed program and send there.
frozenThe mint's freeze authority froze the account. A transfer into it fails until it is thawed.
no such mintThe address holds no account at all. Check the mint string your game config carries.
not an SPL mint, owned by ...The address is an account of the program the verdict names, so it is no token mint. The game config carries the wrong address.
token account belongs to another ownerThe account at the associated address was handed to a different owner. A transfer there pays that owner, so hold the reward and ask the player to check the wallet.
account is not a token account of this programSomething other than a token account of the mint's program sits at the address. Do not send; check the wallet and mint strings.
02

Why the program id decides everything

A mint account is owned by the token program that created it. That owner is the only reliable source for the program id: read the mint, look at its owner field, and use that address everywhere. A hardcoded constant in the send code is a guess that holds until someone ships a reward under the other program.

The program id also feeds the address. A player's associated token account is a program derived address from three seeds: the wallet, the token program and the mint. Swap the program and the derivation lands on a different address. A transfer aimed at the address derived with the classic program, for a Token-2022 mint, points at an account that does not exist, and the transfer instruction sent to the wrong program fails on the mint it does not own.

The check derives both candidate addresses on the machine, so neither needs a lookup. It asks for the mint and both accounts in one call, then reads the mint's owner and picks the matching account. All three accounts come from the same slot, so the verdict never mixes two moments. A wallet can own more than one token account for one mint, and the associated one is the address your game computes, so that is the one read. Token-2022 accounts can be longer than the 165 bytes of a classic one because of extensions, and the fields this file reads sit in the same first bytes in both.

For the same program question in a single lookup, see Token program detection.

03

Where the Unity client fits

Unity never calls this file and never sees the key. The reward is sent by your game server, after the client reports a win and the server has checked it. The client gives the server the wallet address the player connected, and the server runs the check on it and on the reward mint before building the transfer. A wallet adapter or deep link in the game build only has to hand over the public key.

In C#, send the address to your server with UnityWebRequest.Post, and have the server answer with the verdict and the program. If the verdict says the account is missing, the server can still send: the transaction it builds carries the create instruction followed by the transfer. If the verdict is frozen, no such mint or any other verdict besides ready and no token account, hold the payout and show a message in the game instead of a raw chain error. Show decimals from the printed value and divide raw amounts by 10 to the power of it.

Run the check once per payout attempt, not once per frame or per screen. A cached answer older than a few seconds can describe an account that has since been created or closed.

04

The check

Install with npm install @solana/[email protected] and set "type": "module" in package.json. Node 24 strips the types on load. CARBIUM_KEY is required and the file exits with a message without it. CARBIUM_RPC_URL is optional.

main.ts
// I0107 · Unity reward delivery check// https://carbium.sh/library/integrate/unity-reward-delivery-check// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport {  address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, getAddressEncoder,  getProgramDerivedAddress, isAddress, type Address,} 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 [walletArg, ...mintArgs] = process.argv.slice(2);if (!walletArg || !isAddress(walletArg) || !mintArgs.length || !mintArgs.every((m) => isAddress(m))) {  console.error("Usage: node main.ts <wallet> <mint> [<mint> ...]");  process.exit(1);}const wallet = address(walletArg);const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);const TOKEN = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");const TOKEN_2022 = address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");const ATA_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");const enc = getAddressEncoder();const dec = getAddressDecoder();// The associated token account is derived from wallet, token program and mint.const ataFor = async (program: Address, mint: Address): Promise<Address> =>  (await getProgramDerivedAddress({    programAddress: ATA_PROGRAM,    seeds: [enc.encode(wallet), enc.encode(program), enc.encode(mint)],  }))[0];async function check(mintText: string) {  const mint = address(mintText);  const [classic, ext] = await Promise.all([ataFor(TOKEN, mint), ataFor(TOKEN_2022, mint)]);  // Mint and both candidate accounts in one call, so all three come from one slot.  const { context, value } = await rpc    .getMultipleAccounts([mint, classic, ext], { commitment: "confirmed", encoding: "base64" })    .send({ abortSignal: AbortSignal.timeout(10_000) });  const slot = context.slot.toString();  const [m, a, b] = value;  if (!m) return { mint, slot, verdict: "no such mint" };  if (m.owner !== TOKEN && m.owner !== TOKEN_2022) {    return { mint, slot, verdict: `not an SPL mint, owned by ${m.owner}` };  }  const is2022 = m.owner === TOKEN_2022;  const program = m.owner;  const ata = is2022 ? ext : classic;  const acct = is2022 ? b : a;  const other = is2022 ? a : b;  const decimals = Buffer.from(m.data[0], "base64")[44]; // mint layout: decimals at byte 44  let verdict: string;  if (acct) {    const d = Buffer.from(acct.data[0], "base64");    // token account layout: owner at bytes 32 to 64, state at byte 108 (2 = frozen)    if (acct.owner !== program || d.length < 109) verdict = "account is not a token account of this program";    else if (dec.decode(d.subarray(32, 64)) !== wallet) verdict = "token account belongs to another owner";    else verdict = d[108] === 2 ? "frozen" : "ready";  } else {    verdict = other ? "only the other program's account exists" : "no token account";  }  return { mint, slot, program, decimals, ata, verdict };}const results = await Promise.allSettled(mintArgs.map(check));results.forEach((r, i) =>  console.log(    JSON.stringify(      r.status === "fulfilled"        ? r.value        : { mint: mintArgs[i], error: r.reason instanceof Error ? r.reason.message : String(r.reason) },    ),  ),);

run: node main.ts <wallet> <mint> [<mint> ...]

05

Run it and read the output

Start it with node main.ts <wallet> <mint> [<mint> ...]. Each mint is checked on its own and one failing read does not stop the others: a failed line prints the error text for that mint. Put your reward mint next to a classic mint such as USDC the first time: when the reward mint is a Token-2022 mint, the two program fields differ in the output.

The read uses commitment confirmed, set in the call. A payout that must not rest on a slot that could be dropped can switch it to finalized. Before the check is wired into a server, compare one verdict against what a block explorer shows for the wallet's token accounts.

06

What it costs against your limits

getMultipleAccounts charges 10 cells per pubkey, so each mint costs 30 cells for its three keys. It is an account read, which Free allows at 0.5 req/s, Dev at 15, Business at 50 and Pro at 400. Limits are per account, so every key on the account shares one budget, and a call over its rate gets a 429 with a retry hint after the one short wait.

A payout flow makes one such call per reward. Calls for many rewards in one pass fit as separate calls per mint, since three keys per mint keeps each call far under the 100 pubkey cap that applies below Pro.

07

Where it ends

  • It only reads. It builds no transaction and holds no private key, so the create instruction and the transfer are yours to write.
  • It checks the associated token account only. A player's wallet may hold the token in another account, and this file does not look for it.
  • Rent for a missing account is paid by whoever signs the create instruction. The check does not price it.
  • Token-2022 extensions that change a transfer, such as a transfer fee or a required memo, are not read. Mint extensions need their own decoder.
  • A verdict is a snapshot. An account can be created or frozen between the check and the send, so keep the send's own error handling.
08

When it goes wrong

what goes wrongwhat to do
The verdict says no token account for a player who says they own the token.The player may hold it in a token account other than the associated one, which the check does not read. Create the associated account under the printed program and send the reward there.
The send still fails with incorrect program id after a ready verdict.The transfer or create instruction names a hardcoded program. Pass the program the check printed into both instructions and into the address derivation.
A line prints an error containing HTTP error (401).The key was refused at the door. Check that CARBIUM_KEY holds the whole key and that the process environment carries it.
A line prints an error containing HTTP error (429).The account is over its account-read rate. Wait the retry-after seconds, run fewer mints per pass, and check that no other key on the account is spending the budget.
The verdict says no such mint.The string in your game config is not a mint on mainnet, or it has a stray character. Copy it from the mint's creation record again.
09

Questions

How do I know which token program my reward mint uses?

Read the mint account and look at its owner. The check prints it as the program field, so run it once with your mint and put that address in your send code, or better, read it at run time.

Does a connected wallet already have an account for my token?

Not until someone creates it. The verdict says no token account in that case, and the transaction that pays the player can create it first and then transfer.

Why derive both addresses instead of fetching the player's token accounts?

Deriving costs no call and the three accounts arrive from one slot. Listing every token account the wallet owns is a heavier read and is not needed to answer this one question.

Can I run the check from the Unity build?

It needs the key, and a key in a build can be read out by the player. Run it on your server and pass the verdict to the client.