Skip to content

Hassam-SoftwareEng/CodeSentinel_Updated_Basic-Blockchain-in-Python-Task_2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Blockchain with Proof of Work

A Python-based blockchain simulation that demonstrates the fundamentals of blockchain, including block creation, Proof of Work, visualization, and tampering detection. This project helps in understanding how blockchains maintain integrity and security.

Features

✅ Add new blocks with custom data

✅ Proof of Work (PoW) with configurable difficulty

✅ Display block details: hash, nonce, mining time

✅ Visualize blockchain structure using networkx and matplotlib

✅ Validate the blockchain to detect tampered blocks

✅ Simulate blockchain tampering to see how the chain integrity breaks

Installation

Clone this repository:

git clone <YOUR_GITHUB_REPO_LINK> cd <YOUR_PROJECT_FOLDER>

Install required Python packages:

pip install networkx matplotlib

Optional for progress bars (if using tqdm):

pip install tqdm

Usage

Run the program:

python Updated_basic_blockchain.py

You will see an interactive menu:

Options:

  1. Add a new block
  2. Print blockchain
  3. Visualize blockchain
  4. Check blockchain validity
  5. Tamper a block
  6. Exit

Example Workflow

Add a block: Enter custom data. The block is mined using Proof of Work.

Print blockchain: See detailed info for each block (index, timestamp, hash, nonce, mining time).

Visualize blockchain: Shows a graphical structure of the chain with colors and arrows.

Check validity: Detect if any blocks have been tampered.

Tamper a block: Simulate a malicious change and check how the chain breaks.

Key Concepts Demonstrated

Proof of Work: Mining a block requires finding a hash with a certain number of leading zeros.

Block Integrity: Each block stores the hash of the previous block, linking the chain.

Blockchain Validation: The program verifies the integrity of the blockchain and detects tampering.

Visualization: Interactive graphical representation using networkx and matplotlib.

Sample Output Enter difficulty level (number of leading zeros in hash, e.g., 2-4): 2

Options:

  1. Add a new block
  2. Print blockchain
  3. Visualize blockchain
  4. Check blockchain validity
  5. Tamper a block
  6. Exit Enter your choice (1-6): 1 Enter data for the new block: Transaction A

Block 1 mined successfully! Hash: 00ab3f2c... Nonce: 345 Mining Time: 0.24 seconds

Enter your choice (1-6): 4 🔍 Checking blockchain validity... ✅ Blockchain is valid!

Dependencies

Python 3.x

networkx

matplotlib

Optional for enhanced mining progress visualization:

tqdm

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages