How to get decoded events with abi
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 with abi
In order to get decoded events with abi, Blocklens provides you a decodeEventWithAbi endpoint to do so.
Here you'll need a parameter: transaction_hash
.
Once you've obtained the transaction_hash
, 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.decodeEventWithAbi(
"0x3d6122660cc824376f11ee842f83addc3525e2dd6756b9bcf0affa6aa88cf741",
{
abi: [
{
encode_signature:
"MHg4YzdhMDA1ZDBjMDNiNmM2OTZkNDZlYmM4YTZlYTFhNGViZjc1OTMxNTRjY2MzMGU5OGI3Mzg4ZWI3YTQ0M2E4",
signature:
"0x8c7a005d0c03b6c696d46ebc8a6ea1a4ebf7593154ccc30e98b7388eb7a443a8",
},
],
}
);
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:
[
{
"tx_hash": "0x8c7a005d0c03b6c696d46ebc8a6ea1a4ebf7593154ccc30e98b7388eb7a443a8",
"contract_address": "0x0000000000000000000000000000000000001003",
"block_number": 1,
"timestamp": 1661314004,
"block_time": "1970-01-19T12:04:31.492Z",
"signature": "0x8c7a005d0c03b6c696d46ebc8a6ea1a4ebf7593154ccc30e98b7388eb7a443a8",
"index": "0",
"data_decoded": "0",
"event_name": "0"
}
]
Congratulations 🥳 you just found the get decoded events with abi 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.