How to get nft transfers from a block to a block
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 from a block to a block
In order to get nft transfers from a block to a block, Blocklens provides you a getNftTransfersFromBlockToBlock endpoint to do so.
Here you'll need parameters: from_block
, to_block
.
Once you've obtained all the from_block
, to_block
, 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.getNftTransfersFromBlockToBlock({"from_block":18246150,"to_block":18246151});
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.eyJpZCI6IjB4NmFhNjlhOEZFNzdEN0Y0OEY3MzI1M0JCM0NFNjdFNGUwYzQyZkQ2N180XzB4MGZhZjEwZmNlODU2NDJjZmIxNmI3ZDAwNmFiN2VmZDY2M2RjNTY5N2E1NmI5NTRiYTg2NWM2MzZmNjY0NzQwYl8zMTEiLCJwYWdlIjoxLCJmcm9tX2Jsb2NrIjoxODI0NjE1MCwidG9fYmxvY2siOjE4MjQ2MTUxLCJpYXQiOjE2OTcwODQ5MjV9.UCqDHXqk-FgQwU7Eo2HGM-C_u5rjg0GE2lwRnA_ICnk",
"total_items": 1,
"data": [
{
"token_address": "0xde607Ec7B715bf8b315Ae05A005dFe9c50d66772",
"contract_type": "ERC721",
"token_id": "4409",
"block_hash": "0x28f7522cc52594826d9853bf25d65ebb382650320ad791cd5434d955a9110d82",
"block_number": 18246151,
"transaction_hash": "0xe89c48858d80b29af09cfca6737ee110f241771cc9f75d8e77d4d04175836207",
"log_index": 294,
"from": "0x0000000000000000000000000000000000000000",
"to": "0x3F01793259Ad3D937c85cd872CA9F012aAd84E18",
"amount": "1",
"operator": null,
"timestamp": 1696048283
}
]
}
Congratulations 🥳 you just found the get nft transfers from a block to a block 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.