How is it possible to view NFTs with the Solana RPC API? Have been looking at the documentation but haven't been able to figure out how to do it.
1 Answer
NFT is not something native to Solana. It is built on the top of Solana. To Solana, it's just a SPL token with supply = 1 and decimal = 0. So you can use a regular getProgramAccounts or getParsedProgramAccounts APIs to retrieve the token account of the NFT. Here is QuickNode's guide on how to do so: How to Get Tokens Held by a Wallet
If you want to retrieve the metadata of an NFT, the easiest way is to use the APIs provided by Metaplex itself. Here is the link to JS SDK which can help you retrieve the NFTs based on the wallet, creators, mint address, etc: Metaplex Javascript SDK. Alternatively, you can calculate the metadata PDA yourself and parse data field to retrieve NFTs using getProgramAccounts.
-
How can I get the Pubkey of program required by getProgramAccounts? For instance if I only know the public key of the account and not which type of tokens such as when programming a Wallet App that will explore the wallet to discover everything that it contains. The Quick Node example uses a Github library from what I can tell right? How can you do it with only RPC API? Could you give a code example of if you only knew a Wallet address (public key) how you could then get a list of tokens using only RPC API? Commented Oct 8, 2022 at 19:29
-
The pubkey of the program will the public key of Token Program: solscan.io/account/TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. You can add the public key of the account in the filter to only return the tokens owned by the wallet as mentioned in the article. Then you can pick the NFTs from the tokens by first filtering the tokens with the supply = 1 and afterwards retrieving the metadata account by calculating PDA. Alternatively, you can save the whole lot of trouble by simply using Metaplex API.– 0xShukCommented Oct 8, 2022 at 19:38
-
I do not understand. Lets say I know only the Wallet Address. Which API would I then use to get a list of tokens? If I try to use getProgramAccounts it asks for "Pubkey of program, as base-58 encoded string" as a parameter which I do not have. I don't understand which RPC API I use to get this. Commented Oct 9, 2022 at 6:05
-
Could you give a code example of if you only have a Wallet's Public Address (Public Key) and then retrieve a list of NFTs on it using only the RPC API? Commented Oct 9, 2022 at 8:11