This chapter introduces peer-to-peer networking concepts to achieve decentralization in the blockchain network. This chapter also covers how blockchain is maintained in a decentralized network with the help of an example application.
(set up two connected nodes and mine 1 block)
install python version >= 3.5
pip install -r requirements.txt
PORT=3001 python main.py
PORT=3002 PEERS=ws://localhost:3001 python main.py
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
NOTE: Windows users might face an issue while installing a dependency (uvloop). So, windows users are advised to run the application using docker as mentioned in the next section.
Docker engine and Docker compose installation instructions can be found here.
(set up three connected nodes and mine a block)
docker-compose up
Additional node can be created by creating a new docker instance:
docker run --name chapter4_node1 --publish 0.0.0.0:6001:6001 chapter4_node1 /bin/bash -c "PORT=6001 python main.py
curl http://localhost:3001/blocks
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock
curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6001"}' http://localhost:3001/addPeer
curl http://localhost:3001/peers
The project of P2P blockchain application built in chapter 4 could be found here.