Find a .sol domain in a wallet

Hi everyone ! i’m currently building a dApp, with react.js ; i can connect an adress but i want to look into the adress connected to get all the SNS and print them, did anyone knows how to do that ? Thank you so much and have a nice day :slight_smile:

Hey @lucasbriandbr !

You can find the RPC request that does just this here GitHub - Bonfida/solana-name-service-guide: Small guide to the Solana name service

This will return you the public keys of the domains owned by the user, to obtain the human readable names you will have to perform a reverse look up with this GitHub - Bonfida/solana-name-service-guide: Small guide to the Solana name service

For the reverse look up you could actually go one step further and do it in batch to optimize RPC requests, I think it would something like this:

export async function performReverseLookupBatch(
  connection: Connection,
  nameAccounts: PublicKey[]
): Promise<(string | undefined)[]> {
  let reverseLookupAccounts: PublicKey[] = [];
  for (let nameAccount of nameAccounts) {
    const hashedReverseLookup = await getHashedName(nameAccount.toBase58());
    const reverseLookupAccount = await getNameAccountKey(
      hashedReverseLookup,
      REVERSE_LOOKUP_CLASS
    );
    reverseLookupAccounts.push(reverseLookupAccount);
  }

  let names = await NameRegistryState.retrieveBatch(
    connection,
    reverseLookupAccounts
  );

  return names.map((name) => {
    if (name === undefined || name.data === undefined) {
      return undefined;
    }
    let nameLength = new BN(name.data.slice(0, 4), 'le').toNumber();
    return name.data.slice(4, 4 + nameLength).toString();
  });
}