---
id: HS0006
title: "Bulk NFT metadata reader"
url: https://carbium.sh/library/howsolana/bulk-nft-metadata-reader
collection: How to use Solana
category: NFT metadata from the chain
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Bulk NFT metadata reader

One TypeScript file takes a list of mint addresses, derives each metadata account offline, reads them 100 at a time, and prints one JSON line per mint with name, symbol, metadata URI, creators and collection. It only reads: no keypair, no signature.

## What lives on chain

An NFT on Solana is a mint account. Its name, symbol, creators and collection live in a second account, the metadata account, at an address anyone can compute from the mint. It is a program derived address built from three seeds: the word `metadata`, the Token Metadata program id and the mint. Computing it is local arithmetic that makes no network call.

That account also holds a `uri`. The image and the traits are behind it. The chain stores a link to a JSON file that the creator hosts, and by the Metaplex JSON standard that file has an `image` field and an `attributes` list of `trait_type` and `value` pairs. Rarity is stored nowhere. You compute it from the attributes of the whole collection.

A dashboard that wants mints, images and rarity ends up doing three things:

1. Derive the metadata address of every mint offline.
2. Read the metadata accounts from Carbium, 100 per call, and decode the `uri` and the other fields.
3. Fetch each `uri` and score the traits.

The file does the first two, which touch the chain. The third is one plain HTTP GET per `uri` to a host the creator chose, which makes it a separate job with its own limits.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips TypeScript types on its own. Pass one mint address or many as arguments.

`main.ts` (run: `node main.ts <mint-address> [more mint addresses]`)

```ts
// HS0006 · Bulk NFT metadata reader
// https://carbium.sh/library/howsolana/bulk-nft-metadata-reader
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { setTimeout as sleep } from "node:timers/promises";
import {
  address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder,
  getAddressEncoder, getBase64Encoder, getProgramDerivedAddress, isSolanaError,
  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,
} 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 mints = process.argv.slice(2).map((m) => address(m));
if (mints.length === 0) {
  console.error("Usage: node main.ts <mint-address> [more mint addresses]");
  process.exit(1);
}
const META = address("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const enc = getAddressEncoder();
const dec = getAddressDecoder();
const b64 = getBase64Encoder();
const utf8 = new TextDecoder();

// Offline: the metadata account is a PDA of ("metadata", program, mint).
const pdas = await Promise.all(mints.map(async (mint) => (await getProgramDerivedAddress({
  programAddress: META, seeds: ["metadata", enc.encode(META), enc.encode(mint)],
}))[0]));

function parse(bytes: Uint8Array) {
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
  let o = 1 + 32 + 32; // key, update authority, mint
  const str = () => {
    const n = view.getUint32(o, true);
    const s = utf8.decode(bytes.slice(o + 4, o + 4 + n)).replace(/\0+$/, "");
    o += 4 + n;
    return s;
  };
  const name = str(), symbol = str(), uri = str();
  const sellerFeeBasisPoints = view.getUint16(o, true);
  o += 2;
  const creators: string[] = [];
  if (bytes[o++] === 1) {
    const n = view.getUint32(o, true);
    o += 4;
    for (let i = 0; i < n; i++, o += 34) {
      if (bytes[o + 32] === 1) creators.push(dec.decode(bytes.slice(o, o + 32)));
    }
  }
  o += 1; // primary_sale_happened
  const mutable = bytes[o++] === 1;
  if (bytes[o++] === 1) o += 1; // edition_nonce
  if (bytes[o++] === 1) o += 1; // token_standard
  let collection: string | null = null;
  if (bytes[o++] === 1 && bytes[o] === 1) collection = dec.decode(bytes.slice(o + 1, o + 33));
  return { name, symbol, uri, sellerFeeBasisPoints, creators, collection, mutable };
}

async function withRetry<T>(call: () => Promise<T>): Promise<T> {
  try {
    return await call();
  } catch (e) {
    if (!isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) || e.context.statusCode !== 429) throw e;
    const seconds = Number(e.context.headers.get("retry-after")) || 1;
    console.error(`429: waiting ${seconds}s, then one more try`);
    await sleep(seconds * 1000);
    return await call();
  }
}

for (let i = 0; i < pdas.length; i += 100) {
  const { value } = await withRetry(() =>
    rpc.getMultipleAccounts(pdas.slice(i, i + 100), { commitment: "confirmed", encoding: "base64" }).send(),
  );
  value.forEach((account, j) => {
    const meta = account ? parse(new Uint8Array(b64.encode(account.data[0]))) : { metadata: null };
    console.log(JSON.stringify({ mint: mints[i + j], ...meta }));
  });
}
```

`getProgramDerivedAddress` builds each metadata address in your process, and `getMultipleAccounts` then reads up to 100 of them in one call, all at the same slot.

The read asks for `confirmed` commitment and `base64` encoding, so the account data arrives as a string the file turns into bytes. Metadata rarely changes, which makes `finalized` an equally good choice here.

Decoding is by hand because the metadata layout is fixed: a one-byte key, the update authority, the mint, then the name, symbol and uri as length-prefixed strings, a two-byte seller fee, the creators, two flags, and three optional fields that end with the collection. A few `DataView` reads cover it, which keeps `@solana/kit` the only dependency.

## Reading the output

Each mint gets one JSON line, in the order you passed them, so the output loads straight into a table or a database.

