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.ETH_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.eyJpZCI6MTgyNDYxNTAwMTE5MDAwMzIwLCJwYWdlIjoxLCJmcm9tX3RpbWUiOiIxNjk2MDQ4MjU5IiwidG9fdGltZSI6IjE2OTYwNDgyNjAiLCJpYXQiOjE2OTcwNjM4MDN9.xskwJ24A6_xdGRd8MPXwqYk8xGkYsJ1zebNFKr4NKjE",
"total_items": 1,
"data": [
{
"tx_hash": "0xb541e2f8143ad11384154b02ecfb733a82bbf2b0f53009ad20d79d21bec3df31",
"tx_index": 125,
"contract_address": "0xFdFF462845953D90719A78Fd12a2d103541d2103",
"block_hash": "0x0517e1369f5159852973c47dc335d28b67ccffb238333542f880abc3fe3ab505",
"block_number": 18246150,
"timestamp": 1696048259,
"log_index": 329,
"data": "0x00000000000000000000000000000000000000000000000002c68af0bb140000",
"topic0": "0x7047a0fb8bfae78c0ebbd4117437945bb85240453235ac4fd2e55712eb5bf0c3",
"topic1": "0x00000000000000000000000000000000000000000000000000000000000001b2",
"topic2": "0x000000000000000000000000bdee962137373a755a71c716e01b9946b1a27686",
"topic3": null,
"removed": "false"
}
]
}
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.