MATRIX
Search
K
Comment on page

Accessing block info(JS, NodeJS), Beginner level

by Delbypoc
This tutorial is for educational purposes only, I’m not responsible for any losses, damages, or other liabilities which may occur by using any info/code provided here(or anywhere else it is posted).
Graphical user interface, text

Description automatically generated
I’m under no circumstances a Javascript professional (or a JS Ninja/Expert)!
The code is not production ready! (only for learning purposes)
In this guide, I’m going to show you how to access specific details from a block (for example transactions)
We will make use of the following package : ‘aiman’.
You can install it by using :
npm install aiman
We can initialize it with an HTTP provider like this:
If we would like to access info for the 5 mil block, for example, we can declare a variable then create a promise:
Text

Description automatically generated
After solving the promise we will be able to access the following details:
Graphical user interface, text

Description automatically generated
We can also access the transactions info which has the following details:
Text

Description automatically generated
In the next part I’m going to print the block hash + difficulty and all of the transactions hashes:
Text

Description automatically generated
The output for block 5.000.000 should look like this:
Text

Description automatically generated
Text

Description automatically generated
For more documentation you can check dev.matrix.io