services
Get a key

library / AI and blockchain / ML classification / SI0069

Token-2022 transfer labels

Reads up to 100 mints in one call and prints a JSON line per mint with a set of labels: fee-on-transfer, hook-accounts-required, non-transferable, permanent-delegate, default-frozen, can-pause and paused, plus the fee rate in force this epoch.

By Carbium · ML classification · SI0069 · updated 2026-11-22

01

Which instruction works when

The Token-2022 program has three transfer forms. Transfer moves an amount and names no mint. TransferChecked names the mint and its decimals, so the program can compare them with the mint's own. TransferCheckedWithFee does the same and also states the fee the sender expects to pay. A transfer hook has no instruction of its own: the token program calls a second program in the middle of TransferChecked, and people shorten that to a hook-checked transfer.

A mint with no extensions takes all of them. A mint with a transfer fee refuses plain Transfer. Plain Transfer passes no mint account, and the program needs the mint to read its fee config, its hook and its pause state, so it refuses the transfer. The same holds for a mint with a transfer hook or a pause extension: their token accounts carry account extensions that make plain Transfer fail with MintRequiredForTransfer. A non-transferable account fails every transfer form with NonTransferable, because Token-2022 checks that account extension before it looks for the mint. A hook mint also needs the sender to append the accounts the hook program asks for. The hook program lists them in a validation account derived from the seed extra-account-metas and the mint address. A transaction that leaves them out fails inside the hook call.

Code written for the legacy token program calls Transfer and keeps working on Token-2022 until it meets one of these mints. A compatibility check therefore needs a per-mint answer to two questions: which form does this mint need, and can a transfer succeed at all right now.

The second question has its own causes. A non-transferable mint refuses every transfer. A paused mint refuses transfers until its pause authority resumes it. A mint whose default account state is frozen creates token accounts that cannot send or receive until the freeze authority thaws them. A permanent delegate can move or burn tokens in any account of the mint without the owner's signature, so a balance can leave in a transfer its holder never signed.

02

The label set

Each mint gets a set of labels, so a feature row for a classifier has one flag per label and a mint with three powers gets three flags. The labels come from the extensions in the mint account, which the node decodes when asked for jsonParsed data.

LabelExtension readWhat it means for a transfer
fee-on-transfertransferFeeConfigThe mint needs TransferChecked or TransferCheckedWithFee, and the receiver gets the amount minus the fee.
hook-accounts-requiredtransferHook with a program idThe mint needs TransferChecked plus the accounts the hook program lists. The hook can also reject the transfer. A transferHook extension with no program id sets the form to TransferChecked and gets no label.
non-transferablenonTransferableEvery transfer fails.
permanent-delegatepermanentDelegateOne address can move or burn tokens from any account of the mint.
default-frozendefaultAccountState set to frozenNew token accounts start frozen and cannot move tokens until thawed.
can-pausepausableConfig with an authorityThe pause authority can stop transfers whenever it chooses, whether or not the mint is paused now.
pausedpausableConfig with paused trueTransfers fail until the authority resumes the mint.

A mint with a pause authority carries can-pause while it runs normally, so the pause power is visible before it is used. The paused label appears only while the switch is on. A classifier can weigh them separately: the first describes who holds control, the second describes the mint today.

A mint with none of these extensions gets an empty set, and a legacy token program mint prints an empty set too. Every row has the same shape. The names of all extensions found on the mint are printed in full next to the labels, so an extension without a label still shows up for a reviewer.

03

The fee rate in force

The transferFeeConfig extension holds two rates, olderTransferFee and newerTransferFee. Each has an epoch, a transferFeeBasisPoints rate and a maximumFee cap in raw token units. When the fee authority sets a new rate, it lands in the newer slot and takes effect two epochs later. The program charges the newer rate once the current epoch reaches its epoch and charges the older rate until then.

The script reads getEpochInfo in the same pass as the mints and picks the rate by epoch. The fee field in each output line holds the rate in force now. When the newer rate is still ahead, a scheduled field names it and its starting epoch, so a future rate never reads as the current one. If the epoch call fails, the line carries both rates under rates and picks neither.

