6

I'm current using the following method to get an NFT's owner wallet. I'd like to batch this to do multiple requests at once. Since this requires two function calls, however, it requires two batch requests. Before going down this path, I wanted to confirm there wasn't a better way of getting an NFT's owner wallet, ideally with only one call to the RPC.

        const token = await this.connection.getTokenLargestAccounts(nftPubKey);
        const holder = token.value[0]?.address;

        if (!holder)
            return null;

        const acc = await this.connectionQuick.getParsedAccountInfo(holder);
        const data = acc?.value?.data as ParsedAccountData;

        if (!data)
            return null;

        const owner = data.parsed.info.owner as string;
        return owner;
1
  • if your question is answered, please mark this as answered. Thank you
    – vicyyn
    Jan 14, 2023 at 18:55

1 Answer 1

3

what you can do is create an array of mints and loop through them to get the owners.

Also, make sure you pause some time between each call (sleep()). Public endpoints have a limited number of calls per second.

const connection = new Connection("https://api.mainnet-beta.solana.com");
const mints =
[ 
  "9ARngHhVaCtH5JFieRdSS5Y8cdZk2TMF4tfGSWFB9iSK",
  "9ARngHhVaCtH5JFieRdSS5Y8cdZk2TMF4tfGSWFB9iSK"
];

for (const tokenMint of mints) {
  const largestAccounts = await connection.getTokenLargestAccounts(
    new PublicKey(tokenMint)
  );
  const largestAccountInfo = await connection.getParsedAccountInfo(
    largestAccounts.value[0].address
  );
  console.log(largestAccountInfo.value.data.parsed.info.owner);
  sleep(1000)
}

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.