How to get collections
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 collections
In order to get collections, Blocklens provides you a getCollections endpoint to do so.
import Blocklens from "blocklens-sdk";
const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });
const runApis = async () => {
const response = await blocklens.APTOS_MAINNET.getCollections();
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": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImYxNzIyNGVjMjAwOTkzOGVmZjA0MzJjYmZmMjE5ODgyYWE3Y2QwZWQ5ZDM5NWI4MjNmODNhNGMzMzM0NjNhMGMiLCJwYWdlIjoxLCJpYXQiOjE2OTcwNTkyNTJ9.1WhSHVicYJpZ1LGAsAPYirV1p0w4Bz2_Hu4BzY9g8wE",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"collection_data_id_hash": "ff117ffe2f15292da701824b2a3515f570d2ac6a3c2db2f0987570487aa04166",
"collection_name": "Cetus Position | tAPT-USDC_tick(60)",
"creator_address": "0xbe5ace54bc9513ab501bac4ab5017bfb411636b04d3f29720975cd22edab7b52",
"description": "Cetus Liquidity Position",
"description_mutable": true,
"maximum": 0,
"maximum_mutable": true,
"metadata_uri": "https://2335flaya2zmlob5dty2ulbytrlmbcih33mtlmmmju5v6b6llmyq.arweave.net/1vfSrBgGssW4PRzxqiw4nFbAiQfe2TWxjE07XwfLWzE",
"supply": 0,
"table_handle": "0x5ff8c2457c1d5f42c8b904f1da6aa3d28695dbc233ef9a3368fd1aa000ce7d84",
"transaction_timestamp": 1695224523,
"transaction_version": 269297638,
"uri_mutable": "true"
}
]
}
Congratulations 🥳 you just found the get collections 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.