---
id: BI0036
title: ".sol domain resolver"
url: https://carbium.sh/library/blockchainideas/sol-domain-resolver
collection: Blockchain ideas
category: Consumer and social
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# .sol domain resolver

You get the primary .sol name of any wallet, checked against who owns it now. Two batched account reads return one verdict per wallet, matched, stale or none, ready for a profile page or a feed.

## Three accounts behind one name

A wallet's .sol name sits in three accounts, and each one is found from the one before. The primary record is a program-derived account under the primary-domain program, seeded with `favourite_domain` and the wallet address. Its data is a one-byte tag and the address of a name account. The name account opens with a 96-byte header holding its parent, owner and class addresses: the parent is the .sol root and the owner is the wallet that holds the name. The reverse record's address derives from the name account's address, so the primary record is the first read, because it is the only place that names the account.

The reverse record carries the readable text. After its own 96-byte header come a four-byte little-endian length and the name without the `.sol` suffix, which the code adds when it prints.

| Account | Found from | What the code reads |
|---|---|---|
| Primary record | `favourite_domain` and the wallet address, under the primary-domain program | The name account's address |
| Name account | The address in the primary record | The parent and owner fields |
| Reverse record | A SHA-256 hash of `SPL Name Service` plus the name account's address in base58, under the name program with the reverse-lookup class | The name text |

## The ownership check

A primary record is a note the wallet wrote once. If the name is sold afterwards the note stays, so the record alone proves nothing. The check reads the name account and compares its owner field with the wallet and its parent with the .sol root. The reverse record has to decode to text as well, since a display name needs a name to show.

| Verdict | When | What a UI shows |
|---|---|---|
| matched | A primary record exists, the name account's owner is the wallet, its parent is the .sol root and the reverse record decodes | The name, with the wallet as its proof |
| stale | A primary record exists and one of those checks fails | The short address, because the name is a leftover |
| none | The wallet has no primary record account | The short address and a prompt to set a primary domain |

A fourth word, `unread`, is printed for a wallet whose read failed. Show the short address for it and read again later.

## The build

One file on `@solana/kit` and what Node 24 ships. It only reads: no key pair, nothing sent.

1. With no argument, call getSignaturesForAddress on the primary-domain program for its 8 newest signatures. Fetch each successful one with getTransaction at `maxSupportedTransactionVersion: 1` and take the first account key, the fee payer. A signature whose transaction the ledger no longer holds answers null and is skipped.
2. Add one fixed address that has no record, the system program's, so every run prints a `none` row. Wallets given on the command line replace both steps.
3. Derive each wallet's primary record address and read them all with getMultipleAccounts, 100 addresses a call.
4. For each record found, take the name account address, derive its reverse record and read the name account and the reverse record together in a second round.
5. Print wallet, name and verdict, one row per wallet.

`main.ts` (run: `CARBIUM_KEY=<YOUR_KEY> node main.ts [<wallet> ...]`)

