Skip to main content

How to get erc20 token approvals 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 ERC20 token approvals from time to time

In order to get erc20 token approvals from time to time, Blocklens provides you a getErc20ApprovalsByTimeRange 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.getErc20ApprovalsByTimeRange({"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:

{
"cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTgyNDYxNTAwMDA5MDAwMDYwLCJwYWdlIjoxLCJmcm9tVGltZSI6IjE2OTYwNDgyNTkiLCJ0b1RpbWUiOiIxNjk2MDQ4MjYwIiwiaWF0IjoxNjk3MDYzMjE3fQ.O2f1m6hf-tycWRgEyGuJnBNgf6u4p0vdtCRUceYyGJM",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"token_name": "DXdao",
"token_symbol": "DXD",
"token_decimals": 18,
"contract_address": "0xa1d65E8fB6e87b60FECCBc582F7f97804B725521",
"transaction_hash": "0x69e0363e5b6276be1b56c2dbc9709ca6ae57e0779863ed03562728ba6015403b",
"transaction_index": 121,
"log_index": 325,
"block_hash": "0x0517e1369f5159852973c47dc335d28b67ccffb238333542f880abc3fe3ab505",
"block_number": 18246150,
"from_wallet": "0x5554A279FF7A6313Dc686e1916B05Bd70e650D86",
"to_wallet": "0xa7Ca2C8673bcFA5a26d8ceeC2887f2CC2b0Db22A",
"value": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"value_decimal": "115792089237316195423570985008687907853269984665640564039457.584007913129639935",
"timestamp": 1696048259
}
]
}

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