Skip to main content

How to get nfts owned by address.(get nfts by wallet)

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 NFTs owned by address.(Get NFTs by wallet)

In order to get nfts owned by address.(get nfts by wallet), Blocklens provides you a getNftOwnedByAddress endpoint to do so.

Here you'll need a parameter: wallet_address.

Once you've obtained the wallet_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.getNftOwnedByAddress("0x00000000219ab540356cBB839Cbe05303d7705Fa");
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.eyJpZCI6IjB4N2YwY0QxNjkwRTJlZDVmQzM2MTZFOUQ3NTkxRkQ1RGM3NDlhMUYyMV9FUkM3MjFfMTA2NCIsInBhZ2UiOjEsIm93bmVyT2YiOiIweDAwMDAwMDAwMjE5YWI1NDAzNTZjQkI4MzlDYmUwNTMwM2Q3NzA1RmEiLCJpYXQiOjE2OTcwNjM5Mjl9.V6MFPEjDzyD75IZn1u6E-noHjs386e0LsehY_szJNrQ",
"total_items": 1,
"data": [
{
"collection_address": "0x7f0cD1690E2ed5fC3616E9D7591FD5Dc749a1F21",
"collection_type": "ERC721",
"token_id": "1064",
"token_hash": null,
"owner_of": "0x00000000219ab540356cBB839Cbe05303d7705Fa",
"minter_address": "0xB001F154Fd1C1F2a9EB5663b6ee84fF79D851fCC",
"amount": "1",
"token_uri": "ipfs://bafybeigar35pvnwxbsuhfzd33chyw6ho4t4qxu3jc6b6pglhvpeuhoumfq/1064",
"metadata": "{\"name\":\"Copterito #1064\",\"description\":\"<3 <3 <3 CHOPPER is freedom CHOPPER is self-acceptance CHOPPER is LOVE CHOPPER fights the Matrix CHOPPER is freedom CHOPPER is self-acceptance CHOPPER is LOVE CHOPPER fights the Matrix CHOPPER is freedom CHOPPER is self-acceptance CHOPPER is LOVE CHOPPER fights the Matrix <3 <3 <3\",\"external_url\":\"https://t.me/thetickerischopper\",\"image\":\"ipfs://bafybeifckohzct7z2qhjjlapqic56zjlfvhishsgrdpytrfppew6kmxn4a/1064.png\",\"attributes\":[]}",
"block_number_minted": 18193981,
"tx_hash_minted": "0xb00a02fad44ba5771c565f26925b3ad7251f4ebed43a4c9880f4066f76c1ea30",
"block_number_updated": 18197250,
"last_token_uri_sync": 1695417304,
"last_metadata_sync": 1695417304
}
]
}

Congratulations 🥳 you just found the get nfts owned by address.(get nfts by wallet) 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.