How to get decoded 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 decoded events
In order to get decoded events, Blocklens provides you a getDecodedEvents 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.getDecodedEvents();
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.eyJpZCI6IjB4ZmZmZmZhMjUxMDZkZTE1N2NhOGYzMGM2ZjY3MjFmZmM4ZWJhYThiYTk4NmZiNThjN2E2NTRmYjliYjQzY2FjMl8yNTciLCJwYWdlIjoxLCJpYXQiOjE2OTcwNjMwNDZ9.dTfG6R4JECcKyg5m-sdXRVIUMit-zj9JkQgQy6jZEMg",
"total_items": 1,
"data": [
{
"tx_hash": "0xffffffd37775038cb9f7019f14a4a8ffb0b2e8ccae72a29c61de61e81ab7e14e",
"contract_address": "0xB705268213D593B8FD88d3FDEFF93AFF5CbDcfAE",
"block_number": 18230941,
"timestamp": 1695864143,
"block_time": "2023-09-28 01:22:23",
"signature": "Transfer(address,address,uint256)",
"index": 52,
"data_decoded": "[\"0xDFd5293D8e347dFe59E90eFd55b2956a1343963d\",\"0xf84dfA47420f906Ae23F6684e3c837D09eD11F1a\",{\"type\":\"BigNumber\",\"hex\":\"0x22fd7bb5b544911400\"}]",
"event_name": "Transfer"
}
]
}
Congratulations 🥳 you just found the get decoded 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.