Using the Bonfida APIs, you can do a reverse lookup as follows:

import { performReverseLookup } from "@bonfida/spl-name-service";

// Public key of bonfida.sol
const domainKey = new PublicKey("Crf8hzfthWGbGbLTVCiqRqV5MVnbpHB1L9KQMd6gsinb");

const domainName = await performReverseLookup(connection, domainKey); // bonfida

In practice, this is returning an "invalid account name" error for user public keys. Is there an intermediary step to convert from a user's public key to their naming account public key first?

3 Answers 3


There's an alternative way to get all the domain names owned by a public key:

import { Connection, PublicKey } from "@solana/web3.js";
import { NAME_PROGRAM_ID } from "@bonfida/spl-name-service";

export async function findOwnedNameAccountsForUser(
  connection: Connection,
  userAccount: PublicKey
): Promise<PublicKey[]> {
  const filters = [
      memcmp: {
        offset: 32,
        bytes: userAccount.toBase58(),
  const accounts = await connection.getProgramAccounts(NAME_PROGRAM_ID, {
  return accounts.map((a) => a.publicKey);
  • 1
    I used getAllDomains from Bonfida but this is much better, ty!
    – 0xMertimus
    Jul 14, 2022 at 17:54

Was able to figure it out - TL;DR you need to add a call for getAllDomains first.


const pubKey = new PublicKey('some-public-key');
const domains = await getAllDomains(connection, pubKey);
const reqs = domains.map((x) => performReverseLookup(connection, x));
const resolvedNames = await Promise.all(reqs);

On solscan.io you can find Domains based on the Public Key provided.

See this example;


  • I'm curious on how to do it via the API :)
    – 0xMertimus
    Jul 14, 2022 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.