getNftMetadataBatch - SDK

Gets the NFT metadata for multiple NFT tokens.

Don’t have an API key?

Start using this method in your app today. Get started for free

Description

Gets the NFT metadata for multiple NFT tokens.

Parameters

NameTypeDescription
tokensarrayAn array of NFT tokens to fetch metadata for.
optionsstringConfiguration options for making the request.

Response

PropertyTypeDescription
Promise<Nft[]>array of objectsAn array of objects containing nft metadata.

Nft[] response object parameters

PropertyTypeDescription
contractobjectThe NFT’s underlying contract and relevant contract metadata. Parameters in the contract include: 1. contractDeployer?: string The address that deployed the NFT contract. 2. name: string The name of the contract. 3. symbol: string The symbol of the contract. 4. totalSupply: string The number of NFTs in the contract as an integer string. This field is only available on ERC-721 contracts. 5. tokenType: string The type of the token in the contract. e.g, ERC721, ERC1155, UNKNOWN.
titlestringThe NFT title.
descriptionstringThe NFT description.
timeLastUpdatedstringWhen the NFT was last updated in the blockchain. Represented in ISO-8601 format.
metadataErrorstring | undefinedHolds an error message if there was an issue fetching metadata.
rawMetadataobjectThe raw metadata fetched from the metadata URL specified by the NFT. The field is undefined if Alchemy was unable to fetch metadata.
tokenURIobjectURIs for accessing the NFT’s metadata blob.
mediaarrayURIs for accessing the NFT’s media assets.
spamInfoobjectDetailed information on why an NFT was classified as spam.

Example Request and Response

Prerequisite: You will need to install the Alchemy SDK before making requests with it.

The commands for installing it using npm or yarn are given below:

$npm install alchemy-sdk

Request

index.js
1// Imports the Alchemy SDK
2const { Alchemy, Network } = require("alchemy-sdk");
3
4// Configures the Alchemy SDK
5const config = {
6 apiKey: "alchemy-replit", // Replace with your API key
7 network: Network.ETH_MAINNET, // Replace with your network
8};
9
10// Creates an Alchemy object instance with the config to use for making requests
11const alchemy = new Alchemy(config);
12
13const main = async () => {
14
15 //Call the method
16 let response = await alchemy.nft.getNftMetadataBatch(
17 [
18 {
19 contractAddress: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
20 tokenId: "3",
21 tokenType: "ERC721"
22 },
23 {
24 contractAddress: "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e",
25 tokenId: "4",
26 tokenType: "ERC721"
27 }
28 ],
29 {
30 tokenUriTimeoutInMs: 5000,
31 refreshCache: true
32 }
33 )
34
35 //Logging the response to the console
36 console.log(response)
37};
38
39main();

Response

json
1[
2 {
3 contract: {
4 address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',
5 name: 'BoredApeYachtClub',
6 symbol: 'BAYC',
7 totalSupply: '10000',
8 tokenType: 'ERC721',
9 openSea: [Object],
10 contractDeployer: '0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03',
11 deployedBlockNumber: 12287507
12 },
13 tokenId: '3',
14 tokenType: 'ERC721',
15 title: '',
16 description: '',
17 timeLastUpdated: '2023-02-26T08:28:13.584Z',
18 metadataError: undefined,
19 rawMetadata: {
20 image: 'ipfs://QmYxT4LnK8sqLupjbS6eRvu1si7Ly2wFQAqFebxhWntcf6',
21 attributes: [Array]
22 },
23 tokenUri: {
24 gateway: 'https://ipfs.io/ipfs/QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/3',
25 raw: 'ipfs://QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/3'
26 },
27 media: [ [Object] ],
28 spamInfo: undefined
29 },
30 {
31 contract: {
32 address: '0x8a90cab2b38dba80c64b7734e58ee1db38b8992e',
33 name: 'Doodles',
34 symbol: 'DOODLE',
35 totalSupply: '10000',
36 tokenType: 'ERC721',
37 openSea: [Object],
38 contractDeployer: '0x2b3ab8e7bb14988616359b78709538b10900ab7d',
39 deployedBlockNumber: 13430097
40 },
41 tokenId: '4',
42 tokenType: 'ERC721',
43 title: 'Doodle #4',
44 description: 'A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.',
45 timeLastUpdated: '2023-02-26T08:28:13.658Z',
46 metadataError: undefined,
47 rawMetadata: {
48 image: 'ipfs://QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm',
49 name: 'Doodle #4',
50 description: 'A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.',
51 attributes: [Array]
52 },
53 tokenUri: {
54 gateway: 'https://ipfs.io/ipfs/QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4',
55 raw: 'ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4'
56 },
57 media: [ [Object] ],
58 spamInfo: undefined
59 }
60]

Use Cases

Here are some use cases for the getNftMetadataBatch function:

  • NFT Marketplaces: An NFT marketplace is a platform where users can buy and sell NFTs. In such platforms, the getNftMetadataBatch function can be used to retrieve metadata for multiple NFTs in a single API call. This can improve the platform’s performance and user experience, as users can quickly view information about multiple NFTs at once.

  • NFT Galleries: NFT galleries are websites or apps that showcase a collection of NFTs. With getNftMetadataBatch, gallery owners can easily retrieve and display metadata for multiple NFTs, making it easier for visitors to browse and explore the collection.

  • NFT Wallets: NFT wallets are digital wallets that allow users to store, manage, and trade their NFTs. When users want to view their NFTs, the getNftMetadataBatch function can be used to retrieve metadata for all NFTs in the wallet, providing a quick overview of the user’s collection.

Related Methods

Here are the methods related to getNftMetadataBatch:

  • getNftMetadata: Get the NFT metadata associated with the provided parameters.