Accessing block info(JS, NodeJS), Beginner level
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).
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: