A simple test blockchain and cryptocurrency implementation in JavaScript using express.
- Clone the project using
`git clone https://github.com/ashwinrisbood/Blockchain.git - Install packages by running
npm install
- Create Clients and join them as peers.
- By default clients are created serving API on 3000 and p2p on 8000.
- Create the first client by running npm start.
- Create the second client by passing additional parameters for
- HTTP_PORT = POrt to run the HTTP server
- P2P_PORT = Port to run the P2p client
- PEERS = comma separated address of Peers in P2p connection
for example:
HTTP_PORT=3001 P2P_PORT=8001 PEERS=block://localhost:8000 npm start
- Create API requests to run blockchain functions.
An example flow of blockchain operations
-
GET public key of one of the nodes using /public-key for example: GET
localhost:3000/public-key
Response: { "publicKey": "04b406d69697ecc5..." } -
POST transactions from on of the clients to this address using /transact and providing { "recipient": "04b406d69697ecc5...", "amount": 50 }
-
Check transactions on any of the clients using GET /transactions
-
Mine the transaction using a client into the blockchain by calling GET on /mine-transactions.
NOTE: The client that Mines recieves a 50 unit crypto for his processing. this is visible in the blockchain that is returned in response to /mine-transactions.
Pending Feature additions:
- dynamic add node