Skip to main content

How to get nft owners by 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 owners by collection

In order to get nft owners by collection, Blocklens provides you a getNftOwnersByCollection endpoint to do so.

Here you'll need a parameter: address.

Once you've obtained the address, 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.ETH_MAINNET.getNftOwnersByCollection("0x6339e5E072086621540D0362C4e3Cea0d643E114");
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.eyJpZCI6IjB4NjMzOWU1RTA3MjA4NjYyMTU0MEQwMzYyQzRlM0NlYTBkNjQzRTExNF9FUkM3MjFfOTc3MCIsInBhZ2UiOjEsImlhdCI6MTY5NzA2Mzk2NX0.iT0q6Xh7d6kYqnDRFgNldLkevtnDZoDZ5zjsxJ_Wfmo",
"total_items": 1,
"data": [
{
"collection_address": "0x6339e5E072086621540D0362C4e3Cea0d643E114",
"collection_type": "ERC721",
"token_id": "9984",
"token_hash": null,
"owner_of": "0xac850154630243E2dda28F08e1DAFaCa8aCCF843",
"minter_address": "0xa93903f3E321A3ef58ee707DAA0cdEcbcD9d3135",
"amount": "1",
"token_uri": null,
"metadata": null,
"block_number_minted": 16364372,
"tx_hash_minted": "0xf687778747cf28937d8f8e5615a8844e4314389f74e5b8573fe941849377359f",
"block_number_updated": 17005903,
"last_token_uri_sync": 1695788769950,
"last_metadata_sync": -9223372036854776000
}
]
}

Congratulations 🥳 you just found the get nft owners by 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.