services
Get a key

library / Blockchain ideas / BI0017

Token approval checker

A read-only checker that takes a wallet address, reads its token accounts under the Token and Token-2022 programs and prints every delegate with its remaining allowance. A team can ship a security screen or a support lookup from it.

By Carbium · Wallet watchers · BI0017 · updated 2026-11-22

01

Who uses it

Three groups want the same list. The first is a wallet app that wants a security screen: before a user signs anything, show who can already move their tokens. The second is a support desk that gets the message "my USDC vanished" and needs to see in one read whether a delegate was set on the account. The third is a hackathon team looking for a small, finished tool that works on any address the judges paste in.

On Solana the answer lives on the token account itself. A token account holds at most one delegate and one allowance, so the whole approval state of a wallet is a list of accounts to read. Nothing needs indexing, and no history is involved.

02

What it checks

An approval is an approve or approveChecked instruction signed by the wallet. It writes a delegate address and an amount into one token account. From then on the delegate can transfer up to that amount out of the account without the owner signing, and a new approval on the same account overwrites the old one. The checker reads the parsed account data and reports these fields.

FieldWhere it comes fromWhat it tells you
Delegateinfo.delegate on the token accountThe address that can move tokens without the owner's signature
Allowanceinfo.delegatedAmountHow much that delegate may still move, as a decimal string
Balanceinfo.tokenAmountWhat the account holds now. The delegate can move at most the smaller of the two numbers
Close authorityinfo.closeAuthorityAn address other than the owner that may close the account once it is empty
Stateinfo.statefrozen means the mint's freeze authority has locked the account, so nothing moves until it is thawed

An allowance far above the balance is common. It covers the current balance plus whatever arrives later, up to the allowance. The checker prints both numbers on one line so that case is visible.

03

The build

The checker is one file that needs @solana/kit and what Node 24 ships. It is read-only: no private key, nothing signed, nothing sent.

  1. Take the wallet address from the first argument. With no argument, read the newest signatures of the USDC mint, fetch a few of those transactions and use each fee payer as a sample wallet until one has token accounts.
  2. Call getTokenAccountsByOwner once per token program, with the program id as the filter and jsonParsed as the encoding. The two programs are Token and Token-2022, and a wallet can hold accounts under either.
  3. Settle the two calls together. If one fails, print why and report the other, so a failure in one program does not hide the other's result.
  4. For every account with a delegate, print the account, the mint, the delegate, the allowance and the balance, and mark frozen accounts.
  5. Print any close authority, then one summary line: accounts found and accounts with a delegate.
main.ts
// BI0017 · Token approval checker// https://carbium.sh/library/blockchainideas/token-approval-checker// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, 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 rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);const PROGRAMS = {  "Token": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",  "Token-2022": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",};// A busy mint: its newest signatures lead to wallets with live token accounts.const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";type Amount = { amount: string; uiAmountString: string };type Row = {  pubkey: string;  account: { data: { parsed: { info: {    mint: string; state: string; tokenAmount: Amount;    delegate?: string; delegatedAmount?: Amount; closeAuthority?: string;  } } } };};const why = (e: unknown) => (e instanceof Error ? e.message : String(e));// Prints every delegate on the wallet's token accounts; returns the account count.async function check(owner: Address): Promise<number> {  const names = Object.keys(PROGRAMS);  const settled = await Promise.allSettled(    Object.values(PROGRAMS).map(async (id) => {      const res = await rpc        .getTokenAccountsByOwner(owner, { programId: address(id) }, { encoding: "jsonParsed" })        .send();      return res.value as unknown as Row[];    }),  );  let accounts = 0;  let delegated = 0;  console.log(`wallet ${owner}`);  settled.forEach((r, i) => {    if (r.status === "rejected") {      console.error(`  ${names[i]} read failed: ${why(r.reason)}`);      return;    }    accounts += r.value.length;    for (const { pubkey, account } of r.value) {      const info = account.data.parsed.info;      if (info.delegate) {        delegated++;        console.log(`  ${names[i]} account ${pubkey} mint ${info.mint}`);        console.log(`    delegate ${info.delegate} allowance ${info.delegatedAmount?.uiAmountString} of ${info.tokenAmount.uiAmountString} held${info.state === "frozen" ? " (frozen)" : ""}`);      }      if (info.closeAuthority) console.log(`  ${pubkey} has close authority ${info.closeAuthority}`);    }  });  console.log(`  ${accounts} token accounts, ${delegated} with a delegate`);  return accounts;}const arg = process.argv[2];if (arg) {  await check(address(arg));} else {  // No wallet given: take fee payers from the mint's newest transactions until one holds tokens.  const sigs = await rpc.getSignaturesForAddress(address(USDC), { limit: 10 }).send();  for (const s of sigs.filter((x) => !x.err).slice(0, 5)) {    try {      const tx = await rpc        .getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1 })        .send();      if (!tx) {        console.error(`${s.signature.slice(0, 8)} not served, skipped`);        continue;      }      if ((await check(tx.transaction.message.accountKeys[0])) > 0) break;    } catch (e) {      console.error(`${s.signature.slice(0, 8)} failed: ${why(e)}`);    }  }}

