---
id: HS0025
title: "Token program detection"
url: https://carbium.sh/library/howsolana/token-program-detection
collection: How to use Solana
category: Token-2022
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Token program detection

One TypeScript file takes mint addresses, reads them 100 to a call, and prints which token program owns each one, which Token-2022 extensions alter a transfer, and the token account address for a wallet you name. It only reads.

## Two programs, one test

Solana has two token programs. The legacy SPL Token program is `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`. Token-2022 is `TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb`. A mint belongs to exactly one of them, and the program that owns the mint account is the answer to your question. No name, symbol or tag in the mint says it, so the owner field is the whole test.

The owner matters because everything around the mint follows it. Token accounts for that mint are owned by the same program, the instruction you send to move tokens must name that program, and the address of a wallet's associated token account is derived with the program id as one of its seeds. Use the legacy id for a Token-2022 mint and the derived address points at an account that does not exist.

1. Read the mint with `getAccountInfo` or `getMultipleAccounts` and look at `owner`.
2. Owner is the legacy id: a classic mint with no extensions.
3. Owner is the Token-2022 id: the mint may carry extensions, and some of them change what a transfer does.
4. Any other owner: the address is not a token mint.

The same test works on a token account. Its owner is also one of the two programs, and its `mint` field names the mint.

## The code

Add `@solana/kit` 8.6.0 to the project, set `CARBIUM_KEY` and start the file on Node 24, which strips the types itself. Pass mint addresses as arguments and the file reads them 100 to a call. With none, it checks USDC, a legacy mint, and PYUSD, a Token-2022 mint. Set `OWNER` to a wallet address and the file also prints that wallet's token account for each mint.

`main.ts` (run: `node main.ts [mint-address ...]`)

```ts
// HS0025 · Token program detection
// https://carbium.sh/library/howsolana/token-program-detection
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));

const TOKEN: string = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
const TOKEN_2022: string = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
const ATA_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
const USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const PYUSD = "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo";

const WATCH: Record<string, string> = {
  transferFeeConfig: "a fee is withheld on every transfer",
  transferHook: "another program runs on every transfer, its accounts must ride along",
  nonTransferable: "transfers are refused",
  permanentDelegate: "a delegate can move or burn any balance",
  pausableConfig: "transfers stop while the mint is paused",
  defaultAccountState: "new token accounts may start frozen",
  confidentialTransferMint: "balances can be hidden",
};
type Ext = { extension: string; state?: any };
type Parsed = { parsed?: { type?: string; info?: { decimals?: number; extensions?: Ext[] } } };

const mints = process.argv.slice(2);
if (mints.length === 0) mints.push(USDC, PYUSD);
const owner = process.env.OWNER;

const accounts: any[] = [];
const failed = new Set<string>();
for (let i = 0; i < mints.length; i += 100) {
  const batch = mints.slice(i, i + 100);
  const keys = batch.map((m) => address(m));
  try {
    const r = await rpc.getMultipleAccounts(keys, { encoding: "jsonParsed", commitment: "confirmed" }).send();
    accounts.push(...r.value);
  } catch (e) {
    console.error(`mints ${i + 1} to ${i + batch.length} failed: ${e instanceof Error ? e.message : String(e)}`);
    for (const m of batch) failed.add(m);
    accounts.push(...batch.map(() => null));
  }
}
const enc = getAddressEncoder();
for (const [i, mint] of mints.entries()) {
  if (failed.has(mint)) {
    console.log(`${mint}: read failed`);
    continue;
  }
  const acct = accounts[i];
  if (!acct) {
    console.log(`${mint}: no account`);
    continue;
  }
  const program = acct.owner === TOKEN_2022 ? "Token-2022" : acct.owner === TOKEN ? "legacy SPL Token" : null;
  const parsed = (acct.data as unknown as Parsed).parsed;
  if (!program || parsed?.type !== "mint") {
    console.log(`${mint}: not a token mint (owner ${acct.owner})`);
    continue;
  }
  console.log(`${mint}: ${program}, ${parsed.info?.decimals} decimals, token program id ${acct.owner}`);
  for (const x of parsed.info?.extensions ?? []) {
    const effect = WATCH[x.extension];
    if (!effect) continue;
    let detail = "";
    if (x.extension === "transferFeeConfig") {
      const bps = x.state?.newerTransferFee?.transferFeeBasisPoints;
      if (!bps) continue;
      detail = ` (${bps} bps)`;
    }
    if (x.extension === "transferHook") {
      if (!x.state?.programId) continue;
      detail = ` (program ${x.state.programId})`;
    }
    console.log(`  ${x.extension}: ${effect}${detail}`);
  }
  if (owner) {
    const [ata] = await getProgramDerivedAddress({
      programAddress: ATA_PROGRAM,
      seeds: [enc.encode(address(owner)), enc.encode(acct.owner), enc.encode(address(mint))],
    });
    console.log(`  token account for ${owner}: ${ata}`);
  }
}
```

The read asks for `jsonParsed` encoding, so the node decodes the mint and lists its extensions by name. With base64 you would decode the extension layout yourself. The call reads at confirmed commitment. Each page of 100 is settled on its own: when one fails, the file prints the range of mints it covered, prints read failed for those mints and carries on with the other pages.

