---
id: I0055
title: "Meilisearch token name directory"
url: https://carbium.sh/library/integrate/meilisearch-token-name-directory
collection: Integrations
category: Search and time series
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Meilisearch token name directory

A Node script derives the metadata address for each mint, reads up to 50 mints in one call, decodes name and symbol from Metaplex or Token-2022 accounts, and prints one Meilisearch document per mint with the place its name came from.

## Where a token's name is stored

A mint account holds supply, decimals and two authorities. It has no name field. The name and symbol a wallet shows live in a second account, and which one depends on the token program that owns the mint.

- Metaplex metadata. Most tokens keep their name in an account owned by the Token Metadata program. Its address is derived from the mint, so you compute it and never search for it.
- Token-2022 in-mint metadata. A mint owned by the Token-2022 program can store name, symbol and uri inside its own data, in a `tokenMetadata` extension. That extension is only trustworthy when the `metadataPointer` extension names the mint itself. A pointer to another account means the data lives in that account.

Both are ordinary accounts, so `getMultipleAccounts` reads them on any endpoint. A directory built this way needs no indexer: take the mints you already have, compute addresses, read once, decode bytes.

## Deriving the metadata address

The metadata address is a program derived address under the Token Metadata program, built from three seeds in order: the text `metadata`, the program id as 32 bytes, and the mint as 32 bytes. The derivation is a local hash, so fifty mints cost no calls.

The script reads each metadata address and its mint in the same `getMultipleAccounts` call. The mint is there for its owner field: a mint owned by Token-2022 may carry its name inside itself. Two keys per token means 50 mints fill the 100 pubkeys a call can carry below Pro. A call of 300 pubkeys is Pro's.

