A lightweight, educational blockchain implementation in Python designed to help beginners understand the fundamental concepts of blockchain technology.
Simplicity Blockchain is an intuitive implementation that demonstrates core blockchain concepts including decentralized consensus, proof-of-work mining, cryptographic verification, and distributed ledger technology. Built with Python and Firebase, it provides a hands-on learning platform for blockchain fundamentals while remaining accessible to beginners.
- Core Blockchain Components: Blocks, transactions, and cryptographic linking
- Proof of Work Mining: Educational implementation of mining mechanics
- Digital Signatures: ECDSA-based transaction authentication
- Decentralized Network: Node discovery and peer-to-peer communication
- Consensus Algorithm: Chain validation and conflict resolution
- Mining Rewards: Coinbase transaction implementation
- Data Persistence: Firebase integration for reliable storage
- Node Management: TTL-based network coordination
- RESTful API: HTTP interfaces for blockchain interaction
The system follows a modular architecture with three primary layers:
┌─────────────────────────────────────────┐
│ Simplicity Blockchain │
└──────────────┬──────────────────────────┘
│
┌─────────┴─────────┐
▼ ▼ ▼
┌──────────┐ ┌─────────────┐ ┌──────────────┐
│ Core │ │ Network │ │ Persistence │
│ Layer │ │ Layer │ │ Layer │
└──────────┘ └─────────────┘ └──────────────┘
Each block in the chain contains:
┌─────────────────────────────┐
│ Block │
│ │
│ ┌─────────────────────────┐ │
│ │ Header │ │
│ │ - Index │ │
│ │ - Timestamp │ │
│ │ - Previous Hash │ │
│ │ - Merkle Root │ │
│ │ - Nonce (Proof) │ │
│ └─────────────────────────┘ │
│ │
│ ┌─────────────────────────┐ │
│ │ Transactions │ │
│ │ - Transaction 1 │ │
│ │ - Transaction 2 │ │
│ │ - ... │ │
│ └─────────────────────────┘ │
└─────────────────────────────┘
# Clone the repository
git clone https://github.com/affanshaikhsurab/simplicity-server.git
cd simplicity-blockchain
# Install required dependencies
pip install -r requirements.txt
# Configure Firebase credentials
# 1. Create a Firebase project at https://console.firebase.google.com/
# 2. Generate a service account key file
# 3. Save the JSON file to the project directory as firebase-credentials.json
# Start the primary node
python app.py
# Start additional nodes on different ports
python app.py --port 5001
Once your nodes are running, you can interact with them using the API:
-
View the blockchain:
GET http://localhost:5000/chain
-
Mine a new block:
GET http://localhost:5000/mine
-
Submit a transaction:
POST http://localhost:5000/transactions/new
With JSON body:
{ "transaction": { "sender": "sender_address", "recipient": "recipient_address", "amount": 5.0 }, "digital_signature": "base64_encoded_signature", "public_key": "base64_encoded_public_key" }
-
Register new nodes:
POST http://localhost:5000/nodes/register
With JSON body:
{ "nodes": ["http://localhost:5001", "http://localhost:5002"] }
-
Resolve conflicts:
GET http://localhost:5000/nodes/resolve
File | Description |
---|---|
blockchain.py | Core blockchain implementation, handling blocks, transactions, and mining |
database.py | Firebase integration for blockchain persistence |
account_db.py | Account management and key pair operations |
nodeManager.py | Network node discovery and management |
app.py | Flask API server exposing blockchain functionality |
The mining process follows these steps:
- Transaction Selection: Pending transactions are selected from the pool
- Coinbase Creation: A reward transaction is created for the miner
- Proof of Work: A nonce is found that creates a block hash with the target difficulty
- Block Construction: The new block is assembled with transactions and proof
- Network Propagation: The new block is broadcast to all nodes
- Validation: Other nodes verify the block before adding it to their chain
Transactions are secured using ECDSA (Elliptic Curve Digital Signature Algorithm):
- Sender creates and signs transaction with their private key
- Transaction and sender's public key are broadcast to the network
- Nodes verify the signature using the provided public key
- Valid transactions are added to the mining pool
Contributions are welcome! Please see our contribution guidelines for details.
Development Environment Setup:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# Windows:
venv\Scripts\activate
# Unix/MacOS:
source venv/bin/activate
# Install development dependencies
pip install -r requirements-dev.txt
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or support:
- GitHub Issues: https://github.com/yourusername/simplicity-blockchain/issues
- Email: [email protected]
Built with ❤️ for blockchain education