How to get erc20 token transfers from a block to a block
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 transfers from a block to a block
In order to get erc20 token transfers from a block to a block, Blocklens provides you a getErc20TransfersByBlockRange endpoint to do so.
Here you'll need parameters: from_block
, to_block
.
Once you've obtained all the from_block
, to_block
, 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.getErc20TransfersByBlockRange({"from_block":18246150,"to_block":18246151});
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.eyJpZCI6MTgyNDYxNTEwMTI5MDAwMjYwLCJwYWdlIjoxLCJmcm9tQmxvY2siOjE4MjQ2MTUwLCJ0b0Jsb2NrIjoxODI0NjE1MSwiaWF0IjoxNjk3MDg0NDgxfQ.tHPJlZgJyjNNAGNDw7AhBz7eRhu8to0sAaqDnuYSYBs",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"token_name": "Wrapped Ether",
"token_symbol": "WETH",
"token_decimals": 18,
"contract_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"transaction_hash": "0x016834a72d9ea0f836eeeb347e3d1388b0d15549b6e9eedcb43f5bde097eb565",
"transaction_index": 166,
"log_index": 329,
"block_hash": "0x28f7522cc52594826d9853bf25d65ebb382650320ad791cd5434d955a9110d82",
"block_number": 18246151,
"from_wallet": "0x56A6e046f29A6a9eFA3A0d3897b59446027D38D2",
"to_wallet": "0x1111111254fb6c44bAC0beD2854e76F90643097d",
"value": "52125000",
"value_decimal": "0.000000000052125",
"timestamp": 1696048283
}
]
}
Congratulations 🥳 you just found the get erc20 token transfers from a block to a block 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.