---
id: UC0092
title: "Checkout request simulation check"
url: https://carbium.sh/library/usecase/checkout-request-simulation-check
collection: Use cases
category: Payments and checkout
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Checkout request simulation check

A read-only Node check that tests a payment request's recipient, mint, recipient token account, amount decimals and blockhash against chain state, prints pass or fail for each, and gives a ready verdict before a QR is shown.

## What a simulation needs to pass

A payment request is a short description: a recipient, an amount, often a token mint, and a label or two. The wallet that scans the QR turns that description into a transaction, then runs the transaction against current chain state to show the buyer what will change. That run is a simulation. It fails when the transaction touches an account that is missing, names a mint that does not exist, or carries an amount the token cannot hold.

A merchant never sees the wallet's simulation or the code that builds the transaction. The merchant does control the inputs, and a failure the buyer sees on a phone can trace to one of them being wrong before the QR was drawn. A mistyped recipient, a mint address from the wrong place, a recipient that never had a token account for the token, an amount with too many decimals. Each of those is visible with plain account reads.

> The check reads chain state for the inputs of your request. It does not run the wallet's simulation and cannot see what the wallet builds, so a pass removes the faults you own and nothing else.

## The preflight list

Five checks cover the inputs. The first four apply to every token payment, and the fifth applies when your server builds a transaction and hands it to the wallet.

| Check | Read | Fails when |
|---|---|---|
| Recipient is known on chain | `getAccountInfo` on the recipient | No account at the address and no token account for the mint, which is what a mistyped address that still decodes looks like. |
| Mint exists under a token program | `getAccountInfo` on the mint | The address is absent, or its owner is neither the Token program nor Token-2022. The decimals sit at byte 44 of the mint data. |
| Recipient token account for the mint | `getTokenAccountsByOwner` with a mint filter, and the derived associated address | The owner's associated token account for this mint and its token program is not among the accounts the owner holds. |
| Amount fits the decimals | The mint's decimals | More fraction digits than the mint has, a zero amount, or a value over the largest u64 in base units. |
| Fresh blockhash | `getLatestBlockhash` | The call fails. |

The token account check carries most of the weight. A transfer needs a destination token account, and a request names only the owner. Whoever builds the transaction either finds the account or adds an instruction that creates it and pays its rent. A merchant who confirms the account exists removes one failure source from the buyer's phone. The [token program detection](https://carbium.sh/library/howsolana/token-program-detection) entry shows how to tell which program owns a mint.

A wallet can hold more than one token account for one mint, but a Solana Pay token transfer goes to the recipient's associated token account, the address derived from the owner, the mint's token program and the mint. The check derives that address with `getProgramDerivedAddress` and passes only when it is among the owner's accounts. A wallet with no SOL can still own a token account, so the first check accepts one as proof that the address is known. In that case the line says there is no account at the address and lists the token accounts it holds.

The amount check works in base units. USDC has 6 decimals, so 1.25 becomes 1250000. An amount such as 0.0000001 needs a seventh digit the mint cannot store, and no wallet can send it.

## Run the check

Pass a recipient and an amount to test your own request. With no arguments the script finds a recipient itself. It lists the ten newest signatures on the USDC mint, reads each transaction at `maxSupportedTransactionVersion: 1`, and takes the first owner whose USDC balance went up. That owner has just received USDC, so the checks have live accounts to read. To test another token, change the mint constant.

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

