---
id: SI0037
title: "Copycat token name matcher"
url: https://carbium.sh/library/si/copycat-token-name-matcher
collection: AI and blockchain
category: RAG and embeddings
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Copycat token name matcher

Give it a mint address. It reads the Metaplex name and symbol in one call, folds lookalike characters, checks them against a list of well-known tokens, and prints COPYCAT, CLOSE or no match with the reference mint beside it.

## What a copycat token looks like

A token's name and symbol are free text its creator chose. Nothing on chain stops a second mint from calling itself USDC, so a wallet screen or an agent that matches on text alone can be handed a different token with the right label. The identity of a token is its mint address. The name is only a claim, and the job here is to find names that claim to be a token they are not.

Copycats come in three common shapes.

- The same text under another mint: name and symbol read exactly like a well-known token.
- Lookalike text: a zero in place of the letter O, a Cyrillic letter inside a Latin word, a trailing space or a zero-width character.
- One edit away: a dropped, doubled or swapped letter, so the symbol differs from the real one by a single character.

When a user asks an agent whether a token is real or fake and pastes a mint address, this check runs as one tool call. The agent gets back which well-known label the suspect collides with and at which mint, which is evidence it can quote. [Read-only model tools](https://carbium.sh/library/si/read-only-model-tools) covers wiring read tools to a model.

## Reading names from Metaplex metadata

Most mints on mainnet keep their name and symbol in a Metaplex metadata account. Its address is derived from the seeds `metadata`, the metadata program id and the mint. The account starts with a key byte, a 32 byte update authority and the 32 byte mint. The name, symbol and uri follow as length-prefixed strings, padded with zero bytes to 32, 10 and 200 bytes. The file reads the first two and trims the padding.

The read is one call. `getMultipleAccounts` takes the derived addresses of the candidate and the six reference mints together. It is an account read that charges 10 cells per pubkey, so seven accounts cost 70 cells in a single request. The call passes `commitment: "confirmed"` and `encoding: "base64"`, and names change rarely enough that confirmed is plenty.

A mint with no metadata account comes back as null and is skipped. Token-2022 mints can hold the name inside the mint itself, which needs a different read, shown in [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup).

## The matcher file

One file on @solana/kit 8.6.0 and Node 24, which runs the TypeScript directly. Set `CARBIUM_KEY` first; the file exits with a message when it is unset. `CARBIUM_RPC_URL` overrides the endpoint, which defaults to `https://services.carbium.sh`.

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

```ts
// SI0037 · Copycat token name matcher
// https://carbium.sh/library/si/copycat-token-name-matcher
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Copycat token name matcher: compare a mint's name and symbol with well-known tokens.
// Run: CARBIUM_KEY=... node main.ts [mint]
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 } }));

type Tok = { mint: string; name: string; symbol: string };
const META = address("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const REFS = [
  "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
  "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", // USDT
  "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN", // JUP
  "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", // BONK
  "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So", // mSOL
  "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn", // JitoSOL
];
const LOOKALIKES: Tok[] = [["B0NK", "B0NK"], ["Jupіter", "JUP"], ["USD C0in", "USDC"], ["Orchard Pay", "ORCH"]]
  .map(([name, symbol]) => ({ mint: "", name, symbol }));

const FOLD: Record<string, string> = {
  "0": "o", "1": "l", i: "l", "5": "s", "3": "e", "4": "a", $: "s", "@": "a",
  "а": "a", "е": "e", "о": "o", "р": "p", "с": "c", "х": "x", "і": "l",
};
const skel = (s: string) =>
  [...s.normalize("NFKC").toLowerCase()].map((c) => FOLD[c] ?? c).join("").replace(/[^a-z0-9]/g, "");

function lev(a: string, b: string): number {
  let row = Array.from({ length: b.length + 1 }, (_, j) => j);
  for (let i = 1; i <= a.length; i++) {
    const next = [i];
    for (let j = 1; j <= b.length; j++) next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
    row = next;
  }
  return row[b.length];
}

function judge(a: Tok, b: Tok): string {
  let out = "";
  for (const [x, y] of [[a.name, b.name], [a.symbol, b.symbol]]) {
    const s = skel(x), t = skel(y);
    if (!s || !t) continue;
    if (s === t) return "COPYCAT";
    if (Math.max(s.length, t.length) >= 4 && lev(s, t) <= 1) out = "CLOSE";
  }
  return out;
}

async function load(mints: string[]): Promise<Tok[]> {
  const enc = getAddressEncoder();
  const pdas = await Promise.all(mints.map(async (m) =>
    (await getProgramDerivedAddress({ programAddress: META, seeds: ["metadata", enc.encode(META), enc.encode(address(m))] }))[0]));
  const { value } = await rpc.getMultipleAccounts(pdas, { commitment: "confirmed", encoding: "base64" }).send();
  return value.flatMap((acc, i): Tok[] => {
    if (!acc) return [];
    try {
      const b = Buffer.from(acc.data[0], "base64");
      let o = 65; // key byte, update authority, mint
      const str = () => {
        const n = b.readUInt32LE(o);
        const s = b.toString("utf8", o + 4, o + 4 + n).replace(/\0/g, "").trim();
        o += 4 + n;
        return s;
      };
      return [{ mint: mints[i], name: str(), symbol: str() }];
    } catch { return []; }
  });
}

const candidate = process.argv[2];
const toks = await load(candidate ? [candidate, ...REFS] : REFS).catch((e: Error) => {
  console.error(`failed: ${e.message}`);
  return process.exit(1);
});
const refs = toks.filter((t) => REFS.includes(t.mint));
console.log(`references read: ${refs.map((r) => r.symbol).join(", ")}`);
const subjects = [...toks.filter((t) => t.mint === candidate), ...LOOKALIKES];
if (candidate && subjects.length === LOOKALIKES.length) console.log(`no Metaplex metadata at ${candidate}`);
for (const s of subjects) {
  const hits = refs.filter((r) => r.mint !== s.mint).map((r) => [judge(s, r), r] as const).filter(([v]) => v);
  const text = hits.map(([v, r]) => `${v} ${r.symbol} (${r.mint})`).join("; ");
  console.log(`${s.name} [${s.symbol}] ${s.mint.slice(0, 8)}: ${text || "no match"}`);
}
```

Pass one mint address as the first argument to test it. The file also tests three built-in lookalike labels every run: `B0NK` with a zero, `Jupiter` with a Cyrillic letter in it, and `USD C0in` carrying the real USDC symbol, plus one invented name that should match nothing. The reference list holds six well-known mints: USDC, USDT, JUP, BONK, mSOL and JitoSOL. Edit `REFS` to hold the tokens your users get impersonated as.

Each subject prints one line with its name, its symbol, the first eight characters of its mint, and every reference it collides with. The reference mint is printed in full, so the line can go straight to a user.

## Folding lookalike characters

Two labels are compared after a fold. Unicode NFKC turns full-width and styled letters into plain ones, the text is lowercased, and a short table maps common stand-ins to one letter each: `0` to `o`, `1` and `i` to `l`, `5` to `s`, `3` to `e`, `4` to `a`, and a few Cyrillic letters to their Latin twins. Everything outside `a-z` and `0-9` is then dropped, which removes spaces, punctuation and zero-width characters.

| Label | After the fold | Reference label |
|---|---|---|
| B0NK | bonk | BONK |
| USD C0in | usdcoln | USD Coin |
| Jupiter with a Cyrillic i | juplter | Jupiter |

Mapping `1` and `i` to the same letter is deliberate. A fold only has to send both sides of a lookalike pair to one string, and the result does not need to read well. Two real labels that differ only by `i` against `l` collide, which is the intent.

After the fold, equal strings are a COPYCAT. Strings within one edit of each other, when the longer has at least four characters, are CLOSE. The length floor stops three letter symbols from matching each other by accident.

## Reading COPYCAT and CLOSE

COPYCAT means the folded name or the folded symbol equals a reference's while the mint differs. Show it to the user in full, with the reference mint beside the suspect. CLOSE means one edit apart, and it catches honest neighbours too: USDC and USDT differ in their last letter, so listing both in `REFS` makes each flag the other. Treat CLOSE as a prompt to look and COPYCAT as a stop.

A line that ends in `no match` says the label does not collide with the six references. A scam token can wear a name no list holds, so the line never says safe. An agent given these lines should be told to quote the reference mint on a hit and to say nothing about safety on a miss.

A wrapped version of a well-known token under its own mint also prints COPYCAT, since same label under another mint is exactly the pattern. Keep a short allow list of mints you have checked by hand and skip them before judging.

## Cost and reuse

A run reads seven accounts in one request at 70 cells. Reference metadata changes rarely, so a service that checks many mints should read the references once, keep them in memory and spend cells only on candidates. `getMultipleAccounts` takes up to 100 pubkeys a call on plans below Pro, because the 1,024 cell burst caps a call there. Up to 300 a call is Pro's.

String distance finds labels that look alike. It does not find labels that mean the same, such as 'Wrapped USD Coin' for USDC. For that, embed the names and symbols of your reference list, retrieve the nearest few for each candidate and feed them to the model with the string verdicts, as in [Live account RAG](https://carbium.sh/library/si/live-account-rag). The string pass is the cheap first step and needs no model.

A look at who controls the mint belongs next to this check. [Token authority screening](https://carbium.sh/library/usecase/token-authority-screening) screens mint and freeze authorities, a separate signal from the label.

## Where it ends

- The chain cannot say which token is real. The reference list does, so a token that is not on it cannot be judged, and a clear result is only the absence of a collision.
- Name and symbol can change while the update authority holds the right to edit them. Store the mint and the time of the read next to the verdict.
- Mints that keep metadata inside a Token-2022 mint are skipped. They need the `metadataPointer` extension read described in [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup).
- The fold table is short. Greek, Armenian and other homoglyphs pass until you add them, and edit distance misses translations and reordered words.
- Many legitimate tokens share a label, such as wrapped versions of one asset. Every hit is a flag for review.
- A candidate with no metadata account prints a line saying so and gets no verdict.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The candidate prints a no-metadata line while the references load. | The mint has no Metaplex account. Fetch it with `getAccountInfo` and look for the metadata inside the mint, as a Token-2022 mint with the `metadataPointer` extension does. |
| The run prints `failed:` and no verdicts. | Read the message after it. A 401 UNKNOWN_KEY means the whole key was not attached, so check `CARBIUM_KEY`. A wrong `CARBIUM_RPC_URL` also lands here. The file makes one read, so there is nothing partial to keep. |
| A real token is flagged CLOSE against another real one, such as USDT against USDC. | That pair is one edit apart by design. Skip pairs where both mints are on your reference list, and read CLOSE as a prompt to look. |
| A lookalike written with Greek or other letters comes back with no match. | Add the letter pair to `FOLD`, then rerun the labels that slipped through to confirm they now collide. |
| A longer reference list returns an error from the single read. | Send at most 100 pubkeys a call below Pro and join the results. The 1,024 cell burst caps a call there, and 300 a call is Pro's. |

## Questions

### Can this tell me a token is real?

No. It reports whether a label collides with a token you listed. Real means the mint address matches one you trust, so keep the list of mints and compare addresses first.

### Why does a wrapped USDC show COPYCAT?

A wrapped version carries the same label under a different mint, which is the pattern the matcher looks for. It cannot know the mint is fine. Add that mint to an allow list in the file and skip it.

### Does it work on NFT collections?

A collection NFT is a mint with its own metadata account, so the read is the same. Item names usually end in a number, so compare the collection's own name, since numbered names rarely match.

### How do I hand the result to a model?

Return the printed line as the tool result. It holds the suspect's mint, the reference mint and the verdict. Tell the model to quote the reference mint on a hit and to claim nothing on a miss.

## 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#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
