A secure blockchain-powered voting system built with Python and Flask. Perfect for exploring blockchain, REST APIs, encryption, and secure digital voting in a distributed environment.
- ⚓️ Basic blockchain with Proof-of-Work (PoW)
- 🗳️ Cast votes using the
/vote
endpoint - ⛔️ Prevent double voting via hashed Voter IDs
- 🛠️ Mine pending votes into blocks via
/mine
- 🔍 View blockchain via
/chain
- 🌐 Flask-based REST API
- 🧑👷 Mining rewards for PoW
- 🔐 AES Vote Encryption to protect vote content
- 🔑 Decryption logic restricted to admin only
- 📅 Admin panel endpoints for vote result visibility
- 🔧 Registration and validation logic to manage voter eligibility
- 🌍 Multi-node network support
- 🧠 Consensus algorithm to maintain single source of truth
- 🔗 Node registration & broadcasting
- 🔄 Automatic chain syncing across nodes
- Python 3.x
- Flask
pycryptodome
(for AES encryption)- Requests (for inter-node communication)
-
Clone the repository
git clone https://github.com/yourusername/blockchain-voting-system.git cd blockchain-voting-system
-
Install dependencies
pip install flask pycryptodome requests
-
Run the app
python app.py
Server will run on http://127.0.0.1:5000
Method | Endpoint | Description |
---|---|---|
POST | /vote |
Submit an encrypted vote |
GET | /mine |
Mine votes into a block |
GET | /chain |
View the entire blockchain |
POST | /register |
Register a new voter |
POST | /admin/decrypt |
Admin-only endpoint to decrypt votes |
GET | /admin/results |
Admin-only endpoint to view vote counts |
POST | /nodes/register |
Register new nodes to the network |
GET | /nodes/resolve |
Consensus algorithm to resolve chain |
POST to /vote
:
{
"voterId": "your-unique-id",
"vote": "Alice"
}
voterId
is validated and hashed.- Vote is AES-encrypted.
- One vote per voter enforced.
- Registration: Voter registers once via
/register
. - Voting: Voter submits encrypted vote via
/vote
. - Mining: Pending votes are mined with PoW.
- Distributed Network:
- Nodes register with each other
- Chains are synced using a consensus algorithm
- Admin Panel:
- Admin-only decryption of votes
- Vote results accessible via
/admin/results
- Transparency: Public, traceable blockchain
- Integrity: Tamper-resistant records
- Security: Encrypted, validated, and permission-controlled
- Decentralization: No single point of failure
- Web-based voting interface
- Role-based access control (voter, admin, observer)
- Enhanced consensus via PBFT or Raft
This project helps you learn:
- Distributed blockchain mechanics
- Proof-of-Work & Consensus algorithms
- AES encryption for privacy
- Flask APIs for full-stack blockchain apps
- Designing secure, decentralized systems
Open-source under the MIT License