How to explore Data inside of Blockchain Network in Javascript

In this tutorial, we’re gonna build API that allows us to explore the data inside of our Blockchain Network. We will have ability to search the entire Blockchain for a specific Block by Hash, for a specific Transaction by Id. We can also fetch data from our Blockchain Network for a specific User/Address.

Previous Post: How to build Consensus Algorithm for Blockchain Network in Javascript

Explore Data Endpoints

We will make 3 endpoints:

– GET /block/:hash: shows a specific Block by :hash.
– GET /transaction/:id: shows a specific Transaction by Transaction’s :id.
– GET /address/:address: shows all Transactions that an :address is related to (address/user is a sender or a recipient).

These endpoints use 3 Blockchain class finder methods:

Practice

Implement Blockchain class Finder Methods

Inside blockchain.js file, add 3 methods to Blockchain class:

Find specific Block by Hash

Find specific Transaction by Transaction’s Id

Find all Transactions by Address/User

Explore Data Endpoints

Inside api.js file, add 3 endpoints:

Block by Hash

Transaction by Id

Data related to Address/User

Run & Check results

– Run the API on Terminal with command:
npm run node1

– Broadcast some Transactions and mine on node1, then check with url http://localhost:3001/blockchain:

– Find Block by Hash:

explore-data-blockchain-network-javascript-show-block-by-hash

– Find Transaction by Id:

explore-data-blockchain-network-javascript-show-transaction-by-id

– Find all Transactions by Address/User

explore-data-blockchain-network-javascript-show-transactions

Source Code

Blockchain-explore-data

By grokonez | June 15, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*