Skip to main content

How to get nft activities by block height

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 activities by block height

In order to get nft activities by block height, Blocklens provides you a getNftActivitiesByHeight endpoint to do so.

Here you'll need a parameter: block_height.

Once you've obtained the block_height, 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.APTOS_MAINNET.getNftActivitiesByHeight("18246150");
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:

{
"cursor": "string",
"page": 0,
"limit": 0,
"total_items": 0,
"data": [
{
"transfer_type": "0x3::token::MutateTokenPropertyMapEvent",
"transaction_version": 130,
"block_time": "2023-08-28 09:24:31.0",
"timestamp": 1693214669,
"token_data_id_hash": "2665375481df1ebbcdc9449cc4880e18f21a33fadda6b9ebf259797cc0a0e291",
"token_amount": 20,
"to_address": "09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b",
"name": "rockeric.apt",
"property_version": 0,
"from_address": "0x305a97874974fdb9a7ba59dc7cab7714c8e8e00004ac887b6e348496e1981838",
"event_sequence_number": 5,
"event_index": 2,
"event_creation_number": 1,
"event_account_address": "Aptos Names V1",
"collection_name": "09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b",
"collection_data_id_hash": "09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b",
"coin_type": "coin type",
"coin_amount": 1000,
"creator_address": "09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b",
"block_height": 1000
}
]
}

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