```ts
// BI0036 · .sol domain resolver
// https://carbium.sh/library/blockchainideas/sol-domain-resolver
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, getAddressEncoder, getProgramDerivedAddress, isSolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, type Address } from "@solana/kit";
import { createHash } from "node:crypto";

const key = process.env.CARBIUM_KEY ?? "";
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const PRIMARY_PROGRAM = address("85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29");
const NAME_PROGRAM = address("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX");
const REVERSE_CLASS = address("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z");
const SOL_ROOT = address("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx");
const NO_RECORD = address("11111111111111111111111111111111"); // the system program never signs, so it has no record
const enc = getAddressEncoder();
const dec = getAddressDecoder();
type Acct = Buffer | null | undefined; // null: no such account, undefined: the read failed
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
const errText = (e: unknown) => (e instanceof Error ? e.message : String(e));
const pda = async (programAddress: Address, seeds: Parameters<typeof getProgramDerivedAddress>[0]["seeds"]) =>
  (await getProgramDerivedAddress({ programAddress, seeds }))[0];

// One getMultipleAccounts call; a 429 is retried once after the seconds its retry-after hint names.
async function readChunk(chunk: Address[]): Promise<Acct[]> {
  for (let attempt = 0; ; attempt++) {
    try {
      const { value } = await rpc.getMultipleAccounts(chunk, { encoding: "base64", commitment: "confirmed" }).send();
      return value.map((a) => (a ? Buffer.from(a.data[0], "base64") : null));
    } catch (e) {
      const hint = isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) && e.context.statusCode === 429 ? Number(e.context.headers.get("retry-after")) : 0;
      if (attempt > 0 || !(hint > 0)) {
        console.log(`read of ${chunk.length} accounts failed: ${errText(e)}`);
        return chunk.map(() => undefined);
      }
      await sleep(hint * 1000);
    }
  }
}
async function readAll(addrs: Address[]): Promise<Acct[]> {
  const out: Acct[] = [];
  for (let i = 0; i < addrs.length; i += 100) out.push(...(await readChunk(addrs.slice(i, i + 100))));
  return out;
}

// Fee payers of the primary-domain program's newest successful transactions.
async function feePayers(): Promise<Address[]> {
  const sigs = await rpc.getSignaturesForAddress(PRIMARY_PROGRAM, { limit: 8, commitment: "confirmed" }).send();
  const txs = await Promise.allSettled(sigs.filter((s) => s.err === null).map((s) =>
    rpc.getTransaction(s.signature, { maxSupportedTransactionVersion: 1, encoding: "json", commitment: "confirmed" }).send()));
  const payers = new Set<Address>();
  for (const t of txs) {
    if (t.status === "rejected") { console.log(`getTransaction failed: ${errText(t.reason)}`); continue; }
    const keys = (t.value?.transaction.message as unknown as { accountKeys?: Address[] } | undefined)?.accountKeys; // t.value is null past the ledger floor
    if (keys?.[0]) payers.add(keys[0]);
  }
  return [...payers];
}

async function main(): Promise<void> {
  const found = process.argv.length > 2 ? process.argv.slice(2).map((w) => address(w))
    : [...(await feePayers().catch((e) => { console.log(`discovery failed: ${errText(e)}`); return []; })), NO_RECORD];
  const wallets = [...new Set(found)];
  // Round 1: each wallet's primary record holds a tag byte and the name account's address.
  const records = await readAll(await Promise.all(wallets.map((w) => pda(PRIMARY_PROGRAM, ["favourite_domain", enc.encode(w)]))));
  const linked: { w: Address; name: Address }[] = [];
  wallets.forEach((w, i) => { const r = records[i]; if (r && r.length >= 33) linked.push({ w, name: dec.decode(r.subarray(1, 33)) }); });
  // Round 2: the name account and its reverse record, which derives from the name account's address.
  const reverse = await Promise.all(linked.map((l) => pda(NAME_PROGRAM, [createHash("sha256").update("SPL Name Service" + l.name).digest(), enc.encode(REVERSE_CLASS), new Uint8Array(32)])));
  const second = await readAll(linked.flatMap((l, i) => [l.name, reverse[i]]));
  wallets.forEach((w, i) => {
    const rec = records[i];
    let name = "-";
    let verdict = rec === undefined ? "unread" : rec === null ? "none" : "stale";
    const k = linked.findIndex((l) => l.w === w);
    if (k >= 0) {
      const acct = second[2 * k], rev = second[2 * k + 1];
      if (rev && rev.length > 100) name = rev.subarray(100, 100 + rev.readUInt32LE(96)).toString("utf8") + ".sol";
      if (acct && acct.length >= 96 && name !== "-" && dec.decode(acct.subarray(0, 32)) === SOL_ROOT && dec.decode(acct.subarray(32, 64)) === w) verdict = "matched";
      else if (acct === undefined || rev === undefined) verdict = "unread";
    }
    console.log(`${w} ${name} ${verdict}`);
  });
}
main().catch((e) => console.error("failed:", errText(e)));
```

Every call passes commitment `confirmed`. A run prints `matched` for a fee payer whose primary name is still theirs, which includes a wallet that set its record minutes ago. It prints `none` for a payer with no record and for the fixed address, and `stale` for a payer whose name was sold, wrapped or is a subdomain. The program's newest traffic decides which wallets appear, so the mix changes between runs.

## Batching and cost