```ts
// UC0092 · Checkout request simulation check
// https://carbium.sh/library/usecase/checkout-request-simulation-check
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Check a payment request's inputs before a QR is shown: recipient, mint, token account, amount, blockhash.
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressEncoder, getProgramDerivedAddress, isAddress } 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 rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const [recipientArg, amount = "1.25"] = process.argv.slice(2);
if ((recipientArg && !isAddress(recipientArg)) || !/^\d+(\.\d+)?$/.test(amount)) {
  console.error("Usage: node main.ts [<recipient> [<amount>]]");
  process.exit(1);
}

const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
const ATA_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";

// With no recipient: the first owner whose USDC balance rose in a recent mint transaction.
async function newestRecipient(): Promise<string> {
  const sigs = await rpc.getSignaturesForAddress(address(USDC), { limit: 10 }).send();
  for (const s of sigs) {
    if (s.err) continue;
    try {
      const tx = await rpc.getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1 }).send();
      const pre = tx?.meta?.preTokenBalances ?? [];
      const got = (tx?.meta?.postTokenBalances ?? []).find((b) => b.mint === USDC && b.owner &&
        BigInt(b.uiTokenAmount.amount) > BigInt(pre.find((p) => p.accountIndex === b.accountIndex)?.uiTokenAmount.amount ?? "0"));
      if (got?.owner) return got.owner;
    } catch (e) { console.log(`getTransaction ${s.signature.slice(0, 8)} failed: ${e}`); }
  }
  throw new Error("no recent USDC receipt found");
}

const recipient = recipientArg ?? await newestRecipient().catch((e: unknown) => { console.error(`discovery failed: ${e}`); return process.exit(1); });
const [wallet, mint, accounts, hash] = await Promise.allSettled([
  rpc.getAccountInfo(address(recipient), { encoding: "base64" }).send(),
  rpc.getAccountInfo(address(USDC), { encoding: "base64" }).send(),
  rpc.getTokenAccountsByOwner(address(recipient), { mint: address(USDC) }, { encoding: "jsonParsed" }).send(),
  rpc.getLatestBlockhash().send(),
]);
const val = <T>(r: PromiseSettledResult<T>): T | undefined => (r.status === "fulfilled" ? r.value : undefined);
const why = (r: PromiseSettledResult<unknown>) => (r.status === "rejected" ? `call failed: ${r.reason}` : "");

const w = val(wallet)?.value;
const m = val(mint)?.value;
const accts = val(accounts)?.value ?? [];
const bh = val(hash)?.value;
const decimals = m ? Buffer.from(m.data[0], "base64")[44] : undefined;
const [whole, frac = ""] = amount.split(".");
const units = decimals === undefined || frac.length > decimals ? undefined : BigInt(whole + frac.padEnd(decimals, "0"));

// A Solana Pay token transfer goes to the owner's associated token account for the mint's token program.
const enc = getAddressEncoder();
const ata = m ? (await getProgramDerivedAddress({ programAddress: address(ATA_PROGRAM),
  seeds: [enc.encode(address(recipient)), enc.encode(m.owner), enc.encode(address(USDC))] }))[0] : undefined;
const held = accts.map((a) => a.pubkey).join(", ");
const hasAta = ata !== undefined && accts.some((a) => a.pubkey === ata);

const noAccount = accts.length ? `no account at the address, holds ${held}` : "no account at the address";
const checks: [string, boolean, string][] = [
  ["recipient is known", w != null || accts.length > 0, w ? `account owned by ${w.owner}` : why(wallet) || noAccount],
  ["mint under a token program", !!m && [TOKEN, TOKEN_2022].includes(m.owner), m ? `owner ${m.owner}, ${decimals} decimals` : why(mint) || "no account at the mint address"],
  ["recipient token account", hasAta, hasAta ? `associated account ${ata}` : accts.length ? `associated account ${ata} is not among ${held}` : why(accounts) || "none for the mint"],
  ["amount fits the decimals", units !== undefined && units > 0n && units < 2n ** 64n, units === undefined ? `${amount} does not fit ${decimals ?? "unknown"} decimals` : `${amount} is ${units} base units`],
  ["blockhash fetched", !!bh, bh ? `valid through block height ${bh.lastValidBlockHeight}` : why(hash)],
];
console.log(`recipient ${recipient}  amount ${amount}`);
for (const [name, ok, detail] of checks) console.log(`${ok ? "PASS" : "FAIL"}  ${name}: ${detail}`);
const ready = checks.every(([, ok]) => ok);
console.log(ready ? "READY: show the QR" : "NOT READY: fix the failed checks first");
process.exitCode = ready ? 0 : 1;
```

The four reads go out together and settle on their own. A failed call prints its reason on its own line and fails only its check. Reads leave commitment out, so `@solana/kit` 8.6.0 fills in confirmed, and each answer describes one moment. Run the check again right before the QR is drawn.

