---
id: UC0013
title: "NFT ticket check-in"
url: https://carbium.sh/library/usecase/nft-ticket-check-in
collection: Use cases
category: Ticketing and events
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# NFT ticket check-in

Check a Solana ticket token at the door: confirm the mint is a one-of-one, the wallet holds it and nobody scanned it already. One read per scan, a Node script with a local scan log, and where the check ends.

## What the door decides

A ticket token is an ordinary SPL token. For a one-of-one ticket the mint has 0 decimals and a supply of 1, so only one wallet can hold it at a time, and whoever holds it holds the seat. A scan at the gate turns into four checks, in this order.

1. The mint is a ticket: it belongs to a token program, has 0 decimals and a supply of exactly 1, and is on the event's list of ticket mints.
2. The presenting wallet holds it: its token account for that mint exists, names the wallet as owner and carries a balance of 1.
3. The account is initialized: a frozen token account still admits, because programmable NFTs keep the holder's account frozen at all times, and the verdict line reports the state.
4. The ticket has not been scanned already: entry changes nothing on chain, so the door keeps its own log.

A token is not used up by entry, so the same wallet passes the first three checks all night. The scan log is part of the validation, and it must be written in the same step that admits the person.

> If token accounts and associated addresses are new to you, read [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) first.

## One RPC call per scan

The script reads what the first three checks need in one `getMultipleAccounts` call: the mint, plus the wallet's associated token account for that mint under each of the two token programs, Token and Token-2022. A mint belongs to one program, so one of the two accounts is real and the other comes back empty. The call goes to [`https://services.carbium.sh`](https://carbium.sh/docs#endpoints) with the key in the [`x-api-key` header](https://carbium.sh/docs#auth), and it reads at finalized commitment.