| Field | Meaning |
|---|---|
| mint | The mint address you passed. |
| name | The name with its padding removed. Older mints often pad the name to 32 bytes with zero bytes, and newer create instructions leave it unpadded. |
| symbol | The symbol, with any zero padding removed. The program allows 10 bytes. |
| uri | The link to the off-chain JSON with `image` and `attributes`. Up to 200 bytes. |
| sellerFeeBasisPoints | The creator royalty as an integer, 500 meaning 5%. |
| creators | The creators whose signature is verified on the account. |
| collection | The verified collection mint, or null. |
| mutable | True while the update authority can still change the metadata, the `uri` included. |
| metadata | Null when the mint has no Token Metadata account. |

Store the `uri` itself next to what you fetched from it, and check `mutable` before you cache that JSON. A mutable asset can have its `uri` changed or its JSON edited later, so a rarity table built last month can drift. An immutable one still depends on the host of the JSON, because the chain holds only the link.

> A mint with no Token Metadata account prints a line with `metadata: null`. Fungible tokens made with the same program decode the same way, so you can test the file on a fungible mint that has a Token Metadata account, such as USDC, before you point it at a collection.

## From the URI to rarity

For the third step, run an HTTP GET on each `uri` with a short timeout and a small concurrency, and keep `image` and `attributes` from the answer. The `image` field is often an `ipfs://` or `ar://` link. Rewrite it to an HTTP gateway you trust before you put it in a page.

Rarity comes from counting. For each `trait_type` and `value`, count how many mints in the set carry it and divide by the size of the set. A common score adds up 1 divided by that frequency over a mint's traits, so a rare value contributes more. The counts must cover the whole collection, because scores from a partial list change when the rest arrives.

A trait that a mint lacks is a value too. Count it as `none` for that `trait_type`, or the mints with fewer traits look rarer than they are.

## On Carbium

`getMultipleAccounts` charges [10 cells per pubkey](https://carbium.sh/docs#rpc) and takes up to 300 on Pro, but below Pro the burst caps a call at 100 pubkeys. A 100-pubkey body runs over 4 KiB, so each call costs 1001 cells. A collection of 1,000 mints is 10 calls and 10,010 cells. The file sends 100 so that a retry after a 429 repeats a small batch.

On a small plan, space the batches out with a sleep between them. Each plan has its own [rate ceilings](https://carbium.sh/docs#limits), and the sleep keeps a long collection under them.

Where the mint list comes from is your side of the job. A project's published mint list or your own index works. On chain, the usual route is the collection's verified creator address, which sits in the creators list of the mints, or its update authority: `getSignaturesForAddress` on that address lists the transactions that touched it, and each mint transaction names the new mint. That call costs 50 cells and reaches back 30 days, the age of Carbium's own address index, so it lists activity from that window only.

`-32601` means [method not found](https://carbium.sh/docs#errors): do not retry it. If you try `getTokenLargestAccounts` or `getProgramAccountsV2` to find mints or holders, Carbium answers `-32601`, because it does not serve them.

## Where it ends

The file stops at the `uri`. It does not read the off-chain JSON, so it prints no `image` and no traits, and it computes no rarity. Those come from plain HTTP GETs against hosts that are not Carbium and that you will want to rate-limit yourself.

It reads one kind of NFT: assets with a Token Metadata account. A mint that keeps its data some other way prints `metadata: null`, and the file cannot tell you why.

It does not discover mints. It reads the ones you pass in.

The output is a snapshot at `confirmed`. A creator who edits a mutable asset after your run changes what a later run prints, and the file keeps no history.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every line prints `metadata: null` for addresses you know are NFTs. | Check that you passed the mint address of each NFT. A wallet or a token account has no Token Metadata account at the derived address. A certified collection is itself an NFT mint with its own metadata account, so passing it prints that collection NFT's line and lists none of its members. |
| `name` or `uri` ends with odd characters in your own decoder. | Many mints, older ones especially, pad these strings with zero bytes. The file strips them. If you decode elsewhere, trim the trailing zero bytes. |
| HTTP 429 with a retry-after hint. | The file waits that many seconds and retries once. If it repeats, add a sleep between batches or move to a plan with more account reads per second. |
| Error -32601 method not found. | Fix the method name or use another method. A method Carbium does not serve keeps answering -32601, so do not retry it. |
| The run throws on an argument before any request goes out. | `address()` rejects a string that is not a valid base58 address of 32 bytes. Check the argument for a typo or a stray character. |

## Questions

### Which explorer has a bulk API for mints, images and traits?

You do not need one. The mint, name, collection and `uri` are on chain, and `getMultipleAccounts` reads 100 metadata accounts per call. The image and the traits come from the JSON at each `uri`.

### Do I need a private key to read NFT metadata?

No. The file only reads accounts. The Carbium key identifies your account to the RPC.

### Why 100 mints per call when Pro allows 300?

The cost is 10 cells per pubkey either way. A batch of 100 keeps each retry small after a 429. On Pro you can raise it toward 300.

### Does an NFT's metadata account change?

Its name, symbol and `uri` change only while `mutable` is true, and only by the update authority. Run the file again to refresh it.

### Does deriving the metadata address cost a request?

No. `getProgramDerivedAddress` hashes the seeds in your own process, so no request leaves it for that step.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
