How to get transaction by version
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 version
In order to get transaction by version, Blocklens provides you a getTransactionByVersion endpoint to do so.
Here you'll need a parameter: txn_version
.
Once you've obtained the txn_version
, 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.getTransactionByVersion("275092708");
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": 96326594,
"timestamp": 1695663149,
"version": 275092708,
"type": "user_transaction",
"hash": "0xe38d8e28b163d6f1689d60506c066f1d17663fd9aa836f116bd89d6c3f7c2668",
"sender": "0x3e9aced3239e7bb01fdacc0610609ccc0cf207657640b1e19506e0132fc837ad",
"receiver": "null",
"function": "Vote::vote_project_12",
"amount": 0,
"gas_used": 505,
"accumulator_root_hash": "0x5f814bcdbd3bf979ba64999632ff9a8e1e7b24e4600f549521ff3236c9c9d5d5",
"block_hash": "0x28af54883944e96c651d0d26b98405adc738ef2102ba9a4dac09cc8a076f038d",
"epoch": -2147483648,
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"expiration_time": "2023-09-25 18:00:45",
"gas_unit_price": 100,
"max_gas_limit": 0,
"proposer": "null",
"round": -2147483648,
"sequence_number": 123,
"signature": "{\"public_key\":\"0xc34b148b10d4d28d666ef518d57ee187f876b76f8cff5bf1bfb892579bdc7820\",\"signature\":\"0x52d99958fcc00a7ce8d7303d1b28474e05de5579d60b5ec77b2addad31f752a328bc657fb636998678e27aa8c0b4b2b7332cd167ac54589c0b0b166f2a848b0b\",\"type\":\"ed25519_signature\"}",
"smart_contract": "0x79f9a2d4ae6722b4eaf905890126cd5100abf20f08431acae7ed7ea658e8357e",
"state_change_hash": "0x2c516b1148fccd19270767f1cde3e8513650208364e80b0ac1f028c57392a840",
"success": true,
"vm_status": "Executed successfully"
}
Congratulations 🥳 you just found the get transaction by version 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.