Skip to main content

How to get activities of type 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 activities of type from a block to a block

In order to get activities of type from a block to a block, Blocklens provides you a getActivitiesOfTypeFromBlockToBlock endpoint to do so.

Here you'll need parameters: coin_type, from_block, to_block.

Once you've obtained all the coin_type, 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.APTOS_MAINNET.getActivitiesOfTypeFromBlockToBlock("0x1::aptos_coin::AptosCoin", {"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.eyJpZCI6Mjc1MDkxMzE1OTk5OTk5LCJwYWdlIjoxLCJmcm9tX2Jsb2NrIjo5NjMyNjE2NSwidG9fYmxvY2siOjk2MzI2MTY1LCJjb2luX3R5cGUiOiIweDE6OmFwdG9zX2NvaW46OkFwdG9zQ29pbiIsImlhdCI6MTY5NzA4MzExNX0.C35a37pHPuUhK--u-Kv8AoaLMBDxpSikG6RH5RGHRVI",
"total_items": 1,
"data": [
{
"activity_type": "0x1::aptos_coin::GasFeeEvent",
"amount": 4300,
"block_height": 96326165,
"coin_type": "0x1::aptos_coin::AptosCoin",
"entry_function_id_str": "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap",
"event_account_address": "0x1a5f85d702b02feaf3ad52953e4a91773970ee351ebc834062d1a851fd343ee4",
"event_creation_number": -1,
"event_index": -1,
"event_sequence_number": 3,
"id": 275091319999999,
"is_gas_fee": true,
"is_transaction_success": false,
"owner_address": "0x1a5f85d702b02feaf3ad52953e4a91773970ee351ebc834062d1a851fd343ee4",
"timestamp": 1695663050,
"transaction_version": 275091320
}
]
}

Congratulations 🥳 you just found the get activities of type 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.