Get the NFT metadata associated with the provided parameters.
Donβt have an API key?
Start using this method in your app today.
Description
Get the NFT metadata associated with the provided parameters.
Parameters
Name | Type | Description |
---|---|---|
contractAddress | string | The contract address of the NFT. |
tokenId | string | Token id of the NFT. |
options | object | Options for the request. A null object should still be passed in params if no options are provided for the request. |
options
paramters
options
paramtersParameter | Type | Deescription |
---|---|---|
tokenType? | object | Optional field to specify the type of token to speed up the query. Available options include: [ERC721 = "ERC721", ERC1155 = "ERC1155", UNKNOWN = "UNKNOWN"] |
tokenUriTimeoutInMs? | number | No set timeout by default - When metadata is requested, this parameter is the timeout (in milliseconds) for the website hosting the metadata to respond. If you want to only access the cache and not live fetch any metadata for cache misses then set this value to 0. |
refreshCache? | boolean | Whether to refresh the metadata for the given NFT token before returning the response. Defaults to false for faster response times. |
Response
Property | Type | Description |
---|---|---|
Promise<Nft> | object | Object containing nft metadata. |
Nft
response object properties
Nft
response object propertiesProperty | Type | Description |
---|---|---|
contract | object | The NFT's underlying contract and relevant contract metadata. Parameters in the contract include: 1. address : string The address of the NFT contract.2. tokenType : object The type of the token in the contract3. name : string The name of the contract.4. symbol : string The symbol of the contract.5. totalSupply?: string The number of NFTs in the contract as an integer string. This field is only available on ERC-721 contracts.6. openSeaMetadata: object OpenSea's metadata for the contract.7. contractDeployer?: string The address that deployed the NFT contract.8. deployedBlockNumber?: number The block number the NFT contract deployed in.9. isSpam : boolean Whether the NFT contract is marked as spam.10. spamClassifications : array Potential reasons why an NFT Contract was classified as spam. |
tokenId | string | The NFT token ID as an integer string. |
tokenType | string | The type of NFT, e.g.,ERC721 , ERC1155 , UNKNOWN . |
name | string | The NFT name. |
description | string | The NFT description. |
timeLastUpdated | string | When the NFT was last updated in the blockchain. Represented in ISO-8601 format. |
raw | object | The raw metadata for the NFT based on the metadata URI on the NFT contract. 1. tokenUri?: string : The raw token URI on the NFT contract.2. metadata: string : The raw metadata parsed from the raw token URI.3. error?: string : Error message if the raw metadata could not be fetched. |
tokenUri | string | URIs for accessing the NFT's metadata blob. |
image | object | Media URLs and information for the NFT. Parameters in this object include: 1. cachedUrl: string : URL of the image stored in Alchemy's cache.2. thumbnailUrl: string : URL of a thumbnail-sized image.3. pngUrl: string : URL of the image in png format.4. contentType: string : The type of the media image. |
acquiredAt | object | Time at which the user most recently acquired the NFT. Only available when specifying orderBy: NftOrdering.TRANSFERTIME in the request.1. blockTimestamp?: string : Timestamp of the block at which an NFT was last acquired.2. blockNumber?: number : Block number of the block at which an NFT was last acquired. |
collection | object | Collection metadata for the NFT, if available. Parameters include: 1. name: string : The name of the collection.2. slug?: string : The OpenSea human-readable slug of the collection.3. externalUrl?: string : The external URL for the collection.4. bannerImageUrl?: string : The banner image URL for the collection. |
mint | object | Mint information for the NFT. Parameters include: 1. mintAddress?: string : The address that the NFT was minted to.2. blockNumber?: number : The block number that the NFT was minted on.3. timestamp?: string : The timestamp the NFT was minted on.4. transactionHash?: string : The transaction hash of the transaction that minted the NFT. |
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 i alchemy-sdk@latest
yarn add alchemy-sdk@latest
Request
// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");
// Configures the Alchemy SDK
const config = {
apiKey: "alchemy-replit", // Replace with your API key
network: Network.ETH_MAINNET, // Replace with your network
};
// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);
const main = async () => {
const contractAddress = "0x5180db8F5c931aaE63c74266b211F580155ecac8";
const tokenId = "1590";
// call the method
let response = await alchemy.nft.getNftMetadata(contractAddress, tokenId, {});
// logging the response to the console
console.log(response)
};
main();
Response
{
"contract": {
"address": "0xe785E82358879F061BC3dcAC6f0444462D4b5330",
"name": "World Of Women",
"symbol": "WOW",
"totalSupply": "10000",
"tokenType": "ERC721",
"contractDeployer": "0xc9b6321dc216D91E626E9BAA61b06B0E4d55bdb1",
"deployedBlockNumber": 12907782,
"openSeaMetadata": {
"floorPrice": 0.6021,
"collectionName": "World of Women",
"collectionSlug": "world-of-women-nft",
"safelistRequestStatus": "verified",
"imageUrl": "https://i.seadn.io/gcs/files/8604de2d9aaec98dd389e3af1b1a14b6.gif?w=500&auto=format",
"description": "World of Women is a collection of 10,000 NFTs that gives you full access to our network of artists, creators, entrepreneurs, and executives who are championing diversity and equal opportunity on the blockchain.\n\nCreated and illustrated by Yam Karkai (@ykarkai), World of Women has made prominent appearances at Christie's, The New Yorker and Billboard.\n\nJoin us to receive exclusive access to NFT drops, experiences, and much more.\n\nThe Time is WoW.",
"externalUrl": "http://worldofwomen.art",
"twitterUsername": "worldofwomennft",
"discordUrl": "https://discord.gg/worldofwomen",
"bannerImageUrl": "https://i.seadn.io/gae/GHhptRLebBOWOy8kfXpYCVqsqdes-1-6I_jbuRnGTHHW6TD63CtciH75Dotfu2u8v6EmkWt-tjhkFRVLxRUwgMfKqqy5W24AolJayeo?w=500&auto=format",
"lastIngestedAt": "2023-09-18T12:28:27.000Z"
},
"spamClassifications": []
},
"tokenId": "44",
"tokenType": "ERC721",
"name": "WoW #44",
"tokenUri": "https://alchemy.mypinata.cloud/ipfs/QmTNBQDbggLZdKF1fRgWnXsnRikd52zL5ciNu769g9JoUP/44",
"image": {
"cachedUrl": "https://nft-cdn.alchemy.com/eth-mainnet/9316855d8f60a32cd44aa71f07cd7dc1",
"thumbnailUrl": "https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/9316855d8f60a32cd44aa71f07cd7dc1",
"pngUrl": "https://res.cloudinary.com/alchemyapi/image/upload/convert-png/eth-mainnet/9316855d8f60a32cd44aa71f07cd7dc1",
"contentType": "image/png",
"size": 105117,
"originalUrl": "https://ipfs.io/ipfs/QmUkdJKCsV8ixm2eDLJGosH8Bntwwx942YXxfuF9yXPBzi"
},
"raw": {
"tokenUri": "ipfs://QmTNBQDbggLZdKF1fRgWnXsnRikd52zL5ciNu769g9JoUP/44",
"metadata": {
"name": "WoW #44",
"image": "ipfs://QmUkdJKCsV8ixm2eDLJGosH8Bntwwx942YXxfuF9yXPBzi",
"attributes": [
{
"value": "Green Orange",
"trait_type": "Background"
},
{
"value": "Medium Gold",
"trait_type": "Skin Tone"
},
{
"value": "Slight Smile",
"trait_type": "Mouth"
},
{
"value": "Purple",
"trait_type": "Lips Color"
}
]
}
},
"collection": {
"name": "World of Women",
"slug": "world-of-women-nft",
"externalUrl": "http://worldofwomen.art",
"bannerImageUrl": "https://i.seadn.io/gae/GHhptRLebBOWOy8kfXpYCVqsqdes-1-6I_jbuRnGTHHW6TD63CtciH75Dotfu2u8v6EmkWt-tjhkFRVLxRUwgMfKqqy5W24AolJayeo?w=500&auto=format"
},
"mint": {},
"timeLastUpdated": "2023-09-18T13:25:41.833Z"
}
Code Sandbox
You can test out the getNftMetadata
method using the code sandbox below:
Use Cases
Here are some potential use cases for the getNftMetadata
function:
-
Displaying NFT information: When a user wants to view information about a specific NFT, such as its name, description, image, or other attributes,
getNftMetadata
can be called to retrieve this information from the NFT metadata. -
NFT marketplaces: NFT marketplaces can use
getNftMetadata
to display information about NFTs that are available for sale or auction. This information can help potential buyers decide which NFTs to purchase. -
Verification:
getNftMetadata
can be used to verify the authenticity of an NFT. If the metadata associated with an NFT matches the expected values, then it is more likely to be a genuine NFT.
Related Methods
Here are the methods related to thegetNftMetadata
method:
- getNftMetadataBatch: Gets the NFT metadata for multiple NFT tokens.