---
id: SI0063
title: "Token symbol to mint resolver"
url: https://carbium.sh/library/si/token-symbol-to-mint-resolver
collection: AI and blockchain
category: Swap assistants
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Token symbol to mint resolver

A Node script takes a symbol or an address, maps the symbol through a pinned list with one mint per symbol, verifies the mint with one getAccountInfo read, caches it, and prints the Carbium price beside the mint.

## Why symbols collide

A symbol is a label anyone can write into a token's metadata. Nothing on chain stops two mints from both carrying `USDC`. A bridged copy, a wrapped copy and a lookalike minted yesterday can print the same letters, and each is a separate mint with its own supply, its own holders and its own price. An assistant that takes the user's word `USDC` and picks the first search hit can end up quoting a token the user never meant.

The mint address is the identity. A quote, a balance read and a transaction all take a mint, so the resolver has one job: end with a single verified mint address and a price next to it. Two kinds of input arrive, and each gets its own path.

| Input | Path | Result |
|---|---|---|
| Text shaped like an address | Used as the mint, then verified on chain | The mint, its decimals and its token program |
| A symbol on the pinned list | Looked up to its one mint, then verified | The same three values |
| Any other text | Refused before any network call | The line `not on the pinned list` |

## The resolver

The pinned list is a `Map` from a symbol to one mint and the decimals that mint should report. Each symbol holds exactly one entry. A bridged mint that also calls itself `USDC` never enters the list under that name: pin it under a symbol of your own, or have the user paste its address.

Install the one dependency with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types on load. `CARBIUM_KEY` is required, and the script exits with a message when it is unset. `CARBIUM_RPC_URL` is optional. Arguments are symbols or addresses, and with none it resolves `USDC` and then `SOL`.

`main.ts` (run: `node main.ts`)

```ts
// SI0063 · Token symbol to mint resolver
// https://carbium.sh/library/si/token-symbol-to-mint-resolver
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

const key: string = 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 SOL = "So11111111111111111111111111111111111111112";
// One mint per symbol. A bridged copy that also says "USDC" gets its own symbol here, or the user pastes its address.
const PINNED = new Map<string, [string, number]>([
  ["USDC", ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", 6]],
  ["USDT", ["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", 6]],
  ["SOL", [SOL, 9]],
]);
const TOKEN_PROGRAMS = new Set([
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
  "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
]);
const ADDRESS = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
type Mint = { mint: string; decimals: number; program: string };
const cache = new Map<string, Mint>();

async function resolve(q: string): Promise<Mint & { cached: boolean }> {
  const bySymbol = !ADDRESS.test(q);
  const pinned = PINNED.get(q.toUpperCase());
  const mint = bySymbol ? pinned?.[0] : q;
  if (!mint) throw new Error("not on the pinned list");
  const hit = cache.get(mint);
  if (hit) return { ...hit, cached: true };
  const { value } = await rpc.getAccountInfo(address(mint), { encoding: "jsonParsed", commitment: "confirmed" }).send();
  if (!value || !TOKEN_PROGRAMS.has(value.owner)) throw new Error("not an account of a token program");
  const parsed = (value.data as unknown as { parsed?: { type?: string; info?: { decimals?: number } } }).parsed;
  const decimals = parsed?.info?.decimals;
  if (parsed?.type !== "mint" || typeof decimals !== "number") throw new Error("not a token mint");
  if (bySymbol && decimals !== pinned?.[1]) throw new Error(`decimals ${decimals} differ from the pinned ${pinned?.[1]}`);
  const found = { mint, decimals, program: value.owner };
  cache.set(mint, found);
  return { ...found, cached: false };
}

type Prices = { solUsd?: unknown; rows?: unknown[][] };

// One prices call with no params: the mint's row gives the price, solUsd is the SOL fallback.
async function price(mint: string): Promise<number | undefined> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": key },
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "prices", params: [] }),
  });
  const body = (await res.json().catch(() => ({}))) as { result?: Prices; error?: unknown };
  if (!res.ok || body.error) throw new Error(`HTTP ${res.status} ${JSON.stringify(body.error ?? "")}`);
  const cell = body.result?.rows?.find((r) => r[0] === mint)?.[1] ?? (mint === SOL ? body.result?.solUsd : undefined);
  const n = Number(cell);
  return n > 0 ? n : undefined;
}

const queries = process.argv.length > 2 ? process.argv.slice(2) : ["USDC", "SOL"];
for (const q of queries) {
  try {
    const first = await resolve(q);
    console.log(`${q} -> ${first.mint} (decimals ${first.decimals}, program ${first.program.slice(0, 8)})`);
    console.log(`${q} again: ${(await resolve(q)).cached ? "cache hit" : "cache miss"}`);
    const n = await price(first.mint);
    console.log(n ? `${q} price: ${n} USD for ${first.mint}` : `${q}: no price row for ${first.mint}`);
  } catch (e) {
    console.error(`${q}: ${e instanceof Error ? e.message : e}`);
  }
}
```

For each query the script prints up to three lines. The first shows the verified mint with its decimals and the start of its token program id. The second resolves the same query again and reports `cache hit`. The third prints the price next to the mint. The second resolve runs only after the first one passed, so a refused query costs one failed attempt and prints one line.

## Checking the mint on chain

