Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Blockchain Simulation in JavaScript

A minimal blockchain simulation to demonstrate key blockchain concepts such as block linking, hashing, validation, and proof-of-work.


Getting Started

Prerequisites

  • Node.js (v18+ recommended)
  • npm

Installation

npm install

Run the Simulation

npm start

Features

  • Add dummy transactions before mining
  • Mine blocks with proof-of-work
  • Print the blockchain
  • Tamper with the blockchain and detect it using validation
  • Modular code with Block and Blockchain classes

Project Structure

.
├── blockchain.js        # Block and Blockchain class definitions
├── index.js             # Driver code to run the simulation
├── package.json         # Node.js project metadata and scripts
└── README.md            # Project overview and instructions

Evaluation Criteria

Functionality

  • ✅ Blockchain with Linked Blocks:
    Each block contains a reference (previousHash) to the hash of the previous block, ensuring a linked structure that mimics real-world blockchains.

  • ✅ Validation Method:
    The isChainValid() method verifies:

    • The integrity of each block’s hash.
    • The correctness of the block linkage via previousHash.
      Tampering with any block's data will break the chain’s integrity and be detected.

Code Quality

  • ✅ Well-Structured and Modular:
    The project uses object-oriented design with:

    • A Block class (handles hashing and mining logic).
    • A Blockchain class (manages the chain, validation, and transactions).
  • ✅ Readable Code:
    Variable names are descriptive, and the logic follows a clean, intuitive flow.

  • ⚠️ Comments:
    While the code is mostly self-explanatory, basic inline comments can be added to enhance understanding for newer developers.


Optional Bonus Features

  • ✅ Proof-of-Work (PoW):
    Implemented in the mineBlock() method using a configurable difficulty level. Blocks are mined only when their hash starts with a specific number of leading zeroes (e.g., "000" for difficulty 3), simulating computational effort.

  • ✅ Dynamic Transactions:
    Transactions are added using createTransaction() and grouped into blocks during minePendingTransactions() — allowing multiple transactions per block before mining.


Docker (Optional)

Build and Run with Docker

docker build -t simple-blockchain .
docker run simple-blockchain

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages