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?
3 Answers
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

- 1,066
- 1
- 13
- 25
-
2Or use the metaplex js library - https://docs.metaplex.com/development/clients/js-sdk/getting-started – Sergiy Kozachenko Oct 14 '21 at 20:35
-
1https://docs.metaplex.com/sdk/js/examples#metadata is the updated link to @SergiyKozachenko's comment – technoplato Jan 16 '22 at 18:39
-
Is API of MagicEden public and free to use, I can't find any info about it. – Farid Movsumov Feb 11 '22 at 16:21
-
@Farid I don't believe the endpoint is meant for public use but it's handy to use while testing. – Kartik Soneji Feb 11 '22 at 19:08
-
@KartikSoneji thanks for the answer. Would be great if they open it public – Farid Movsumov Feb 12 '22 at 07:56
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.

- 4,144
- 24
- 42

- 21
- 2
-
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
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!

- 2,687
- 1
- 25
- 42