How to get transactions
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
In order to get transactions, Blocklens provides you a getTransactions 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.getTransactions();
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.eyJpZCI6MTgyNjY5ODgwMDAwNTIsInBhZ2UiOjEsImlhdCI6MTY5NzA2NDgwMn0.YW7WMiHd1yh3F5eK9qBZ9fLbKTa-Wj_fmNhjVRzTZE8",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"hash": "0x632a608d6e538af6a0a9029755e344618231e949260985da0c56f5e949cf0e04",
"from": "0xcAB17f9bbae2101C04c59ae4F9bCb0b3A2bd796D",
"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"receipt_contract_address": null,
"receipt_cumulative_gas_used": "6085263",
"receipt_gas_used": "60825",
"input": "0xa9059cbb0000000000000000000000000107d06317b0eba5eddccea1d66cdac29367569a000000000000000000000000000000000000000000000000000000000eda72bf",
"value": "0",
"nonce": "787",
"gas_price": "6733207173",
"gas": "99244",
"timestamp": 1696299599,
"block_hash": "0x7fa3d2c64c15a89b9a6c7a4261d6a25e7f3ba2e6992184a80f73a2ade5f61ff0",
"block_number": 18266988,
"tx_index": 52,
"status": true,
"effective_gas_price": "6733207173",
"logs_bloom": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000080000088000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000102000000000000000000000000000000000000000000000000100000000000000000000000000000000002000000000000000000000000000000000000000004000000000000000020000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
}
]
}
Congratulations 🥳 you just found the get transactions 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.