Skip to content

gotocva/nilajs-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blockchain Library

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.

Features

  • Core blockchain functionality exposed as REST APIs
  • Data persistence using LevelDB
  • Single-node blockchain implementation

Installation

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

Usage

Running the Server

To start the Blockchain server, run:

node index.js

This will start the server on http://localhost:3000.

REST API Endpoints

Add a New Block/Transaction

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"
}

Get Blockchain

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"
  }
]

Example

Adding a New Block

curl -X POST http://localhost:3000/block -H "Content-Type: application/json" -d '{
    "data" : {
        "from" : "aravind",
        "to" : "boobalan",
        "amount" : "125"
    }
}'

Retrieving the Blockchain

curl http://localhost:3000/blockchain

Roadmap

  • 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

Development

To contribute to this project, follow these steps:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some feature')
  5. Push to the branch (git push origin feature-branch)
  6. Open a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For any questions or issues, please open an issue on GitHub or contact me @ [email protected] || +91-8056359277

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published