How to read Token-2022 metadata in JavaScript

Token-2022 mints can store their name, symbol and uri inside the mint account itself, in the TokenMetadata extension. There is no separate metadata account to find. Here is the byte layout, a decoder in plain JavaScript, and what to do when a mint does not have it.

Where the metadata lives

A Token-2022 mint account is laid out like this:

BytesWhat
0 to 81The classic mint: mint authority, supply, decimals, freeze authority. Same as SPL Token.
82 to 164Zero padding, so a mint is never the size of a token account (165 bytes).
165Account type: 1 for a mint.
166 onwardExtensions, one after another: type (u16), length (u16), then that many bytes.

TokenMetadata is extension type 19. Its value is Borsh-encoded:

  1. updateAuthority: 32 bytes, all zeros if none (the metadata can no longer change)
  2. mint: 32 bytes
  3. name, symbol, uri: each a u32 length followed by UTF-8 bytes
  4. additionalMetadata: a u32 count, then that many key/value string pairs

All integers are little-endian. The extension is variable-length and is usually the last one, because it is added or resized after the others.

Working code, zero dependencies

Save as token-2022-metadata.mjs and run node token-2022-metadata.mjs <mint>. Uses the free public mainnet RPC unless you set SOLANA_RPC_URL.

// token-2022-metadata.mjs: node token-2022-metadata.mjs <mint>. Node 20+, no dependencies
const RPC = process.env.SOLANA_RPC_URL || "https://api.mainnet-beta.solana.com";
const mint = process.argv[2] ?? "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo"; // PYUSD
const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";

const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
function base58(bytes) {
  let n = BigInt("0x" + (Buffer.from(bytes).toString("hex") || "0")), s = "";
  while (n > 0n) { s = ALPHABET[Number(n % 58n)] + s; n /= 58n; }
  for (const b of bytes) { if (b !== 0) break; s = "1" + s; }
  return s;
}

const res = await fetch(RPC, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "getAccountInfo", params: [mint, { encoding: "base64" }] }),
});
const { result } = await res.json();
if (result.value?.owner !== TOKEN_2022) throw new Error("not a Token-2022 mint");
const data = Buffer.from(result.value.data[0], "base64");

// A Token-2022 mint: 82-byte classic layout, padding to 165, one account-type byte (1 = mint), then extensions as
// type (u16) | length (u16) | value. TokenMetadata is type 19.
let at = 166, meta = null;
while (at + 4 <= data.length) {
  const type = data.readUInt16LE(at), len = data.readUInt16LE(at + 2);
  if (type === 0) break;
  if (type === 19) meta = data.subarray(at + 4, at + 4 + len);
  at += 4 + len;
}
if (!meta) throw new Error("this mint has no TokenMetadata extension (look for a Metaplex account instead)");

let p = 0;
const key = () => { const k = meta.subarray(p, p + 32); p += 32; return k.every((b) => b === 0) ? null : base58(k); };
const str = () => { const n = meta.readUInt32LE(p); const s = meta.toString("utf8", p + 4, p + 4 + n); p += 4 + n; return s; };
const updateAuthority = key(), metadataMint = key();
const name = str(), symbol = str(), uri = str();
const additional = [];
const count = meta.readUInt32LE(p); p += 4;
for (let i = 0; i < count; i++) additional.push([str(), str()]);

console.log({ name, symbol, uri, updateAuthority, mint: metadataMint, additional });

PayPal USD, and a pump.fun coin launched on Token-2022:

$ node token-2022-metadata.mjs
{
  name: 'PayPal USD',
  symbol: 'PYUSD',
  uri: 'https://token-metadata.paxos.com/pyusd_metadata/prod/solana/pyusd_metadata.json',
  updateAuthority: '2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk',
  mint: '2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo',
  additional: []
}

$ node token-2022-metadata.mjs DxYWLXgKJpQmfhTG7ikK6oX6oDhxMhN5wCs5BJekpump
{
  name: 'Deed',
  symbol: 'DEED',
  uri: 'https://ipfs.io/ipfs/bafkreidtdeaghcf42hbzmjiqzfitnpbt7q3xsjecccijsm4tp65kzg4t44',
  updateAuthority: null,
  mint: 'DxYWLXgKJpQmfhTG7ikK6oX6oDhxMhN5wCs5BJekpump',
  additional: []
}

The pump.fun coin has no update authority: its name and symbol are fixed for good. PYUSD's issuer can still change them.

Three cases the decoder has to handle

  1. A classic SPL token (USDC, BONK, older pump.fun coins). It is owned by the old Token program and has no extensions at all; its name lives in a separate Metaplex metadata account at a program-derived address. The script above refuses it with "not a Token-2022 mint".
  2. A Token-2022 mint without the extension. Some Token-2022 mints still use Metaplex. Look for the metadataPointer extension (type 18): it names the account that holds the metadata.
  3. A pointer to another account. If metadataPointer points somewhere other than the mint, the metadata is in that account, stored in the same TokenMetadata format inside an entry that starts with an 8-byte discriminator and a 4-byte length.

Shortcut: jsonParsed

If all you need is a quick look, getAccountInfo with encoding: "jsonParsed" returns the extensions decoded, TokenMetadata included, under parsed.info.extensions. Decoding the bytes yourself is what you need when the data reaches you as base64: from accountSubscribe, Geyser, getMultipleAccounts in base64 or a cache.

Both formats in one call

solana-token-meta handles Token-2022 and Metaplex together: it derives the Metaplex address locally, reads the mint and that account in one getMultipleAccounts call, decodes every extension, and tells you which source the name came from:

npm install github:blixvip/solana-token-meta
import { getTokenMeta } from "solana-token-meta";

const m = await getTokenMeta("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo"); // PYUSD
console.log(m.program, m.metadata);
console.log(Object.keys(m.extensions));
console.log(m.transferFee);
token-2022 {
  source: 'token-2022',
  name: 'PayPal USD',
  symbol: 'PYUSD',
  uri: 'https://token-metadata.paxos.com/pyusd_metadata/prod/solana/pyusd_metadata.json',
  updateAuthority: '2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk',
  isMutable: true,
  additionalMetadata: []
}
[
  'mintCloseAuthority',
  'permanentDelegate',
  'transferFeeConfig',
  'confidentialTransferMint',
  'confidentialTransferFeeConfig',
  'transferHook',
  'metadataPointer',
  'tokenMetadata'
]
{ basisPoints: 0, maximumFee: '0', sinceEpoch: '605' }

Pass a classic mint like USDC and metadata.source is "metaplex" instead, with the same fields. Already have the base64 accounts? decodeMint(data, owner) and buildTokenMeta() work offline.

Limits to know

Want it done for you?

This is the small, open version. Blix is the AI-powered Solana memecoin terminal it comes from: every pump.fun launch live, AI coin ratings, narratives, wallet and X tracking, and one-click trading with 0% fees. There is a public API and an MCP server too.

Start trading at blixvip.comJoin the Discord

Help build it

solana-token-meta is open source and takes pull requests. There are good first issues with step-by-step instructions, and setup is git clone and npm test.

More guides

How to check if a Solana token's mint authority is revokedsolana-token-metaHow to see the priority fee a Solana transaction paidsolana-tx-parseHow to calculate a Solana token's top 10 holders percentagesol-holdersHow to detect new pump.fun tokens in real timepump-stream