Skip to main content

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.ETH_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:

{
"page": 1,
"limit": 20,
"cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IkVSQzcyMV8weDkzOENiMGFlMjJEMzhBM0E4MTJkNzdjMzQ1MDkzQjRGOThGMjA4NzMiLCJwYWdlIjoxLCJpYXQiOjE2OTcwNjE1OTV9.iLrqKpIg9i5MoAHUzMrj5wZF3Ho-7ok8IefqFqcASoQ",
"total_items": 1,
"data": [
{
"address": "0xf9b5cD731C2C86f9F9B8185B80Ce0a148CD401C5",
"type": "ERC721",
"name": "Dimensional Dreams",
"owner": "0x912657fa4636f6D0af65aB8b1D75bA3616D6c853",
"base_uri": "ipfs://",
"total_supply": "1",
"description": null,
"external_link": null,
"image": null,
"last_synced_at": 1694871038
}
]
}

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.