Skip to main content

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

In order to get decoded events from time to time, Blocklens provides you a getDecodedEventsFromTimeToTime 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.getDecodedEventsFromTimeToTime({"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.eyJpZCI6IjB4ZTgyYmM5YzA4NjU3OTE0MWU4YjAxMDRjMWY2ZmRiZWI2MGFlOWYyNTQwMzA2MTQ1MWI4MDcxYTBmMjUyYjg1Nl8xNjkiLCJwYWdlIjoxLCJmcm9tX3RpbWUiOiIxNjk2MDQ4MjU5IiwidG9fdGltZSI6IjE2OTYwNDgyNjAiLCJpYXQiOjE2OTcwNjMwMDR9.YJVErCpD_wd5z1IATFQkHriuuF2IdyeKul6yrTp-E40",
"total_items": 1,
"data": [
{
"tx_hash": "0xfd3d58c60ed80d6c75080558ffc047639daefbf106abaccc8466d1492df47ea9",
"contract_address": "0xef9eF6E07602E1E0419a5788f1D85e0698eAB077",
"block_number": 18246150,
"timestamp": 1696048259,
"block_time": "2023-09-30 04:30:59",
"signature": "Swap(address,uint256,uint256,uint256,uint256,address)",
"index": 106,
"data_decoded": "[\"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D\",{\"type\":\"BigNumber\",\"hex\":\"0x00\"},{\"type\":\"BigNumber\",\"hex\":\"0x01f161421c8e0014\"},{\"type\":\"BigNumber\",\"hex\":\"0x133d75d56f8f4356e0d8\"},{\"type\":\"BigNumber\",\"hex\":\"0x00\"},\"0xB9C733CE233d5822C85F3298D3510B38f61a797F\"]",
"event_name": "Swap"
}
]
}

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