Each pubkey in the call costs [10 cells](https://carbium.sh/docs#rpc), so a scan of three pubkeys costs 30 cells. Account reads run at 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro, and each call draws its cells from the plan's budget.

Those rates hold for a 10-cell call, and a 30-cell scan draws three times as many cells, so a plan admits scans at a third of its rate: about 5 a second on Dev, 16 on Business and 133 on Pro, and one every 6 seconds on Free. A class also [absorbs a burst of 1,024 cells](https://carbium.sh/docs#limits) or one second of its rate, whichever is larger, which is about 34 scans at once below Pro.

## The check-in script

The script takes a ticket mint and a wallet address, prints one verdict line and keeps the scan log with `node:sqlite`. It reads `CARBIUM_KEY`, and optionally `CARBIUM_RPC_URL`, `EVENT_MINTS` (a comma-separated list of the event's ticket mints) and `SCANS_DB` (the log file, `scans.db` by default). While `EVENT_MINTS` is empty or unset the script refuses every scan, so a door that lost its configuration admits nobody.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY EVENT_MINTS=<mint1>,<mint2> node main.ts <ticket-mint> <holder-wallet>`)

```ts
// UC0013 · NFT ticket check-in
// https://carbium.sh/library/usecase/nft-ticket-check-in
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only door check: does this wallet hold the one-of-one ticket token, and was it scanned already?
import { DatabaseSync } from "node:sqlite";
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressEncoder, getProgramDerivedAddress } 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 args = process.argv.slice(2);
if (args.length === 1) { console.error("Usage: node main.ts [<ticket-mint> <holder-wallet>]"); 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 TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
const ATA_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
const TOKEN_METADATA = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
const enc = getAddressEncoder();
const ata = async (owner: string, mint: string, program: string) => (await getProgramDerivedAddress({
  programAddress: address(ATA_PROGRAM),
  seeds: [enc.encode(address(owner)), enc.encode(address(program)), enc.encode(address(mint))],
}))[0];

type Bal = { accountIndex: number; mint: string; owner?: string; uiTokenAmount: { amount: string; decimals: number } };
type Tx = { meta: { postTokenBalances?: Bal[] } | null; transaction: { message: { accountKeys: { pubkey: string }[] } } };
type Acc = { data: readonly [string, string]; owner: string } | null | undefined;

let failed = 0;
let first = "";
const note = (e: unknown) => { failed++; first ||= e instanceof Error ? e.message : String(e); };

// No arguments: take the first 0-decimal, supply-1 token held in its owner's associated account from the Token Metadata program's newest signatures, five reads at a time.
const find = async (): Promise<[string, string] | null> => {
  const until = Date.now() + 20_000;
  const sigs = (await rpc.getSignaturesForAddress(address(TOKEN_METADATA), { limit: 1000, commitment: "finalized" }).send().catch((e) => { note(e); return []; })).filter((s) => !s.err);
  const seen = new Set<string>();
  for (let i = 0; i < sigs.length && Date.now() < until; i += 5) {
    const reads = await Promise.allSettled(sigs.slice(i, i + 5).map((s) => rpc.getTransaction(s.signature, { commitment: "finalized", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 }).send()));
    for (const r of reads) {
      if (r.status === "rejected") { note(r.reason); continue; }
      const tx = r.value as unknown as Tx | null;
      for (const b of tx?.meta?.postTokenBalances ?? []) {
        if (b.uiTokenAmount.decimals !== 0 || b.uiTokenAmount.amount !== "1" || !b.owner || seen.has(b.mint)) continue;
        seen.add(b.mint);
        if (tx?.transaction.message.accountKeys[b.accountIndex]?.pubkey !== await ata(b.owner, b.mint, TOKEN)) continue;
        const supply = await rpc.getTokenSupply(address(b.mint), { commitment: "finalized" }).send().catch((e) => { note(e); return null; });
        if (supply?.value.amount === "1") return [b.mint, b.owner];
      }
    }
  }
  return null;
};

const allowed = (process.env.EVENT_MINTS ?? "").split(",").filter(Boolean);
const raw = (a: Acc) => (a ? Buffer.from(a.data[0], "base64") : null);
const judge = (mint: string, holder: string, [mintAcc, classic, next]: readonly Acc[]): string => {
  const m = raw(mintAcc);
  const program = mintAcc?.owner;
  if (!m || m.length < 82 || (program !== TOKEN && program !== TOKEN_2022)) return "REJECT: no token mint at this address";
  const supply = m.readBigUInt64LE(36);
  if (supply !== 1n || m[44] !== 0) return `REJECT: a ticket has supply 1 and 0 decimals, this mint has supply ${supply} and ${m[44]} decimals`;
  if (!allowed.includes(mint)) return "REJECT: mint is not on this event's list (EVENT_MINTS)";
  const t = raw(program === TOKEN_2022 ? next : classic);
  if (!t || t.length < 165 || !Buffer.from(t.subarray(32, 64)).equals(new Uint8Array(enc.encode(address(holder))))) return "REJECT: this wallet has no ticket account";
  if (t.readBigUInt64LE(64) !== 1n) return "REJECT: this wallet no longer holds the ticket";
  if (t[108] === 0) return "REJECT: ticket account is uninitialized";
  const db = new DatabaseSync(process.env.SCANS_DB ?? "scans.db");
  db.exec("create table if not exists scans (mint text primary key, holder text, at text)");
  const firstScan = db.prepare("insert or ignore into scans values (?, ?, ?)").run(mint, holder, new Date().toISOString()).changes;
  return firstScan ? `ADMIT: ticket held by ${holder}, mint authority ${m.readUInt32LE(0) ? "set" : "none"}, account ${t[108] === 2 ? "frozen" : "active"}` : "REJECT: already scanned";
};

// One scan, one fresh read: the mint and the wallet's associated token account under each token program (3 pubkeys, 30 cells).
const check = async (mint: string, holder: string): Promise<string> => {
  const { context, value } = await rpc.getMultipleAccounts(
    [address(mint), await ata(holder, mint, TOKEN), await ata(holder, mint, TOKEN_2022)],
    { encoding: "base64", commitment: "finalized" },
  ).send();
  return `${judge(mint, holder, value)} (slot ${context.slot}, finalized, 30 cells)`;
};

const demo = args.length === 0;
const found = demo ? await find() : null;
if (demo && !found) {
  console.error(`No ticket-shaped token in the newest signatures (${failed} reads failed${first ? `, first error: ${first}` : ""}). Pass a mint and a wallet.`);
  process.exit(1);
}
const [mint, holder] = found ?? (args as [string, string]);
if (demo) console.log(`No arguments, checking a recent ticket-shaped token: mint ${mint}, holder ${holder}`);
if (demo) allowed.push(mint);
for (let n = 0; n < (demo ? 2 : 1); n++) console.log(await check(mint, holder));
```

The log is a table with the mint as primary key. `insert or ignore` admits the first scan and changes no rows on the second, so two scans of one ticket that reach the file at once cannot both get in. The log opens only after the chain checks pass, so a rejected scan leaves no row. A read error throws, which a door should treat as a refusal.

With no arguments the script finds a ticket-shaped token itself. It walks the newest 1,000 finalized signatures of the Token Metadata program, where NFT mints and transfers show up, and reads their transactions five at a time, for up to 20 seconds, at [50 cells each](https://carbium.sh/docs#rpc). It takes the first 0-decimal token balance of 1 whose mint has a supply of 1 and whose holder's associated account holds it. It allows that mint and checks twice, so the first line shows ADMIT and the second shows the scan log refusing a repeat as already scanned. When nothing fits, it prints the first read error and exits with code 1.

The script decodes the base64 account data itself. A mint stores its supply at byte 36 and its decimals at byte 44. A token account stores the owner at byte 32, the balance at byte 64 and its state at byte 108, where 0 is uninitialized, 1 is active and 2 is frozen. Both token programs use those offsets, and Token-2022 extensions only append after them. Only state 0 is refused. The admit line also says whether the mint authority is still set and whether the account is frozen. Read both as information, since some token standards keep an authority that cannot mint more and programmable NFTs keep the holder's account frozen by design.

## Prove the wallet is the holder

A wallet address on a QR code proves nothing: anyone can photograph a ticket screen, and every address is public on chain. The script checks that an address holds the ticket. The attendee's phone still has to show it controls that address.

The usual flow adds a challenge. The door shows a random nonce with the event id and a short expiry. The attendee's wallet signs that message, which needs no transaction and no fee. The door verifies the ed25519 signature against the wallet address, then runs the script with that address. The signature check runs at the door and needs no RPC call. Make the nonce single-use and tied to the gate session, so a replayed signature fails.

## Queues, transfers and history

A pre-event sweep can check every sold ticket before doors open and leave only the scan and the signature for the gate. Every one-of-one ticket has its own mint, so a sweep reads the mint and the holder's associated token account for each ticket: two pubkeys per ticket, 20 cells. A `getMultipleAccounts` call takes up to 300 pubkeys, but the 1024-cell burst caps a call at 100 pubkeys below Pro. A sweep call therefore covers 50 tickets and 1,001 cells on Free, Dev and Business, because a body of 100 base58 addresses runs past 4 KiB, and 150 tickets only on Pro.

| Read | Cost | What it tells the door |
|---|---|---|
| getMultipleAccounts, 3 pubkeys | 30 cells | The scan itself: mint, holder and balance |
| getSignaturesForAddress on the ticket's token account | 50 cells | When the ticket last moved, up to 30 days back |
| logsSubscribe with mentions of a token account | Opens at 25 credits, then 20 credits per MiB sent | A transfer while the ticket waits in the line |

A resale rule such as no transfer in the last hour reads [recent signatures](https://carbium.sh/docs#rpc) of the ticket's token account. Use the token account's address, because a plain transfer names the token accounts involved and the mint appears only in some transfer forms. The pages come from Carbium's own address index, which keeps up to [30 days](https://carbium.sh/docs#migrate).

To hear about a transfer while the line moves, [subscribe](https://carbium.sh/docs#websocket) with `logsSubscribe` mentions of a queued ticket's token account over `wss://services.carbium.sh`, with the key as `?api-key=` on the URL. Socket and subscription counts are capped per account by tier, and Free carries 5 sockets, so keep subscriptions to the tickets in the line.

Create the RPC client once at start-up and call `check` with a mint and a holder for each scan, from a loop or a small HTTP handler. Every call reads the chain again, so each scan judges fresh state.

## Where it ends

- The check reads standard token accounts: one mint per ticket, held in the wallet's associated token account. A ticket held in another account, or issued in another form, needs its own check.
- The script reads no metadata. It does not know the event or collection a mint belongs to, and the `EVENT_MINTS` list stands in for that.
- The scan log is one file. Doors on separate devices need one shared store, or the same ticket can enter at two doors. Every key on an account also [shares one budget](https://carbium.sh/docs#limits), so several gate devices draw on the same rates.
- The signature challenge is not in the script. Without it the holder address is a claim. A wallet that cannot sign messages, such as some program-controlled wallets, needs another route.
- The script does not retry a 429. See [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) for handling it.
- Methods that are not served answer [-32601](https://carbium.sh/docs#errors), which means do not retry. `getSignaturesForAddress` reaches back 30 days at most, and an empty page past that is the index's age limit.
- Check-in is off chain. Burning or marking the token needs a signed transaction, which this read-only script never makes.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The same ticket enters twice. | Write the scan log in the same step that admits, with the mint as primary key, as `insert or ignore` does. Give every door the same store. |
| A valid ticket is rejected with no ticket account for the wallet. | The ticket sits in a token account that is not the wallet's associated one. Find the account by other means, or have the holder move the ticket to the associated account. |
| Scans return 429 when doors open. | Compare peak scans per second with the account-read rate of your plan, counting three pubkeys per scan. Scan again after the retry-after value, sweep holders before doors open, or move up a plan. |
| Someone shows a screenshot of another person's ticket. | Add the signed challenge before the chain check. Admit only when the signature verifies against the wallet address. |
| A scan ends in an error at the door and staff wave the person through. | Treat any error as a refusal and scan again. The script throws on a failed read and never prints ADMIT without a completed check. |
| A mint passes the supply check but belongs to another event, or every scan is refused. | Set `EVENT_MINTS` to tonight's ticket mints. The script refuses any other mint, and every scan while the list is empty. |

## Questions

### Does check-in have to burn or mark the ticket on chain?

No. The script only reads, and the scan log marks the ticket as used. Burning or updating a token needs a signed transaction from the holder or the issuer, which is a separate job.

### Can the door keep working if the venue network drops?

The chain check needs a live read. A door can keep holder lists from a pre-event sweep and fall back to them, with the risk that a ticket moved after the sweep.

### How do several gates share one scan log?

Point every gate at one shared database instead of a local file and keep the mint as primary key, so the first insert wins and every later gate sees the ticket as already scanned. The gates also draw on one account budget, so size the peak scan rate for all of them together.

### Why check both supply and decimals?

A token with 0 decimals and a supply of 1 has one holder at a time. A larger supply lets many wallets pass the same check, which can suit a general-admission pass if you choose it on purpose.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [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#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