The fee on an amount is the amount times the basis points over 10,000, rounded up and capped at maximumFee. Transfer fee calculator works that calculation through for a sender and a receiver. Transfer vs TransferChecked decoder decodes the two instruction forms from a landed transaction.

04

The label script

One file with @solana/kit as its only dependency. Node 24 runs the TypeScript as written. Set CARBIUM_KEY first; the file exits with a message when it is unset. Pass mint addresses as arguments, or pass none.

main.ts
// SI0069 · Token-2022 transfer labels// https://carbium.sh/library/si/token-2022-transfer-labels// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Token-2022 transfer labels. Run: CARBIUM_KEY=... node main.ts [mint ...]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 rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key } }),);const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";const PYUSD = "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo";const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";const c = { commitment: "confirmed" } as const;async function newestMints(): Promise<string[]> {  const sigs = await rpc.getSignaturesForAddress(address(TOKEN_2022), { limit: 8, ...c }).send();  const txs = await Promise.allSettled(    sigs.map((s) => rpc.getTransaction(s.signature, { maxSupportedTransactionVersion: 1, encoding: "json", ...c }).send()),  );  const found = new Set<string>();  for (const t of txs) {    if (t.status === "rejected") { console.error("transaction failed:", String(t.reason)); continue; }    if (!t.value) { console.error("transaction not found, skipped"); continue; }    const tx: any = t.value;    for (const b of tx.meta?.postTokenBalances ?? []) if (b.programId === TOKEN_2022) found.add(b.mint);  }  return [...found];}function label(info: any, epoch?: number) {  const ext = new Map<string, any>((info.extensions ?? []).map((e: any) => [e.extension, e.state ?? {}] as [string, any]));  const labels: string[] = [];  const out: Record<string, unknown> = {};  const fee = ext.get("transferFeeConfig");  if (fee) {    labels.push("fee-on-transfer");    const { olderTransferFee: older, newerTransferFee: newer } = fee;    const rate = (r: any) => ({ epoch: Number(r.epoch), bps: Number(r.transferFeeBasisPoints), max: String(r.maximumFee) });    if (epoch === undefined) out.rates = { older: rate(older), newer: rate(newer) };    else {      const pending = epoch < Number(newer.epoch);      out.fee = rate(pending ? older : newer);      if (pending) out.scheduled = rate(newer);    }  }  const hook = ext.get("transferHook");  if (hook?.programId) { labels.push("hook-accounts-required"); out.hookProgram = hook.programId; }  if (ext.has("nonTransferable")) labels.push("non-transferable");  if (ext.get("permanentDelegate")?.delegate) labels.push("permanent-delegate");  if (ext.get("defaultAccountState")?.accountState === "frozen") labels.push("default-frozen");  const pause = ext.get("pausableConfig");  if (pause?.authority) labels.push("can-pause");  if (pause?.paused) labels.push("paused");  const checked = ["transferFeeConfig", "transferHook", "pausableConfig", "nonTransferable"].some((x) => ext.has(x));  const form = checked ? "TransferChecked" : "Transfer or TransferChecked";  const blocked = labels.includes("non-transferable") || labels.includes("paused");  return { labels, form, blocked, ...out, extensions: [...ext.keys()] };}const args = process.argv.slice(2);let found: string[] = [];if (!args.length) {  try { found = await newestMints(); } catch (e) { console.error("newest mints failed:", String(e)); }}const mints = [...new Set(args.length ? args : [PYUSD, USDC, ...found])].slice(0, 100);const [epochRes, accRes] = await Promise.allSettled([  rpc.getEpochInfo(c).send(),  rpc.getMultipleAccounts(mints.map((m) => address(m)), { encoding: "jsonParsed", ...c }).send(),]);const epoch = epochRes.status === "fulfilled" ? Number(epochRes.value.epoch) : undefined;if (epochRes.status === "rejected") console.error("epoch failed:", String(epochRes.reason));if (accRes.status === "rejected") { console.error("accounts failed:", String(accRes.reason)); process.exit(1); }(accRes.value.value as any[]).forEach((acc, i) => {  const info = acc?.data?.parsed?.info;  if (!info || acc.data.parsed.type !== "mint") { console.log(JSON.stringify({ mint: mints[i], error: "not a readable mint" })); return; }  console.log(JSON.stringify({ mint: mints[i], program: acc.owner === TOKEN_2022 ? "token-2022" : "token", ...label(info, epoch) }));});