The token account address is a program derived address with three seeds: the wallet, the token program that owns the mint and the mint, under the associated token account program. The file computes it locally. It makes no request for it, and the result is an address whether or not the account has been created yet.

## Reading the output

Each mint prints one line with its program, its decimals and the token program id, followed by one indented line for every watched extension that is active on the mint.

| Extension | What it means for a transfer |
|---|---|
| transferFeeConfig | A fee is withheld from every transfer, so the receiver gets less than the sender sent. The line shows the configured basis points |
| transferHook | Another program runs on every transfer, and its accounts must ride along in the instruction. The line shows the hook program |
| nonTransferable | Transfers are refused, the token is bound to its holder |
| permanentDelegate | A delegate can move or burn any holder's balance |
| pausableConfig | Transfers stop while the mint is paused |
| defaultAccountState | New token accounts may start frozen |
| confidentialTransferMint | Balances can be hidden, and a plain transfer moves only the public balance |

A fee extension set to 0 basis points withholds nothing, and a hook extension with no program set runs nothing, so the file prints no line for either. A Token-2022 mint with no extension lines has none of the watched extensions active. Its transfers and token accounts still use the Token-2022 program id.

> Metadata, group and pointer extensions change nothing about a transfer and are left out on purpose. For where a mint keeps its name and image, see [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup).

## Sending the transfer

The file stops at detection, since sending needs a signer.

- The program id on the instruction is the owner you just read. A Token-2022 mint takes the Token-2022 id, and the legacy id fails the instruction.
- The sender's and receiver's token accounts are the derived addresses the file prints, computed with that same program id.
- Use the checked transfer, which carries the mint and its decimals, so the program verifies the amount's scale. The instruction data layout is the same for both programs.
- If the receiver has no token account yet, create it with the idempotent associated token account instruction, passing the token program id, before the transfer in the same transaction.

A mint with `transferFeeConfig` still accepts the plain checked transfer, and the program withholds the fee. The fee-aware transfer instruction is optional and only makes the program check the fee you expect to pay. A mint with `transferHook` needs the hook program and its extra accounts appended to the transfer instruction. A client library for Token-2022 builds these for you, and the extension lines the file prints tell you which case you are in before you build.

## On Carbium

`getMultipleAccounts` is an account read at 10 cells per pubkey, so three mints cost 30 cells in one request. The [account-read class](https://carbium.sh/docs#rpc) allows 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro. A call takes up to 300 pubkeys on Pro, but the 1024-cell [burst](https://carbium.sh/docs#limits) caps a call at 100 pubkeys below Pro. The file sends at most 100 pubkeys per call, so it runs on any plan. A longer list goes out as several calls one after another. A full 100-mint call costs 1001 cells because its body passes 4 KiB.

## Where it ends

The file tells you which program owns a mint and which transfer-relevant extensions it carries. It does not tell you whether a given transfer will succeed. A transfer hook can reject a transfer for reasons that live in its own program, a paused mint rejects every transfer, and a receiver's token account can be frozen. Extensions on the token accounts themselves, such as a receiver that requires a memo on incoming transfers or a CPI guard, also change a transfer and do not show on the mint. Only a simulation or a landed transaction shows the result, and this file sends nothing.

The extension table covers the common ones. Token-2022 adds extensions over time, and a new one will not print until you add it to the `WATCH` map. An unknown extension on the mint is silent, so a missing line proves nothing about it.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The line for an address says no account. | Check the spelling and that it is a mainnet address. A mint created in the last moments can be missing from a `confirmed` read, so try again after a few seconds. |
| The line says not a token mint and shows an owner. | You passed a wallet, a token account or another program's account. For a token account, read its `mint` field with `getAccountInfo` and `jsonParsed`, and run the file on that mint. |
| A transfer fails with an incorrect program id or an account that does not exist. | The instruction or the derived token account used the wrong token program. Take the owner the file prints for the mint and use it for both. |
| HTTP 429 with a retry-after hint. | Pass fewer mints per run. Every 100 mints go out as one call of 1001 cells, since the body is over 4 KiB, so a longer list sends several calls back to back. A plan with a higher account-read allowance also clears it. |
| The file throws an invalid address error. | A mint argument is not a valid base58 address, and the file throws before it prints any line. A bad `OWNER` throws after the first token mint's line. Look for a missing character or a token symbol pasted in place of an address. |

## Questions

### Can I tell the program from the token account instead of the mint?

Yes. A token account is owned by the same program as its mint. Read the account with `jsonParsed` and its owner gives the program, while its `mint` field names the mint.

### Does the same transfer instruction work for both programs?

The checked transfer has the same shape in both, but the program id on the instruction must match the mint's owner. A hook mint needs the hook program and its extra accounts, and a fee mint takes the same checked transfer with the fee withheld.

### Why not guess from the address?

Nothing in the address shows its program. Only the owner field of the account does, and one call reads it for up to 100 mints below Pro, or 300 on Pro.

### Do I need a private key to run this?

No. The file reads accounts and derives an address locally. The Carbium key only identifies your account to the RPC.

## Related

- [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup) (How to use Solana, HS0013)
- [Token authority screening](https://carbium.sh/library/usecase/token-authority-screening) (Use cases, UC0009)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
