Skip to main content

How to get events from time to time

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 events from time to time

In order to get events from time to time, Blocklens provides you a getEventsFromTimeToTime endpoint to do so.

Here you'll need parameters: from_time, to_time.

Once you've obtained all the from_time, to_time, 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.getEventsFromTimeToTime({"from_time":"1696048259","to_time":"1696048260"});
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.eyJpZCI6Mjc5OTgyMjcxMDAwMDA1LCJwYWdlIjoxLCJmcm9tX3RpbWUiOiIxNjk2MDQ4MjU5IiwidG9fdGltZSI6IjE2OTYwNDgyNjAiLCJpYXQiOjE2OTcwNTkzNTV9.rHzfJK63hGJcJfMX3SYsfSxYFbp7t9SLggwyo9KYtow",
"total_items": 1,
"data": [
{
"block_height": 97922852,
"timestamp": 1696048260,
"transaction_version": 279982283,
"transaction_hash": "0xe829b28d562211017ccbb5ddd446ced66c404b0214532ffb792a1e4ff7f6de9f",
"transaction_type": "block_metadata_transaction",
"creation_number": 3,
"account_address": "0x1",
"sequence_number": 97922852,
"type": "0x1::block::NewBlockEvent",
"event_index": 0,
"amount": -9223372036854776000,
"module_name": "null",
"struct_name": "null",
"data": [{}],
"block_hash": "0x1e674d0758069746651dc69c3b53914a2d9eb6cd109ff304bb5502d6018c5b41",
"success": true,
"vm_status": "Executed successfully"
}
]
}

Congratulations 🥳 you just found the get events from time to time 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.