4

Given a token mint address, I'm looking for a way to get access to the metadata of an ERC721 token. Is there an API in @solana/web3.js?

chris
  • 600
  • 7
  • 21

3 Answers3

7

Solana stores token metadata at an address that is derived from the original token's address as per https://docs.solana.com/developing/programming-model/calling-between-programs#hash-based-generated-program-addresses

The reference code is in rust, here is the implementation from @solana/web3.js.
(source)

  static async findProgramAddress(
    seeds: Array<Buffer | Uint8Array>,
    programId: PublicKey,
  ): Promise<[PublicKey, number]> {
    let nonce = 255;
    let address;
    while (nonce != 0) {
      try {
        const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
        address = await this.createProgramAddress(seedsWithNonce, programId);
      } catch (err) {
        if (err instanceof TypeError) {
          throw err;
        }
        nonce--;
        continue;
      }
      return [address, nonce];
    }
    throw new Error(`Unable to find a viable program address nonce`);
  }

Note that the metadata is encoded in base64, using the borsh library, as per https://docs.metaplex.com/nft-standard#token-metadata-program.

Here is a concise implementation to retrieve and parse metadata using only borsh and @solana/web3.js https://gist.github.com/dvcrn/c099c9b5a095ffe4ddb6481c22cde5f4

Finally, MagicDen has an endpoint that returns the metadata: https://api-mainnet.magiceden.io/rpc/getNFTByMintAddress/DugthRKbQZRMcDQQfjnj2HeSjz2VARPC8H9abxdNK2SS

Kartik Soneji
  • 1,066
  • 1
  • 13
  • 25
2

No there's currently no API for that, however the phantom wallet uses the metaplex on-chain program at: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" to get the info it needs about the NFT which is hosted on arweave & the corresponding data account.

steveluscher
  • 4,144
  • 24
  • 42
  • Thanks for the information, I'll take a look at it and build something on my own then. – chris Sep 09 '21 at 11:29
  • This worked for me: https://api-mainnet.magiceden.io/rpc/getNFTByMintAddress/DugthRKbQZRMcDQQfjnj2HeSjz2VARPC8H9abxdNK2SS – Kartik Soneji Oct 10 '21 at 23:33
0

No, but one is available via the Blockchain API here: https://docs.blockchainapi.com/#tag/Solana-NFT/paths/~1v1~1solana~1nft/get

You just supply the mint_address and get back the metadata. Pretty simple!

Joshua Wolff
  • 2,687
  • 1
  • 25
  • 42