Blockchain build with JavaScript on node js
- A proof of work algorithm to secure the network.
- Hashing algorithms to secure the data within the blockchain.
- The ability to mine (create) new blocks that contain data.
- The ability to create transactions and store them in blocks.
- An API/server that will be used to interact with the blockchain from the internet.
- It will be hosted on a decentralized blockchain network.
- A consensus algorithms to verify that the network nodes have valid data and are synchronized.
- A broadcasting system to keep the data in the blockchain network synchronized.
to run the app, outside the "dev" directory , execute in cmd or shell :npm run node_<1 to 5>
egnpm run node_1
,npm run node_2
etc. For node_1, port is 3000 For node_2, port is 3001 and vice versa till node_5 As no. of nodes here represents the number of devices in a network, therefore to run a node, typenpm run node_1
Run these command in separate shell or teminal
Prefer Postman for this application
-
to get the blockchain, use
GET http://localhost:3001/bloclchain
the first block is the genesis block. -
to Add a device in the network,
POST http://localhost:3001/register-and-broadcast-node
.In the request body type
{ "newNetworkNode":"http://localhost:30002" }
or the node you want to add. You can add new node from any running node with this format. -
To mine a block , type
GET http://localhost:3001/mine
. You can mine from any url in the network and it will be syncronised to every node present in the network.
Now a minig reward is given to the miner and is saved in the pending transaction, and will not show in ledger unless another block is mined
-
for transaction
POST http://localhost:3001/transaction/broadcast
and in the request body , type{ "sender":"","recipient":"","amount":"" }
. It will add the transaction to ythe pending transaction of all the nodes in the network and is removed from the transaction unless a new bock in mined. -
If you add the new node in the network, and done minig and transactions and want to synchronize it with the other nodes in the network , then use consensus
GET http://localhost:3001/consensus
make sure you run this from the node you want to add. -
if you want to search the block by its hash, address or the transactionId, then use :-
GET http://localhost:3001/block/:blochash
-
You can also use the link
GET http://localhost:3001/block-explorer
to search the blocks after entring the details