Skip to main content

How to get transactions from block to 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 transactions from block to block

In order to get transactions from block to block, Blocklens provides you a getTransactionsFromBlockToBlock 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.getTransactionsFromBlockToBlock({"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.eyJpZCI6MTgyNDYxNTEwMDAxNTAsInBhZ2UiOjEsImZyb21fYmxvY2siOjE4MjQ2MTUwLCJ0b19ibG9jayI6MTgyNDYxNTEsImlhdCI6MTY5NzA4NTE1OX0.gi9H4dYrd9i8mXkn4TNhxA9RqLD8iW1WNl0neVV8lZ8",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"hash": "0x49c0daf9d1f0611d4b0844723badb703f15004e56829129346b7334a9eb3df5b",
"from": "0x20D0C35637f6D7D458B836136068cA8D1e761e7D",
"to": "0xb584D4bE1A5470CA1a8778E9B86c81e165204599",
"receipt_contract_address": null,
"receipt_cumulative_gas_used": "16532443",
"receipt_gas_used": "28694",
"input": "0xe56461ad000000000000000000000000000000000000000000000000000000000000006400000000000000000000000020d0c35637f6d7d458b836136068ca8d1e761e7d",
"value": "6000000000000",
"nonce": "13",
"gas_price": "6814972758",
"gas": "31563",
"timestamp": 1696048283,
"block_hash": "0x28f7522cc52594826d9853bf25d65ebb382650320ad791cd5434d955a9110d82",
"block_number": 18246151,
"tx_index": 169,
"status": true,
"effective_gas_price": "6814972758",
"logs_bloom": "0x000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000080100000000000000000000000800000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000004000000000000000000000001000000000000000000000000000000000000080000000000000000000000000000000000000000000000004000000080000000000000"
}
]
}

Congratulations 🥳 you just found the get transactions from block to 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.