0

Unfortunately this answer didn't help me to find what I want.

Imagine I have an account address (i.e. user wallet, PDA, etc) and an NFT's token address (aka the SPL token mint), how can I figure out that whether the account holds the given token address?

3
  • Can you clarify what you mean by account address and token address? Should the account address the owner of the NFT? And the token address the NFT's mint address?
    – nickfrosty
    Jan 19 at 14:27
  • @nickfrosty Yes, by token address I mean mint address (as far as I know they are equivalent) and by account I mean the entity that we want to check whether is the owner of NFT or not. Jan 19 at 14:33
  • they are equivalent, but I wanted to make sure I fully understood your question before answering :)
    – nickfrosty
    Jan 19 at 14:45

1 Answer 1

1

Understanding that Solana NFTs are just SPL token mints with a supply of exactly 1 and NFT's ownership is actually held by the "associated token account" (ata for short). So you can derive the correct ata and check the owner of it in order to verify a person/wallet/account owns a specific NFT.

Example

Terminology for clarification:

  • nft_owner is the address of the account that should own the NFTs (i.e. "my wallet address owns NFT X")
  • the mint is the address of the SPL token mint that represents the NFT
  • the ata is the associated token account address derived from the mint and nft_owner address

You should be able to do the following (either in Rust or JS) to determine if a specific account actually owns an NFT:

  • derive the associated token account (ata) from the NFT's mint and the nft_owner's address
  • if the ata exists, then verify if the ata's owner matches the nft_owner address

Note: ata's can technically be transferred to a different owner and not reset the owner field on the account. So the second step above is a very import one to verify the actual correct NFT owner

Also note: that there is likely some extra validation of input addresses you should be doing, especially if you are building a rust program to handle this (i.e. "is this actually the correct NFT you want to check for?")

2
  • Thanks for clarifying the terminology, would you please provide an example that verifies this ownership? My question is that how can I implement this verification in anchor. I couldn't find documentations helpful in this case. Jan 19 at 14:58
  • I would if I knew anchor, sorry :/
    – nickfrosty
    Jan 23 at 20:39

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.