This library provides a core blockchain implementation accessible via REST APIs and stores data using LevelDB. The current release supports a single-node blockchain feature.
- Core blockchain functionality exposed as REST APIs
- Data persistence using LevelDB
- Single-node blockchain implementation
To use this library, you need to have Node.js installed.
To clone the repository
git clone https://github.com/gotocva/nilajs-blockchain.git
Open terminal inside the directory cd nilajs-blockchain
You can install the required dependencies using npm:
npm install
To start the Blockchain server, run:
node index.js
This will start the server on http://localhost:3000
.
Endpoint: POST /block
Description: Adds a new block/transaction to the blockchain with the specified data.
Request Body:
{
"data" : {
"from" : "aravind",
"to" : "boobalan",
"amount" : "125"
}
}
Response:
{
"index": 1,
"timestamp": "1718867161",
"data": {
"from": "aravind",
"to": "boobalan",
"amount": "125"
},
"nonce": 10457,
"previousHash": "00005042da8f149d499f3942ea5bf077e681e2d49e12a57e692a9fadbc99ec8f",
"hash": "0000931257811c594529f0474b50d8c0bd3d1a940e77cd4796235abf10aa8df1"
}
Endpoint: GET /blockchain
Description: Retrieves the entire blockchain.
Response:
[
{
"index": 0,
"timestamp": "1718866875",
"data": {
"title": "Genesis block of the blockchain",
"difficulty": 4,
"consensus": "Proof of work"
},
"nonce": 4104,
"previousHash": "0000XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"hash": "00005042da8f149d499f3942ea5bf077e681e2d49e12a57e692a9fadbc99ec8f"
},
{
"index": 1,
"timestamp": "1718867161",
"data": {
"from": "aravind",
"to": "boobalan",
"amount": "125"
},
"nonce": 10457,
"previousHash": "00005042da8f149d499f3942ea5bf077e681e2d49e12a57e692a9fadbc99ec8f",
"hash": "0000931257811c594529f0474b50d8c0bd3d1a940e77cd4796235abf10aa8df1"
}
]
curl -X POST http://localhost:3000/block -H "Content-Type: application/json" -d '{
"data" : {
"from" : "aravind",
"to" : "boobalan",
"amount" : "125"
}
}'
curl http://localhost:3000/blockchain
- Core Blockchain
- Proof of work - Consensus
- Persistant using Level DB
- REST API
- Blockchain Explorer
- Digital signature
- Distributed networks
- Broadcasting & Queuing the transactions
- Consensus for Peer to Peer
To contribute to this project, follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes
- Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature-branch
) - Open a pull request
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or issues, please open an issue on GitHub or contact me @ [email protected] || +91-8056359277