A minimal blockchain implementation in Python featuring transaction support, Proof of Work, and a RESTful API powered by Flask.
Blockchain data structure with block linking via hashes.
Simple Proof of Work (PoW) algorithm.
Transaction pool integrated into mined blocks.
RESTful API with endpoints to mine, view the chain, validate it, and add transactions.
Demonstrates fundamental blockchain concepts.
Endpoint Method Description
/mine_block GET Mines a new block and adds it to chain
/get_chain GET Retrieves the full blockchain
/is_valid GET Validates the blockchain integrity
/add_transaction POST Adds a new transaction
Blockchain Structure Each block contains:
index
timestamp
proof (Proof of Work)
previous_hash
Transactions
Added via /add_transaction.
Stored in a pending transaction pool.
Included in the next mined block.
Simple algorithm finding a number such that:
SHA256(new_proof² - previous_proof²) → hash starts with '00000'.
Ensures each block's hash correctly references its predecessor and PoW is valid.
Clone the repo:
git clone https://github.com/yourusername/blockchain-python.git
cd blockchain-python
Install dependencies:
pip install flaskRun the Flask app:
python blockchain.pyAccess API at:
Add a transaction:
curl -X POST -H "Content-Type: application/json" \
-d '{"sender": "Alice", "recipient": "Bob", "amount": 50}' \
http://127.0.0.1:5000/add_transaction
Mine a block:
curl http://127.0.0.1:5000/mine_block
Check the chain:
curl http://127.0.0.1:5000/get_chain
🖼️ Blockchain Flow
[User Input]
↓
new_transaction(sender, recipient, amount)
↓
[Transactions Pool]
↓
mine_block()
↓
[Proof of Work]
↓
[create_block(proof, previous_hash, transactions)]
↓
[Append to Chain]
↓
[Clear Transactions]
Open Postman → New → HTTP Request.
Set method to POST.
URL: http://127.0.0.1:5000/add_transaction.
Body → raw → JSON:
{
"sender": "Alice",
"recipient": "Bob",
"amount": 50
}
If you get stuck, please refer to my page.
✅ Blockchain implemented from scratch.
✅ Transactions added to blocks.
✅ Simple Proof of Work.
✅ REST API via Flask.
✅ Testing with curl or Postman.