How to get blocks
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 blocks
In order to get blocks, Blocklens provides you a getBlocks 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.getBlocks();
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.eyJpZCI6OTg5ODMxNzQsInBhZ2UiOjEsImlhdCI6MTY5NzA1NzAyNn0.bM2BWgEnCu1VCMo3fOmRd4Bu3zqanBanuoDfkWyeut0",
"page": 1,
"limit": 1,
"total_items": 1,
"data": [
{
"block_height": 98983174,
"block_hash": "0xf6ae240f9905b4fbe20e101d6f1c47f94d062082641428f4a17f6305e981918d",
"timestamp": 1696299683,
"first_version": 283332249,
"last_version": 283332250,
"epoch": 4276,
"round": 8729,
"total_transactions": 2,
"proposer": "0xef191e643c2ed2d103de4109a506e020f5dde818cbc1ffe5e4ee36328cd22e9b"
}
]
}
Congratulations 🥳 you just found the get blocks 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.