4

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

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, {
    filters,
  });
  return accounts.map((a) => a.publicKey);
}
1
  • 1
    I used getAllDomains from Bonfida but this is much better, ty!
    – 0xMertimus
    Jul 14, 2022 at 17:54
1

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

So,

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);
-1

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

See this example;

https://solscan.io/account/GaxVqiQyJKQDRu6H4pfy9V6Xq19pHGr6HQKDQDv911Y4#domains

1
  • 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.