Both `getAccountInfo` reads are account reads at 10 [cells](https://carbium.sh/docs/rpc) each. Discovery adds 50 cells for the signature page and 50 for each transaction it reads. Signature pages come from an address index that keeps up to 30 days, so `getTransaction` can answer null for an older signature, and the loop skips it. Mainnet carries v1 transactions, and a call without `maxSupportedTransactionVersion: 1` answers -32015 for one, which is why discovery sets it.

## Reading a failed check

Each line starts with PASS or FAIL, then the check and what the read returned. The verdict at the end is READY only when every line passes.

- Recipient FAIL: nothing lives at the address and it holds no token account for the mint. Compare it with the address stored on the order. If it is right, the first payment will have to create a token account, and your transaction builder must add that instruction.
- Mint FAIL with an owner shown: the address is an account, but of another kind, so it is not a mint. With no account at all, the address was copied from the wrong place.
- Token account FAIL: the recipient is known but its associated token account for this mint is not among the accounts it holds, or the mint's token program differs from the one you expected. Create the associated token account from the merchant side once, or fix the mint.
- Amount FAIL: round the price to the mint's decimals before building the request, and reject a zero.
- Blockhash FAIL: the call itself failed. A pass means one answered, and a built transaction stays valid for about 150 blocks, which is roughly half a minute at the current slot time, longer where slots are skipped.

## Where it ends

- Wallet-side faults stay with the wallet: how it parses the request, builds the transaction, chooses fees and renders its result. The check reads none of that, and a fault found there goes to the wallet's maker.
- The check never calls a simulation. It compares your inputs with chain state at confirmed at one moment, and the state can change before the buyer approves.
- It does not read a token account's frozen state or decode Token-2022 extensions such as transfer fees, so a transfer those rules block still passes here.
- It covers token payments. A SOL-only request has no mint, no token account and no amount decimals beyond lamports.
- Discovery only finds a recipient in the newest transactions that list the mint, such as a transferChecked or an account creation. A wallet that received the token in some other way does not turn up, so pass the recipient yourself to test it.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The QR scans but the simulation fails on the phone. | Run the check on the exact recipient, mint and amount in the request. A FAIL line names the input to fix. If every line passes, the fault is on the wallet side and the check cannot see it. |
| The recipient token account check fails for a merchant wallet that exists. | The wallet holds no associated token account for this mint. Create it once from the merchant side, or confirm the mint address in the request. |
| The mint check fails for an address that looks like the right token. | The address came from another network or another token. Read its owner in the output: only the Token program and Token-2022 own mints. Copy the mint again from a source you trust. |
| The amount check fails on a small price. | The price has more fraction digits than the mint stores. Round to the mint's decimals, 6 for USDC, before building the URL, and refuse a zero. |
| With no arguments the script prints "discovery failed: no recent USDC receipt found". | None of the ten newest signatures showed a USDC balance rise, or each getTransaction call failed and printed its reason above. Run it again, or pass the recipient yourself. Keep maxSupportedTransactionVersion: 1 on the call, since a v1 transaction answers -32015 without it. |

## Questions

### Does a pass guarantee the wallet's simulation succeeds?

No. The wallet builds and simulates its own transaction, and the check never sees it. A pass means the recipient, mint, token account, amount and blockhash you control match chain state at that moment.

### Why read accounts when I could simulate a transaction myself?

For a payment request the wallet builds the transaction, so yours would differ from the one that fails. The inputs that decide the result are readable with account reads, and the check names the failing input.

### Does the recipient wallet need SOL to receive a token payment?

No. A token payment lands in a token account, and its rent was paid when it was created. An owner wallet with no SOL can still own one, which is why the check treats a token account as proof the address is known.

### When does the blockhash check matter?

When your server builds the transaction and returns it for signing. A transfer request URL carries no blockhash, and the wallet fetches its own.

## Related

- [Token program detection](https://carbium.sh/library/howsolana/token-program-detection) (How to use Solana, HS0025)
- [Send recipient preflight](https://carbium.sh/library/usecase/send-recipient-preflight) (Use cases, UC0061)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/auth](https://carbium.sh/docs/auth)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
