Skip to main content

How to get erc20 token approvals

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

In order to get erc20 token approvals, Blocklens provides you a getErc20Approvals 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.getErc20Approvals();
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.eyJpZCI6MTgyODMyODYwMDE3MDAwMTMwLCJwYWdlIjoxLCJpYXQiOjE2OTcwNjMyNzZ9.Q0pUi8U_X7sO7q5A6Jtg7TiSuvkN2aZM9uZhza0oqM8",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"token_name": "Liquid staked Ether 2.0",
"token_symbol": "stETH",
"token_decimals": 18,
"contract_address": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
"transaction_hash": "0x0ba709383fc1378e6a75101ff09e1a9bd3ee19eb3e448dfb457444eb4fe8d031",
"transaction_index": 129,
"log_index": 350,
"block_hash": "0x9dce9c505115b31b6afcae07d5b3ddc2bdf4ca89469682cc79cbc64fe12bce7b",
"block_number": 18283286,
"from_wallet": "0xF0D98b95BBbE6e3007703C99A9FFC3D9f5b581E6",
"to_wallet": "0x1111111254EEB25477B68fb85Ed929f73A960582",
"value": "7044483623640093",
"value_decimal": "0.007044483623640093",
"timestamp": 1696496531
}
]
}

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