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
nodesendpoint:curl http://localhost:3000/nodesandcurl http://localhost:3001/nodesshould 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/transactionsandcurl http://localhost:3001/transactionsshould both show the same unprocessed transactions. -
Ask either one of the nodes to mine a new block:
curl -X POST http://localhost:3000/mineorcurl -X POST http://localhost:3001/mine -
Verify the transaction is added to the chain:
curl http://localhost:3000/chainandcurl http://localhost:3001/chain