1

The normal /listings endpoint does not give the metadata of the NFT. How can I also get the metadata and info of the NFT?

2 Answers 2

3

Programmatically, what you can do is the following:

  1. Calculate the metadata PDA address from mintId. You can find many examples of how the calculation is done in the metaplex repositories. Under the hood they will call PublicKey.findProgramAddress or PublicKey.findProgramAddressSync with the appropriate parameters. The particular call for metadata PDA looks like this. The only variable is the tokenMint, which means that there is a 1-1 correspondence between mint id and metadata id. You don't need to use the code below (as this is exposed in metaplex APIs as well, but it's useful to know as this is what all getPDA methods do under the hood).

import {PublicKey} from "@solana/web3.js" /// or use any one of the solana libraries that provide PublicKey

export const getMetadataPDA = (
  tokenMint: PublicKey
): PublicKey => {
  return 
    PublicKey.findProgramAddressSync(
      [
        Buffer.from('metadata'),
        Buffer.from('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'),
        tokenMint.toBuffer()
      ],
      Buffer.from('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s')
    )[0];
}
  1. Once you have the metadata Id calculated in (1), you call connection.getAccountInfo on that address. This gives you the raw account buffer.

  2. You decode the raw account buffer using a suitable deserializer. Again, there are examples in metaplex repos on how to deserialize raw buffers if you're not familiar with how it's done.

To optimise step(2), if you are retrieving multiple metadata in one go, it's best to use connection.getMultipleAccountInfo instead of connection.getAccountInfo. With the former, you can get max 100 accounts in one go, which is more more efficient that 100 individual calls.

2
  • Wow thanks a lot! Any examples of how to decode the raw account? Im using python
    – Pixeled
    Aug 19 at 16:32
  • 1
    I figured it out. Thanks so much
    – Pixeled
    Aug 19 at 20:39
1

The metadata is on the URI json file of each.

You can Snapshot holders or mints and then decode mint (use the --full option to get the NFT metadata for each)that will give you the metadata for each nicely in a folder with the mint address as the file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.