A wallet with no record costs 10 cells, the one pubkey in the first round. A wallet with a primary record costs 30: 10 in the first round and 20 for its name account and reverse record in the second. [getMultipleAccounts](https://carbium.sh/docs/rpc) charges 10 cells per pubkey, so 100 pubkeys cost 1000 cells (1001 over a 4 KiB body). It takes up to 300 pubkeys on Pro, and below Pro the 1024-cell burst caps a call at 100. The file sends at most 100 a call and splits both the wallet list and the second read.

| Plan | Account reads | Cells refilled per second | Refill time for one 1000-cell call |
|---|---|---|---|
| Free ($0) | 0.5 req/s | 5 | about 200 s |
| Dev ($20) | 15 req/s | 150 | about 6.7 s |
| Business ($250) | 50 req/s | 500 | about 2 s |
| Pro ($500) | 400 req/s | 4,000 | about 0.25 s |

Account reads refill at 10 cells times the plan's req/s. Two calls of about 1000 cells back to back draw on one burst, and a [call that cannot refill within 1 s](https://carbium.sh/docs/limits) answers 429 with a retry-after hint. On Dev, Business and Free the second 1000-cell call can hit that. The file waits the seconds the hint names and tries once more, and a failed retry prints `unread` for those wallets. A hint of minutes on Free means a list that long belongs on a paid plan or in a cache.

Dedupe the addresses first: a feed repeats its authors, and each repeat spends 10 cells, or 30 for a wallet with a primary record. The discovery step is for the demo. It costs 50 cells for the signature page and 50 for each transaction, 450 at most, and a real app that already holds its wallets skips it.

## Caching

Keep one verdict per wallet in your own table, in `node:sqlite` for a start, with the time of the read. A `matched` row stays true until the name changes hands or the wallet sets another primary. A `none` row can flip the minute a user sets a record, so give `none` the shorter life. Read a wallet again at the moments that matter: sign-in, opening a profile and before a transfer screen shows a name. Pair the verdicts with the rows from [Wallet social feed](https://carbium.sh/library/blockchainideas/wallet-social-feed) and the profile pages in [Wallet profiles and feeds](https://carbium.sh/library/usecase/wallet-profiles-and-feeds), and read a whole page of authors in one batch.

## Where it ends

- A subdomain always reads `stale`: its reverse record derives under the parent domain, and its parent is not the .sol root.
- A domain wrapped as an NFT has the tokenizer's record account as its owner, so the NFT's holder reads `stale` until the name is unwrapped.
- A primary record names one name. A wallet that owns twenty names and never set a primary reads `none`, and listing the others takes an index you build.
- A name under a root other than .sol has another parent and reads `stale`.
- The demo's discovery step sees the 30-day address index at most, and an empty page past that is the index's age limit.
- A verdict reports who owns the name at the moment of the read. Proof that the person at the screen controls the wallet is a separate step, a signed sign-in message.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| getMultipleAccounts answers 429 on the second call. | The code waits the seconds in the retry-after hint and tries once more. If the retry fails too, the affected wallets print `unread`. Check your plan's refill in the table above, and remember that every key on the account draws on the same budget. |
| getTransaction answers -32015. | The transaction is version 1 and the call left maxSupportedTransactionVersion out or set it to 0. The code sends 1 on every call, so keep it if you copy the call elsewhere. |
| getTransaction returns null for a signature the page listed. | Signature pages from the address index reach below the validator's ledger floor, so an older signature can list and still have no transaction. The code skips null. Prove your own code on the newest signatures. |
| A user says they own the name, and the wallet prints `stale`. | The name was sold, wrapped as an NFT or is a subdomain. Show the short address, and ask the user to unwrap the name or set a primary domain again. |
| Only the fixed address prints a row. | The newest signatures were all failed transactions or the page was empty, or every getTransaction call failed and the run printed why. Run again, or pass wallets on the command line. |

## Questions

### Does every wallet have a .sol name?

No. Most wallets own none, and a wallet that owns several names still needs a primary record to say which one is its display name. Without one, the verdict is `none`.

### Why does the code read the primary record first?

The reverse record's address derives from the name account's address, and the wallet's primary record is the only place that names that account. The wallet address alone does not give you the reverse record.

### Can I go the other way, from a name to a wallet?

Yes. Hash the name with the same prefix, derive the name account under the .sol root and read its owner field. That is a different job from this one, and it needs one read.

### How many wallets fit in one call?

100 below Pro, at 1000 cells a call. Pro takes up to 300 pubkeys a call. The second round holds two accounts per wallet, so it splits at 50 wallets per call.

## Related

- [Wallet profiles and feeds](https://carbium.sh/library/usecase/wallet-profiles-and-feeds) (Use cases, UC0018)
- [Wallet social feed](https://carbium.sh/library/blockchainideas/wallet-social-feed) (Blockchain ideas, BI0007)
- [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)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
