How to get the metadata of a specific NFT
What is NFT metadata?
NFT metadata is the set of descriptive information stored off-chain that details the attributes, properties, and additional content associated with an NFT. These details can be an image URL, its name, description, and attributes related to its uniqueness and ownership.
How to do it with Moralis
Moralis has an NFT API that you can make use of, and they even provide a code sample for the wallet history use-case:
To adapt their code sample, replace the reference to Ethereum with their ID for Chiliz Chain, 0x15b38:
import Moralis from 'moralis';
try {
await Moralis.start({
apiKey: "YOUR_API_KEY"
});
const response = await Moralis.EvmApi.nft.getNFTMetadata({
"chain": "0x15b38", // This is for Chiliz Chain Mainnet.
// For Spicy Testnet, use "0x15b32".
"format": "decimal",
"normalizeMetadata": true,
"mediaItems": false,
"address": "0xYourNFTContractAddress",
"tokenId": "1"
});
console.log(response.raw);
} catch (e) {
console.error(e);
}How to do it with Tatum
Tatum has an NFT submodule to its blockchain abstraction tool that we can make use of, and they even provide a code sample for the metadata-retrieval use-case:
To adapt their code sample, replace the reference to Ethereum with Chiliz Chain:
import {TatumSDK, Network, Chiliz, ResponseDto, NftTokenDetail} from '@tatumio/tatum'
const tatum = await TatumSDK.init<Chiliz>({network: Network.CHILIZ})
const metadata: ResponseDto<NftTokenDetail|null> = await tatum.nft.getNftMetadata({
tokenAddress: '0xYourNFTContractAddress', // replace with your collection
tokenId: '1'
})
console.log(metadata.data)How to do it with thirdweb
thirdweb we can take inspiration from source code hosted on their documentation site:
Here is how we could adapt that into code to retrieve metadata:
const { ThirdwebSDK } = require("@thirdweb-dev/sdk");
const sdk = new ThirdwebSDK("https://rpc.chiliz.com");
const nftContractAddress = "0xYourNFTContractAddress";
const tokenId = "YourTokenID";
async function getNFTMetadata() {
try {
const nftContract = await sdk.getNFTCollection(nftContractAddress);
const nftMetadata = await nftContract.get(tokenId);
console.log(`Metadata of NFT ${tokenId}:`, nftMetadata);
} catch (error) {
console.error("Error fetching NFT metadata:", error);
}
}
getNFTMetadata();How to do it with Nodit
Nodit provides the following code sample in their doc:
const url = 'https://web3.nodit.io/v1/chiliz/mainnet/nft/getNftMetadataByTokenIds';
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'X-API-KEY': 'nodit-demo'
},
body: JSON.stringify({
tokens: [
{contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', tokenId: '1'},
{contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', tokenId: '2'}
]
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));Last updated
Was this helpful?