run: node main.ts

With no arguments the script checks a Token-2022 stablecoin (PYUSD), legacy USDC as a control with no extensions, and the mints it finds in the newest transactions that touched the Token-2022 program. It lists the eight newest signatures for the program, reads each transaction with maxSupportedTransactionVersion: 1, and collects mints from the post-transaction token balances whose programId is the Token-2022 program. A transaction that returns null or fails is reported and skipped. All reads use confirmed commitment.

Then one getEpochInfo call and one getMultipleAccounts call with jsonParsed encoding run together and settle on their own, so a failed epoch read still leaves the labels. The accounts call takes at most 100 mints. It charges 10 cells per pubkey, and a body of 100 addresses is over 4 KiB, so the call costs 1001 cells, which still fits the 1,024-cell burst below Pro. A Pro key may send up to 300 in one call. The signature and transaction lookups cost 50 cells each, so the discovery step costs at most 450 cells.

Each output line is JSON with these fields: mint, program, labels, form (the instruction form to send), blocked (true for a non-transferable or paused mint), fee for fee mints, together with scheduled when a newer rate is still ahead or rates when the epoch read failed, hookProgram for hook mints, and extensions, the full list of extension names found. A mint account that cannot be read prints its mint and an error field.

05

Where it ends

  • The labels describe the mint at confirmed commitment in one read. Authorities can change a rate, pause the mint or reassign the hook later, so cache a label set for a short time and re-read before a decision that moves funds.
  • hook-accounts-required says the mint needs extra accounts. It does not list them and it does not say the hook will accept the transfer. The hook program decides that, and its code can change if its authority upgrades it.
  • The script reads the mint account and no token accounts. Account-level settings such as a required memo on incoming transfers, and the frozen state of one holder's account, live on the token account.
  • Confidential transfer, interest-bearing and other extensions appear by name in extensions and have no label. An extension the node's parser does not know shows as unparseable there.
  • A freeze authority on any mint, legacy mints included, can freeze a holder's account. The script does not label it.
  • The newest balances of the Token-2022 program are a sample of what moves right now and give no ranking of mints.
06

When it goes wrong

what goes wrongwhat to do
A plain Transfer on a mint with a transfer fee fails.Send TransferChecked with the mint's decimals, or TransferCheckedWithFee with the expected fee. The form field says which mints need it.
A transfer on a hook mint fails inside the hook program.Resolve the extra accounts from the hook program's validation account (seed extra-account-metas and the mint) and append them to TransferChecked.
getTransaction answers -32015 while collecting mints.Pass maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and an absent or 0 value is refused for one.
getTransaction answers null for a signature that getSignaturesForAddress just listed.Skip it and use the others. The address index reaches below the validator's ledger floor, so a listed signature can be unreadable.
A call with more than 100 mints is capped on a key below Pro.Send chunks of 100. The 1,024-cell burst caps a call at 100 pubkeys below Pro, and only a Pro key may send up to 300.
The fee shown is a rate that has not started yet.Compare the current epoch with newerTransferFee.epoch. Use the older rate until the epoch reaches it, and show the newer one as scheduled.
07

Questions

Why a label set instead of one risk score?

The labels answer different questions. A fee changes the amount, a hook changes the accounts, a pause changes whether anything moves. A row of flags lets a classifier or a compatibility check weigh each one and explain its result.

Which instruction should my code send?

Send TransferChecked for every Token-2022 mint, since it works on mints with and without extensions. Add the hook accounts when hook-accounts-required is set. Use TransferCheckedWithFee when you want the program to reject a transfer whose fee differs from the one you expect.

Does hook-accounts-required mean the transfer will fail?

No. It means the transfer needs extra accounts to reach the hook program. Whether the hook accepts it depends on that program's own rules.

How many calls does one run make?

One signature list, up to eight transaction reads, one epoch read and one getMultipleAccounts call. With mint arguments given, the discovery calls are skipped and the run makes two calls.