This repository shows a simple blockchain network implementation. Each instance can be considered a blockchain node. You can use the API endpoints defined in routes.js
to interact with the nodes.
Launch a node by running node index.js --port <PORT>
(defaults to port 3000)
- Launch two nodes:
node index.jes --port 3000
node index.jes --port 3001
-
Register node:
curl -X POST http://localhost:3000/register --data '{"address":"http://localhost:3001"}'
-
Verify node is registered by retrieving the
nodes
endpoint:curl http://localhost:3000/nodes
andcurl http://localhost:3001/nodes
should both show the other node as registered. -
Add a transaction:
curl -X POST http://localhost:3000/transaction --data '{"from":"hank","to":"walter","qty":7}'
-
Add another transaction:
curl -X POST http://localhost:3000/transaction --data '{"from":"saul","to":"gus","qty":3}'
-
Verify the transactions are added to the transaction pool on both nodes:
curl http://localhost:3001/transactions
andcurl http://localhost:3001/transactions
should both show the same unprocessed transactions. -
Ask either one of the nodes to mine a new block:
curl -X POST http://localhost:3000/mine
orcurl -X POST http://localhost:3001/mine
-
Verify the transaction is added to the chain:
curl http://localhost:3000/chain
andcurl http://localhost:3001/chain