DecentralizedSMN is a Flask-based blockchain experiment that allows users in the same local network to create, share, and synchronize posts stored on IPFS, without relying on any central server.
Each device acts as an independent node, maintaining its own local blockchain, verifying integrity via cryptographic hashes, and syncing missing blocks automatically from peers.
- 🔒 Encrypted blockchain storage using
cryptography.fernet - 🌐 Peer-to-peer block synchronization over LAN (
fetchDevices.py) - 📦 IPFS-based content storage for decentralized posts
- 🧠 Local identity management (
userIDfile per node) - 💾 Persistent, verifiable blockchain in the
blocks/directory - ⚙️ Flask REST API for interacting with the blockchain
- 🧾 Automatic recovery & verification of all blocks on startup
DecentralizedSMN/
│
├── app.py # Main Flask blockchain app
├── fetchDevices.py # Local subnet scanner
├── ipfs_test.py # IPFS upload/retrieve module
├── DB_Constructor.py # (Optional) Database helper
├── blocks/ # Encrypted blockchain storage
├── templates/
│ ├── create_post.html # Post creation page
│ └── view_posts.html # Optional UI for viewing posts
└── userID # Generated per user on first run
git clone https://github.com/TheTechTiger/DecentralizedSMN.git
cd DecentralizedSMNpip install flask cryptography requestsYou may also need to install packages required by
fetchDevices.pyand your IPFS client.
Ensure ipfs_test.py implements these functions:
def ipfs_upload(content):
# Uploads text content to IPFS and returns its CID
...
def ipfs_retrieve(cid):
# Retrieves content from IPFS using the given CID
...Ensure fetchDevices.py includes:
def scan_all_subnets(port):
# Scans local subnets for active devices running this app
...python app.py- A new user ID (
userID) is generated. - You’ll be asked to enter your name.
- The app will create a genesis block if none exists.
The Flask server will start at:
http://0.0.0.0:1878
| Endpoint | Method | Description |
|---|---|---|
/block/<index> |
GET | Retrieve a specific block by index |
/blockcount |
GET | Get total block count |
/sync |
GET | Sync blockchain with other devices in the network |
/createPost |
GET/POST | Create a new post (stored on IPFS) |
/viewPosts/ |
GET | View posts (paginated, 10 per page) |
/updateBlockchain |
POST | Replace local blockchain with provided JSON |
Each block includes metadata and a hash link to the previous chain state:
{
"action": "create_post" | "create_acc" | "genesis",
"hash": "<sha256_of_previous_chain>",
"data": {
"cid": "<ipfs_cid>",
"token": "<user_token>"
},
"name": "<username>",
"token": "<unique_user_id>"
}-
Each block’s
hashis derived from the entire previous chain to maintain integrity. -
Blockchain files are encrypted per block using:
key = b'65A100d105i116t105i97a107k104h105iTechTiger='
curl -X POST -F "content=Hello, decentralized world!" http://localhost:1878/createPostcurl http://localhost:1878/viewPosts/curl http://localhost:1878/synccurl http://localhost:1878/blockcount- Each node stores encrypted blocks in
blocks/. - Nodes use
fetchDevices.pyto discover peers on the same subnet. - Missing blocks are fetched automatically from other devices.
- Posts are uploaded to IPFS for decentralized content delivery.
- All updates are cryptographically verified and appended to the local blockchain.
- Blocks are encrypted with a symmetric Fernet key.
- Each node must use the same key to decrypt and verify incoming blocks.
- The system ensures data consistency and tamper resistance across nodes.
This project is released under the MIT License. You are free to use, modify, and distribute it with attribution.
- ✅ Digital signatures for user validation
- ✅ Web dashboard for browsing posts
- ✅ Peer discovery via UDP broadcast
- ✅ Multi-gateway IPFS support
- ✅ Optional encryption for post content
GitHub: https://github.com/TheTechTiger/DecentralizedSMN
Built with ❤️ by TheTechTiger
"A small step towards decentralized micro-networks."