run: CARBIUM_KEY=<YOUR_KEY> node main.ts [WALLET]

Every call leaves commitment out, so @solana/kit fills in confirmed. Transactions are read with maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and a lower value answers -32015.

To run it: CARBIUM_KEY=<YOUR_KEY> node main.ts <WALLET>. Leave the wallet off to let it pick a recent wallet that holds tokens.

04

What it costs

A scan of a known wallet is two getTokenAccountsByOwner calls, one per token program. Finding a sample wallet adds one getSignaturesForAddress call and up to five getTransaction calls. Each sampled fee payer also costs its own two getTokenAccountsByOwner scans, so a run that tries five candidates makes up to ten scans. Those two methods cost 50 cells each, and each plan allows them at the rates below. RPC work is metered in credits, and unspent credits stay.

PlanCreditsgetSignaturesForAddressgetTransaction
Free ($0)500K once, at sign-up0.24 req/s0.24 req/s
Dev ($20)10M per month1.2 req/s1.2 req/s
Business ($250)50M per month100 req/s5 req/s
Pro ($500)200M per month500 req/s25 req/s

A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. The getSignaturesForAddress and getTransaction calls of the sample-wallet path come to at most 300 cells, inside that on every plan, and the checker runs the transaction reads one after another. The two scans run as a pair.

A product that checks many wallets pays only for the two scans per wallet. It never needs the discovery path, because the wallets come from your own users.

05

What to add next

  • A watch: re-run the scan on a timer and print only the delegates that appeared since the last run, keyed by token account and delegate.
  • A mint filter: pass a list of mints you care about, such as stablecoins, and list only those accounts first.
  • A risk note: flag a delegate that is not in a short list of addresses you recognize, and sort the output by allowance.
  • A revoke link: hand the account and delegate to the wallet's own signing flow, which builds a revoke instruction. Keep this checker read-only and put signing in the wallet.
06

Where it ends

  • It reads delegates on token accounts. A Token-2022 mint can also name a permanent delegate in a mint extension, and that authority lives on the mint, so a token account read does not show it. Check the mint with Token mint supply and authorities.
  • Other grants over a wallet's value are invisible here: an authority over a locked position held by a program, or a program that owns a wallet's funds under its own rules.
  • The owner of a token account is not necessarily a person. A program-derived address that owns accounts shows its own delegates, and the checker treats them like any other.
  • It is a snapshot at one commitment. An approval signed after the read is not in the output.
  • A wallet with thousands of token accounts returns a large response for each program. The checker prints only the delegated ones, but the read is not smaller.
  • The sample-wallet path uses getSignaturesForAddress, whose pages come from an address index that keeps up to 30 days. That only matters for discovery; a wallet you name is read at its current state.
07

When it goes wrong

what goes wrongwhat to do
One program's read fails and the other prints.The line names the program that failed and the error. On a 429, wait for its retry-after hint and run again, and remember that every key on the account draws from one budget.
The first call answers 401 with UNKNOWN_KEY.The key sent is wrong or cut short. Attach the whole key in CARBIUM_KEY. The checker sends it in the x-api-key header.
The summary says 0 token accounts for a wallet you know holds tokens.Check the address for a typo and confirm it is the owner, not a token account address. getTokenAccountsByOwner filters by the wallet that owns the accounts.
A sample transaction prints as skipped.getTransaction can answer null for an older signature that getSignaturesForAddress still lists. The code moves to the next signature. Run it again or pass a wallet.
A freshly signed approval is missing.The read is at confirmed commitment. Wait a moment and run again, and check that the approval transaction itself landed.
08

Questions

Can a token account have more than one delegate?

No. A token account has one delegate field and one allowance field. A new approval replaces the delegate and the amount in place, so the list the checker prints is the full approval state of that account.

Does Solana have unlimited approvals?

An allowance is a 64-bit amount, so a delegate can be given the largest value. The checker prints the number, which makes those cases easy to spot by eye or with a threshold you add.

Can this tool revoke an approval?

No. Revoking is a revoke instruction the wallet owner signs. This checker holds no keys and sends nothing, so it only reports what to revoke.

Why does a wallet with delegates still show nothing on a plain SOL balance check?

SOL and tokens are different accounts. A balance call reads the wallet's lamports. Delegates sit on its token accounts, which is what the two getTokenAccountsByOwner calls read.