Skip to main content

How to get nft transfers by block number or hash

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 transfers by block number or hash

In order to get nft transfers by block number or hash, Blocklens provides you a getNftTransfersByBlockNumberOrHash endpoint to do so.

Here you'll need a parameter: block_number_or_hash.

Once you've obtained the block_number_or_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.ETH_MAINNET.getNftTransfersByBlockNumberOrHash("0x0517e1369f5159852973c47dc335d28b67ccffb238333542f880abc3fe3ab505");
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.eyJpZCI6IjB4MDAwMDAwMDAwMDY2NGNlZmZlZDM5MjQ0YTgzMTJiRDg5NTQ3MDgwM180NjMyNTlfMHgxYjg2ZTBkNjRlZGM1MzM3ZjFhMWEyMTJmN2M0ZmFhNDM4Y2UyNzIxY2I3NDE5ZDRmMTUwMzMyZmZlMjZiNWFiXzE2NyIsInBhZ2UiOjEsImJsb2NrSGFzaCI6IjB4MDUxN2UxMzY5ZjUxNTk4NTI5NzNjNDdkYzMzNWQyOGI2N2NjZmZiMjM4MzMzNTQyZjg4MGFiYzNmZTNhYjUwNSIsImlhdCI6MTY5NzA2Mzk5MH0.l4JazaILZ_acz2u5sT6Mewk9xi9nJ7p_MTwBEIqAia0",
"total_items": 1,
"data": [
{
"token_address": "0xa58Eb817Dda3415FB68cB040021f5049350dEb45",
"contract_type": "ERC721",
"token_id": "5937",
"block_hash": "0x0517e1369f5159852973c47dc335d28b67ccffb238333542f880abc3fe3ab505",
"block_number": 18246150,
"transaction_hash": "0xab9c991c631a667375e90e45fb0318b1eaeb9891fe4e4941f2496cf21671d684",
"log_index": 223,
"from": "0x0000000000000000000000000000000000000000",
"to": "0xE8E55Ea216E718e0Aa7544545a03E29bAED7a611",
"amount": "1",
"operator": null,
"timestamp": 1696048259
}
]
}

Congratulations 🥳 you just found the get nft transfers by block number or hash 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.