Skip to main content

How to get transaction by hash

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 transaction by hash

In order to get transaction by hash, Blocklens provides you a getTransactionByHash endpoint to do so.

Here you'll need a parameter: txn_hash.

Once you've obtained the txn_hash, 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.APTOS_MAINNET.getTransactionByHash("0xe197e9f590b30b50e301062c4ed2db859da82e8c862c43f345063d6c4c3348f1");
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:

{
"block_height": 1,
"block_time": "2023-06-14 14:14:42.380",
"timestamp": 1,
"version": 1,
"type": "block_metadata_transaction",
"hash": "0xbf3d139d0bbe68f1db6d393b135c2ed12ab5ec1635f08b26994180d1e6434dd1",
"sender": "0xe0a2Bd4258D2768837BAa26A28fE71Dc079f84c7",
"receiver": "0x8b24Eb4E6aAe906058242D83e51fB077370c4720",
"function": "function",
"amount": 1,
"gas_used": 1,
"accumulator_root_hash": "0xf77a94a0b67490ebe6ad9e4554d5952dc49f31df4de25bca40351acbda7091d4",
"block_hash": "0x6b1180117397f7d1d89f5fa0ef50f95b86cd55e7ccaafb60efce8e05ad40d144",
"epoch": "4118",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"expiration_time": "2023-09-20 03:19:29",
"gas_unit_price": "100",
"max_gas_limit": "0",
"proposer": "0x15d241369552ece871a16d865a4e9b96f5e6e6f8c7db5478e89af17845969c02",
"round": "-2147483648",
"sequence_number": "5576670",
"signature": "null",
"smart_contract": "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387",
"state_change_hash": "0xafb6e14fe47d850fd0a7395bcfb997ffacf4715e0f895cc162c218e4a7564bc6",
"success": true,
"vm_status": "Executed successfully"
}

Congratulations 🥳 you just found the get transaction by hash 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.