[Account reads](https://carbium.sh/docs#rpc) cost 10 cells per pubkey, so a full call is 1000 cells, or 1001 over a 4 KiB body. A rate class [absorbs bursts](https://carbium.sh/docs#limits) up to 1,024 cells, which is why the cap sits at 100. The call asks for confirmed commitment and base64 data.

## Decoding name and symbol

A Metaplex metadata account starts with fixed fields, then strings. Each string is a 4-byte little-endian length followed by that many bytes.

| Offset | Field | Size |
|---|---|---|
| 0 | key | 1 |
| 1 | update authority | 32 |
| 33 | mint | 32 |
| 65 | name length | 4 |
| 69 | name bytes | the length just read |
| after name | symbol length, then symbol bytes | 4 plus the length |
| after symbol | uri length, then uri bytes | 4 plus the length |

The program pads the stored name with NUL bytes up to 32 characters and the symbol up to 10, and the length prefix counts that padding. A name such as `USD Coin` therefore arrives with a long tail of invisible characters. Strip trailing NULs and whitespace before anything is indexed, or exact matches fail.

A Token-2022 mint is laid out differently. The base mint takes 82 bytes, the account is padded to 165, and byte 165 holds the account type. Extensions follow from byte 166, each as a 2-byte type, a 2-byte length and a value. Type 18 is `metadataPointer`: an authority, then the address that holds the metadata. Type 19 is `tokenMetadata`: update authority, mint, then name, symbol and uri in the same string form. The script accepts type 19 only when the pointer address equals the mint.

## The Meilisearch document

One document per mint is enough. The script prints each as one JSON line.

| Field | Role in the index |
|---|---|
| `id` | Primary key, the mint address |
| `name` | Searchable text |
| `symbol` | Searchable text |
| `source` | Filterable: `metaplex`, `token-2022` or `none` |

A mint address works as a Meilisearch document id, since ids take letters, digits, hyphens and the `_` character, and base58 stays inside that set. Set `searchableAttributes` to `symbol` then `name`: earlier attributes rank higher, so a search for `jup` finds the symbol before any name that contains those letters. Set `filterableAttributes` to `source` so a front end can hide mints with no name.

Send the printed lines as one JSON array to `POST /indexes/tokens/documents`. A document with an existing id replaces the old one, so a rerun refreshes the directory. Default typo tolerance already finds `Jupitr`.

## The directory script

Use Node 24, which strips the types on load, and `npm install @solana/kit@8.6.0`. Pass mints as arguments, up to 50. The script needs `CARBIUM_KEY` and exits with a message when it is unset. `CARBIUM_RPC_URL` is optional. It only reads: no signing and no sending.

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

```ts
// I0055 · Meilisearch token name directory
// https://carbium.sh/library/integrate/meilisearch-token-name-directory
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

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

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY.");
  process.exit(1);
}
const mints = process.argv.slice(2, 52); // 50 mints = 100 pubkeys, the most one call can carry below Pro
if (mints.length === 0) {
  console.error("Usage: node main.ts <mint> [<mint>...]");
  process.exit(1);
}
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const METAPLEX = address("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
const enc = getAddressEncoder();
const metadataOf = async (mint: string) =>
  (await getProgramDerivedAddress({ programAddress: METAPLEX, seeds: ["metadata", enc.encode(METAPLEX), enc.encode(address(mint))] }))[0];

// a string is a u32 little-endian length, then that many bytes, padded with NULs
const str = (b: Buffer, at: number) => {
  const end = at + 4 + b.readUInt32LE(at);
  return [b.subarray(at + 4, end).toString("utf8").replace(/\0+$/, "").trim(), end] as const;
};
const pair = (b: Buffer, at: number) => {
  const [name, next] = str(b, at);
  return { name, symbol: str(b, next)[0] };
};
// Token-2022 mint: extensions start at byte 166, each is type u16, length u16, value
const inMint = (b: Buffer, mint: string) => {
  const ext = new Map<number, number>();
  for (let at = 166; at + 4 <= b.length; at += 4 + b.readUInt16LE(at + 2)) ext.set(b.readUInt16LE(at), at + 4);
  const pointer = ext.get(18); // metadataPointer: authority, then the address holding the metadata
  const meta = ext.get(19); // tokenMetadata: update authority, mint, name, symbol, uri
  if (pointer === undefined || meta === undefined) return null;
  if (getAddressDecoder().decode(b.subarray(pointer + 32, pointer + 64)) !== mint) return null;
  return pair(b, meta + 64);
};
const bytes = (a: { data: readonly [string, string] }) => Buffer.from(a.data[0], "base64");

try {
  const pdas = await Promise.all(mints.map(metadataOf));
  const { value } = await rpc
    .getMultipleAccounts([...pdas, ...mints.map(address)], { commitment: "confirmed", encoding: "base64" })
    .send();
  mints.forEach((mint, i) => {
    const meta = value[i];
    const mintAccount = value[mints.length + i];
    let doc = { id: mint, name: "", symbol: "", source: "none" };
    try {
      if (meta && meta.owner === METAPLEX) doc = { id: mint, ...pair(bytes(meta), 65), source: "metaplex" };
      else if (mintAccount && mintAccount.owner === TOKEN_2022) {
        const t = inMint(bytes(mintAccount), mint);
        if (t) doc = { id: mint, ...t, source: "token-2022" };
      }
    } catch (e) {
      console.log(`failed ${mint}: ${e instanceof Error ? e.message : String(e)}`);
    }
    console.log(JSON.stringify(doc));
  });
} catch (e) {
  console.log(`failed call: ${e instanceof Error ? e.message : String(e)}`);
}
```

Each output line is a document. A line with `source` set to `none` has an empty name and symbol. A line starting `failed` means one account could not be decoded and the rest still print.

## Where it ends

- A mint with no metadata account has no name anywhere on chain. Many small tokens never created one, and they print as `none`.
- The script skips a Token-2022 mint whose pointer names another account. Reading that account is one more lookup, and the script leaves it out.
- A name is a claim by whoever created the token, and anyone can call a token `USD Coin`. Treat the mint as the identity and show it next to the name. For a known list of real mints, match on the address. [Copycat token name matcher](https://carbium.sh/library/si/copycat-token-name-matcher) covers the lookalike case.
- Names change. A mint whose update authority is still live can be renamed at any time, so the directory is a snapshot. Rerun it on a schedule and let the same ids replace the old documents.
- Several tokens share one name and symbol, so a search returns more than one hit. The mint tells them apart.
- The script reads on-chain text only. The `uri` points to off-chain JSON, with the image and description, which the script does not fetch.
- More than 50 mints need a loop. Each full call is 1000 cells of a 1,024-cell class, so pause between calls.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Names print with a long tail of blank characters, or an exact search for a name finds nothing. | The trailing NUL padding was kept. Strip trailing NUL bytes and whitespace after decoding each string, as the script does, and reindex. |
| A `failed` line appears with a RangeError for one mint. | The data was shorter than the layout needs. A metadata address can hold lamports sent by a stranger and still belong to the system program, with empty data. Check that the account owner is the Token Metadata program before decoding, as the script does. |
| Every Token-2022 mint prints `none`. | Its `metadataPointer` names another account, or the mint has no pointer at all. Decode type 18 and read the address it holds. The name is in that account. |
| The call answers 429. | The call went over its account-read rate and got a retry-after hint. Wait that long, then send again. For long lists, pause between 50-mint calls so the cells refill. |
| The call answers 401. | Carbium does not recognise the key. Attach the whole key in the `x-api-key` header. |

## Questions

### Do I need a special token API to get names from mints?

No. The name sits in an ordinary account. Derive its address from the mint, read it with `getMultipleAccounts` and decode the bytes, as the script does.

### Why does the script read the mint as well as the metadata account?

The mint's owner says whether it belongs to Token-2022, and only that program keeps a name inside the mint. A mint with a Metaplex account is already answered by the first read, and the extra key costs 10 cells.

### How many mints fit in one call?

50 mints, because each takes two pubkeys and a call below Pro carries 100. Pro takes up to 300 pubkeys in a call.

### Can I decode Token-2022 metadata in more detail?

Yes. The `tokenMetadata` extension also holds uri and extra key-value pairs after the symbol. [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup) walks the whole extension.

## Related

- [Token-2022 metadata lookup](https://carbium.sh/library/howsolana/token-2022-metadata-lookup) (How to use Solana, HS0013)
- [Copycat token name matcher](https://carbium.sh/library/si/copycat-token-name-matcher) (AI and blockchain, SI0037)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