One `getAccountInfo` call with `jsonParsed` encoding, at confirmed commitment, answers three questions. Does the account exist? Does one of the two token programs own it? Does the parsed account say it is a mint, with a decimals value? Token-2022 mints sit under a different program id than the original token program, so the check accepts both ids.

On the symbol path the list also stores the decimals the mint should report. A typo in a pinned address, or a pin that points at the wrong mint, fails at the first resolve instead of reaching a user. An address the user pasted has no expected decimals, so it passes on the first three checks alone.

`getAccountInfo` is an [account read](https://carbium.sh/docs/rpc) at 10 cells a call, and it is metered RPC work, so the cache earns its place. The cache is a `Map` keyed by mint that lives as long as the process. It stores a mint only after every check passed, so a mistyped address is read again on the next try and a failure is never remembered as an answer.

## The price beside the mint

Prices come from the `prices` method on the [same endpoint](https://carbium.sh/docs/endpoints) as RPC, `https://services.carbium.sh`. The file posts it as JSON-RPC with an empty params list and the key in the `x-api-key` header. It reads the answer the way the [SOL price ticker](https://carbium.sh/library/integrate/excel-sol-price-ticker) does: the row whose first cell is the mint supplies the price from its second cell, and for SOL the `solUsd` field is the fallback.

> A key without the QUOTE scope is refused on quote calls with 401 and code -32001. Give the key that scope in your account before the first run.

The number prints on one line with the mint it belongs to. When the answer has no row for a verified mint, the line says `no price row` and shows no number. The mint still counts as verified, because identity and price are two separate reads. An assistant that finds no number should say it has none.

The quote plane [spends no credits](https://carbium.sh/docs/limits), so the price read adds nothing to the credit meter. The cost sits in the account read, which the cache removes for every repeat of a mint.

## When two mints claim a name

The pinned list cannot hold two mints for one symbol, so a clash shows up at the edges of the list. A user pastes an address whose on-chain symbol matches a pinned one, or asks for a symbol you never pinned and a search turns up several mints. Three rules cover it.

- A pasted address wins. It is the identity, and the symbol next to it was only a label. The resolver verifies it and prices it as given.
- A symbol on the list resolves to its one mint. If the user meant another mint with the same symbol, they paste that address.
- A symbol off the list returns `not on the pinned list`. The assistant asks for an address and never searches by name and takes the top result.

Add a symbol only after reading its mint address from the issuer's own published page, then run the resolver on it once so the decimals check has something to compare. The list stays short on purpose. Every entry is a mint you looked at by hand.

## Where it ends

- The check proves an account is a token mint with the expected decimals. It does not prove the mint is the token the user means, and a pasted copycat passes. Pair it with a [name matcher](https://carbium.sh/library/si/copycat-token-name-matcher) before an assistant builds a transaction.
- The pinned list is yours to keep. It holds the symbols you checked and nothing else, and it has no search.
- A mint with no row in the `prices` answer gets no number from this script.
- The cache lives in process memory and empties on restart.
- The script reads only. A swap goes through the `quote` and `swap` methods, and `swap` [builds an unsigned transaction](https://carbium.sh/docs/swap) you sign and send yourself.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The script prints `FOO: not on the pinned list`. | The text is not address-shaped and is not a pinned symbol. Ask the user for the mint address, or add the symbol to the list after reading its mint from the issuer and running the resolver on it once. |
| The script prints `decimals 9 differ from the pinned 6`. | The pinned mint is wrong or mistyped for that symbol. Fix the entry from the issuer's published address, run again, and leave the symbol out of the list until it passes. |
| The script prints `not an account of a token program` or `not a token mint`. | The address is a wallet, a token account or a closed account, and no mint. Ask the user for the token's mint address. A balance holder's token account address is a common wrong paste. |
| The price line fails with HTTP 401 after the mint line printed. | The key is unknown or lacks the QUOTE scope. Attach the [whole key](https://carbium.sh/docs/errors) in `CARBIUM_KEY` and give it the QUOTE scope. The verified mint is still good, and the account read does not need that scope. |
| The script prints `no price row` for a verified mint. | The `prices` answer carries no row for that mint. Report the mint with no price and do not substitute a number from another source. |

## Questions

### Why pin symbols instead of searching by name?

A search returns every mint that carries the name, and copies and bridged mints carry the same symbol as the original. A pinned list gives one mint per symbol, checked once by you, and anything else needs the address.

### Does resolving a symbol cost credits?

The `getAccountInfo` check is metered RPC work at 10 cells a call, and a cache hit makes no call. The `prices` call is on the quote plane, which [spends no credits](https://carbium.sh/docs/limits).

### Does it work for Token-2022 mints?

Yes. The owner check accepts the Token-2022 program id as well as the original token program, and the parsed mint reports decimals the same way.

### What should an assistant do when the user's symbol and pasted address disagree?

Use the address. It is the identity, and the resolver prices what the address names. Show the user the mint you resolved so they can confirm it.

## Related

- [Quote mint validation, vendor-neutral](https://carbium.sh/library/howsolana/quote-mint-validation-vendor-neutral) (How to use Solana, HS0073)
- [Copycat token name matcher](https://carbium.sh/library/si/copycat-token-name-matcher) (AI and blockchain, SI0037)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/quote](https://carbium.sh/docs/quote)
- [carbium.sh/docs/prices](https://carbium.sh/docs/prices)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/swap](https://carbium.sh/docs/swap)
