Skip to main content

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.APTOS_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.eyJpZCI6MjgzMzMyMjMxLCJwYWdlIjoxLCJpYXQiOjE2OTcwNjEzMjF9.BM1hfmhTlZfPt7Vxd4mBwrKWRQUqU7a4UxT9Z4B_Ebs",
"page": 1,
"limit": 20,
"total_items": 1,
"data": [
{
"block_height": 98983174,
"timestamp": 1696299683,
"version": 283332250,
"type": "state_checkpoint_transaction",
"hash": "0x2c441f8695ec138456d4ae5539a249e23f6490662c7bdda371f19e0c2f506a36",
"sender": "null",
"receiver": "null",
"function": "null",
"amount": 0,
"gas_used": 0,
"accumulator_root_hash": "0x369b9cf1d7f4a4c1735bac195a85d63511493a2fa05146fa7188376fa131fc36",
"block_hash": "0xf6ae240f9905b4fbe20e101d6f1c47f94d062082641428f4a17f6305e981918d",
"epoch": -2147483648,
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"expiration_time": "2023-10-03 02:21:23",
"gas_unit_price": 0,
"max_gas_limit": 0,
"proposer": "null",
"round": -2147483648,
"sequence_number": 0,
"signature": "null",
"smart_contract": "null",
"state_change_hash": "0xafb6e14fe47d850fd0a7395bcfb997ffacf4715e0f895cc162c218e4a7564bc6",
"success": true,
"vm_status": "Executed successfully"
}
]
}

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.