Skip to main content

How to get nft of collection

Prerequisites

Before getting started, make sure you have the following ready:

  • Node v.14+
  • NPM

Step 1: Setup Blocklens

First register your Blocklens account and get your Blocklens API Key.

Once you have your Blocklens API Key, install the Blocklens SDK in your project.

npm i blocklens-sdk

Step 2: Get NFT of collection

In order to get nft of collection, Blocklens provides you a getNfTsOfCollection endpoint to do so.

Here you'll need a parameter: collection_data_id_hash.

Once you've obtained the collection_data_id_hash, you can copy the following code:

import Blocklens from "blocklens-sdk";

const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });

const runApis = async () => {
const response = await blocklens.APTOS_MAINNET.getNfTsOfCollection("29c6893059a4c77fad7e7160b416a39ee44723830eb79187d97e9c7cdf36aa07");
console.log(response);
};

runApis();

Step 3: Run the script

ts-node index.ts

In your terminal, you should see the following JSON response with the data: In your terminal, you should see the following JSON response with the data blocks:

{
"cursor": "string",
"page": 0,
"limit": 0,
"total_items": 0,
"data": [
{
"collection_data_id_hash": "24a96a93ebc97746f7001326cf7c5747d5bd61c78813e154371e8d6ca1c881e3",
"collection_name": "Aptos Mice Club",
"creator_address": "0x9954a427a8eef9a11d3ec578c29e9592ee7e0d1147e9b58297b130b21cc17424",
"name": "Aptos Mice Club - #1050",
"property_version": "0",
"token_data_id_hash": "29389de555c39b96dbaa83cbd4f53156969ea74a02ec9eaa2f5723d435b59949",
"token_properties": {
"EYES": 1399682407,
"HEAD": 285387749230,
"MOUTH": 5464420,
"SHIRT": 8.268578594926225e25,
"HELMET": 5578108813654980000,
"TATTOO": 1416585572,
"EARINGS": 310939249016,
"BACKGROUND": 1.3869243956110336e33,
"BACK OBJECT": 91759383307631
},
"transaction_version": "9023902",
"transaction_timestamp": "1666503854414696",
"block_height": "2522147"
}
]
}

Congratulations 🥳 you just found the get nft of collection on multiple chains with only a few lines of code using the Blocklens Wallet API!

API Reference

If you want to know more details on the endpoint and optional parameters, check out:

Support

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.