NighChain is a simple cryptocurrency system built using JavaScript. The blockchain stores transaction data and provides a mechanism to mine new blocks with basic validation. This project includes a backend API to interact with the blockchain and a frontend to visualize and mine new blocks.
This file contains the logic for the blockchain, including functions to:
- Create new blocks
- Ensure the validity of the chain by checking for hash collisions
- Handle transactions
This file is the backend API server hosted on port 8000. It handles CRUD operations for the blockchain, including endpoints for fetching the blockchain and mining new blocks.
A testing file used for development to ensure the backend logic works without the need for the front end.
This is the frontend page that users interact with to mine new blocks and view the blockchain ledger.
A JSON file that persists the blockchain data, ensuring it is not lost between server restarts.
To start the project, follow these steps:
-
Install the dependencies:
npm install
-
Start the backend API:
node server.js
-
Start the frontend by opening
index.html
in your browser.
GET /blocks
: Returns the current blockchain.POST /mine
: Mines a new block with the provided transaction data.
-
Mining a New Block To mine a new block, send a
POST
request to/mine
with the following JSON data:{ "amount": 100, "sender": "Alice", "recipient": "Bob" }
curl -X POST http://localhost:8000/mine -H "Content-Type: application/json" -d '{"amount": 100, "sender": "Alice", "recipient": "Bob"}'
curl http://localhost:8000/blocks