How to get events
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
In order to get events, Blocklens provides you a getEvents endpoint to do so.
import Blocklens from "blocklens-sdk";
const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });
const runApis = async () => {
const response = await blocklens.ETH_MAINNET.getEvents();
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.eyJpZCI6MTgyNjY5ODgwMDYzMDAwMTYwLCJwYWdlIjoxLCJpYXQiOjE2OTcwNjM4Mjd9.6M0Y82IEEjCr9L7KT9dbJXUgsh3SX9mf66lUW0mVfKc",
"total_items": 1,
"data": [
{
"tx_hash": "0xf23c1149295fab207cbc5f800207f626a97f3bd17cb4457cdc05665192f91612",
"tx_index": 71,
"contract_address": "0xD850942eF8811f2A866692A623011bDE52a462C1",
"block_hash": "0x7fa3d2c64c15a89b9a6c7a4261d6a25e7f3ba2e6992184a80f73a2ade5f61ff0",
"block_number": 18266988,
"timestamp": 1696299599,
"log_index": 192,
"data": "0x000000000000000000000000000000000000000000000000000000d41bd4d600",
"topic0": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925",
"topic1": "0x0000000000000000000000003849d528e85bd6ab129155e29d86156d27a8ab4a",
"topic2": "0x000000000000000000000000ef2f9b48d7ec80440ab4573df1a2abdbe06d3f60",
"topic3": null,
"removed": "false"
}
]
}
Congratulations 🥳 you just found the get events 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.