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).

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:

After solving the promise we will be able to access the following details:

We can also access the transactions info which has the following details:

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

The output for block 5.000.000 should look like this:

Whole program (https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/blob/main/js/sendManTransaction.js)

For more documentation you can check dev.matrix.io

Last updated