
The author: Kamau Joseph
In the world of non-fungible tokens (NFTs), metadata plays a crucial role by providing additional information about an NFT, including its name, description, image, and other attributes. This metadata is essential for marketplaces and collectors who use it to display, search, and verify the authenticity and ownership of NFTs. In this article, we will explore the process of obtaining NFT metadata using the Chainbase platform and its API.
Before we dive into the process of obtaining NFT metadata, let’s ensure we have the necessary tools in place:
To maximize the benefits of Chainbase’s capabilities, it’s advisable to create a free account on their platform. Here’s how you can do it:
Now that you have your Chainbase account set up and the required tools in place, let’s write a script to fetch the NFT metadata using the Chainbase API. We’ll provide examples using both the fetch and axios libraries in JavaScript.
Using fetch in JavaScript:
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0xed5af388653567af2f388e6224dc7c4b3241c544'; // Take the contract address of Azuki as an example.
token_id = '1'; // Token id should be in hex or num string. Here we take 1 as example.
fetch(`https://api.chainbase.online/v1/nft/metadata?chain_id=${network_id}&contract_address=${contract_addr}&token_id=${token_id}`, {
method: 'GET',
headers: {
'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
'accept': 'application/json'
}
}).then(response => response.json())
.then(data => console.log(data.data))
.catch(error => console.error(error));Using axios in JavaScript, you need to install axios using npm install axios --save in the terminal first.
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0xed5af388653567af2f388e6224dc7c4b3241c544'; // Take the contract address of Azuki as an example.
token_id = '1'; // Token id should be in hex or num string. Here we take 1 as example.
const axios = require('axios');
const options = {
url: `https://api.chainbase.online/v1/nft/metadata?chain_id=${network_id}&contract_address=${contract_addr}&token_id=${token_id}`,
method: 'GET',
headers: {
'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
'accept': 'application/json'
}
};
axios(options)
.then(response => console.log(response.data.data))
.catch(error => console.log(error));Make sure to replace CHAINBASE_API_KEY with your actual Chainbase API key obtained from your account.
In this step, we’ll retrieve and print the NFT metadata using the Chainbase API. Follow these instructions:
{
"contract_address": "0xed5af388653567af2f388e6224dc7c4b3241c544",
"name": "Azuki",
"symbol": "AZUKI",
"owner": "0xC8967D1537F7B995607A1DEa2B0C06E18A9756a2",
"token_id": "0x1",
"erc_type": "ERC721",
"image_uri": "https://ikzttp.mypinata.cloud/ipfs/QmYDvPAXtiJg7s8JdRBSLWdgSphQdac8j1YuQNNxcGE1hg/1.png",
"mint_time": "2022-01-12T04:17:28Z",
"mint_transaction_hash": "0xc208fdb2f133bda64522fececd6518a565aaa6e8801b0a776f2f93c922fe9420",
"token_uri": "https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/1",
"metadata": {
"name": "Azuki #1",
"image": "https://ikzttp.mypinata.cloud/ipfs/QmYDvPAXtiJg7s8JdRBSLWdgSphQdac8j1YuQNNxcGE1hg/1.png",
"attributes": [
{
"trait_type": "Type",
"value": "Human"
},
{
"trait_type": "Hair",
"value": "Pink Hairband"
},
{
"trait_type": "Clothing",
"value": "White Qipao with Fur"
},
{
"trait_type": "Eyes",
"value": "Daydreaming"
},
{
"trait_type": "Mouth",
"value": "Lipstick"
},
{
"trait_type": "Offhand",
"value": "Gloves"
},
{
"trait_type": "Background",
"value": "Off White D"
}
]
},
"traits": [
{
"trait_type": "Type",
"value": "Human"
},
{
"trait_type": "Hair",
"value": "Pink Hairband"
},
{
"trait_type": "Clothing",
"value": "White Qipao with Fur"
},
{
"trait_type": "Eyes",
"value": "Daydreaming"
},
{
"trait_type": "Mouth",
"value": "Lipstick"
},
{
"trait_type": "Offhand",
"value": "Gloves"
},
{
"trait_type": "Background",
"value": "Off White D"
}
]
}The script will send a request to the Chainbase API and retrieve the metadata for the specified NFT. The response will contain detailed information, including the NFT’s name, symbol, owner, image URI, minting details, and additional attributes. Review the printed metadata to gain insights into the NFT’s characteristics.
Obtaining NFT metadata is crucial for understanding an NFT’s attributes and ensuring its authenticity and ownership. By leveraging the Chainbase platform and its API, you can retrieve detailed metadata for specific NFTs, empowering marketplaces, collectors, and enthusiasts to explore and engage with NFTs effectively.
Get started with Chainbase today and unlock the potential of NFT metadata!
Now that you understand how to obtain NFT metadata using Chainbase, you can leverage this knowledge to explore and interact with the exciting world of NFTs. Dive into the vast ecosystem, discover unique digital assets, and experience the creativity and innovation that NFTs have to offer.
Happy exploring!
Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.
Visit our website chainbase.com Sign up for a free account, and Check out our documentation.
Website|Blog|Twitter|Discord|Link3
Original Link: How to Get NFT Metadata
【免责声明】市场有风险,投资需谨慎。本文不构成投资建议,用户应考虑本文中的任何意见、观点或结论是否符合其特定状况。据此投资,责任自负。
