This is a simple blockchain implementation in JavaScript using Node.js and the built-in crypto module. The project demonstrates the fundamental concepts of blockchain, including block creation, proof-of-work, and chain validation.
- Block structure with SHA-256 hashing
- Proof-of-Work (PoW) mechanism for mining
- Genesis block creation
- Adding new blocks to the chain
- Blockchain integrity validation
- Demonstrates tampering detection
Ensure you have Node.js installed on your system. You can check by running:
node -vClone the repository and navigate to the project folder:
git clone https://github.com/your-repo/blockchain-js.git
cd blockchain-jsRun the blockchain script using Node.js:
node blockchain.jsDefines a block with an index, timestamp, transactions, previous hash, nonce, and hash. The calculateHash method generates a SHA-256 hash, and mineBlock performs proof-of-work.
Manages the blockchain, including:
- Genesis block creation
- Adding new blocks
- Validating the blockchain integrity
The script initializes a blockchain, mines two blocks, and validates the chain. It also demonstrates blockchain tampering detection.
Mining Block 1...
Block mined: <hash>
Mining Block 2...
Block mined: <hash>
Blockchain: {...}
Is blockchain valid? true
Is blockchain valid after tampering? false
This project is licensed under the MIT License.
Deepesh Singh Rathore