Skip to content

Zambacoin is a modular educational blockchain in Python with mining, transactions, node sync, and basic consensus.

Notifications You must be signed in to change notification settings

fezamba/python-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning Blockchain with Python

Personal learning project I built to understand how blockchains work under the hood.
It's written in Python using Flask and simulates core concepts like Proof of Work mining, transactions, basic consensus, and multi-node synchronization — all in a simple, readable structure.

This isn't production-ready — it's just me exploring how to actually build a blockchain from scratch, step by step.


Project Structure

python-blockchain/
├── core/                  # Blockchain logic
│   └── blockchain.py
├── api/                   # REST API with Flask
│   └── routes.py
├── run.py                 # Main entrypoint
├── requirements.txt
└── README.md

🚀 How to Run

  1. Install dependencies:
pip install -r requirements.txt
  1. Launch multiple nodes:
python run.py 5001
python run.py 5002
python run.py 5003
  1. Use /connect_node and /replace_chain to sync them.

📡 Endpoints Overview

Method Endpoint What it does
GET /mine_block Mines a block with PoW
GET /get_chain Returns the full chain
GET /is_valid Validates the chain
POST /add_transaction Adds a new transaction (JSON: sender, receiver, amount)
POST /connect_node Connects other nodes (JSON: list of node URLs)
GET /replace_chain Syncs with the longest valid chain among connected nodes

📦 Sample Payloads

POST /add_transaction

{
  "sender": "Alice",
  "receiver": "Bob",
  "amount": 50
}

POST /connect_node

{
  "nodes": [
    "http://127.0.0.1:5002",
    "http://127.0.0.1:5003"
  ]
}

🔁 Node Sync Tip

To sync multiple nodes:

  1. Run /connect_node from one of them
  2. Call /replace_chain on the others to update to the longest valid chain

📄 License

MIT — use this code for learning, remixing, or building your own version.

About

Zambacoin is a modular educational blockchain in Python with mining, transactions, node sync, and basic consensus.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published