MoByte is a decentralized blockchain built in Python and Flask. Created for educational and experimental purposes, it demonstrates the fundamentals of distributed ledger systems — including mining, proof-of-work, transactions, and network synchronization between nodes.
- Complete Blockchain Implementation – Includes mining, proof-of-work, hashing, and validation.
- Transaction System – Send and receive simulated cryptocurrency between users.
- Network Consensus – Synchronize and validate blocks across multiple nodes.
- Dynamic Node Discovery – Connect multiple Flask instances into a shared decentralized network.
- REST API Interface – Simple, human-readable JSON endpoints.
- Lightweight & Docker-Ready – Easy to deploy and experiment with locally or across multiple servers.
/MoByte
|-- main.py # Flask app with API endpoints
|-- blockchain.py # Core blockchain logic
|-- node.json # List of connected nodes
|-- transaction.json # Example transaction format
|-- Dockerfile # Instructions to build the Docker image
|-- docker-compose.yml # Defines the Docker service
|-- Pipfile # Lists project dependencies for pipenv
|-- Pipfile.lock # Locks dependency versions for reproducibility
|-- LICENSE # Apache 2.0 License
└── README.md # You're here!
You’ll need:
- Python 3.13+
- Flask
- pipenv (for dependency management)
- (Optional) Docker and Docker Compose for isolated deployment
-
Clone the Repository
git clone <your-repo-url> cd MoByte
-
Install Dependencies (if running locally)
pip install flask requests
-
Run the Main Node
python3 app.py --port 5001
You’ll see output like:
* Running on http://0.0.0.0:5001
You can interact with MoByte through its REST API using Postman or curl.
-
URL:
/get_chain -
Method:
GET -
Example:
curl http://localhost:5001/get_chain
-
URL:
/mine_block -
Method:
GET -
Example:
curl http://localhost:5001/mine_block
-
URL:
/add_transaction -
Method:
POST -
Body (JSON):
{ "sender": "Mahmoud", "receiver": "Ali", "amount": 20 } -
Example (curl):
curl -X POST http://localhost:5001/add_transaction \ -H "Content-Type: application/json" \ -d '{"sender":"Mahmoud","receiver":"Ali","amount":20}'
Used to link other blockchain nodes together.
-
URL:
/connect_node -
Method:
POST -
Body (JSON):
{ "nodes": [ "http://127.0.0.1:5001", "http://127.0.0.1:5002", "http://127.0.0.1:5003" ] }
Synchronizes the blockchain with the longest valid one across all connected nodes.
-
URL:
/replace_chain -
Method:
GET -
Example:
curl http://localhost:5001/replace_chain
-
URL:
/is_valid -
Method:
GET -
Example:
curl http://localhost:5001/is_valid
You can simulate a decentralized network by running several instances:
python3 app.py --port 5001
python3 app.py --port 5002
python3 app.py --port 5003Then, connect them via:
POST /connect_node
{
"nodes": [
"http://127.0.0.1:5001",
"http://127.0.0.1:5002",
"http://127.0.0.1:5003"
]
}Now each node will share and synchronize blocks automatically when /replace_chain is called.
-
Open Postman
- Click New → HTTP Request
- Select method
GETorPOSTdepending on the endpoint.
-
Enter the URL
-
Example:
http://localhost:5001/mine_blockor
http://localhost:5001/add_transaction
-
-
For POST requests
-
Choose Body → raw → JSON
-
Paste JSON like:
{ "sender": "Mahmoud", "receiver": "Node-2", "amount": 50 }
-
-
Send the Request
- Click Send
- You’ll see a JSON response with the block details or confirmation.
-
Mine the Next Block
- After adding transactions, call
/mine_blockagain to record them into the chain.
- After adding transactions, call
-
Check the Chain
- View your blockchain data via
/get_chain.
- View your blockchain data via
- Implement digital signatures for secure transactions
- Add a simple web dashboard to visualize blocks
- Create persistent storage using SQLite or LevelDB
- Deploy nodes across multiple servers for real P2P networking
- Build a MoByte token wallet system
This project is configured to run seamlessly inside a Docker container.
- Docker: Ensure Docker Desktop (for Mac/Windows) or Docker Engine (for Linux) is installed and running.
- Docker Compose: Included with Docker Desktop. For Linux, you might need to install it separately.
-
Build the Image & Run the Container The
docker-compose upcommand orchestrates the entire process. The--buildflag ensures the image is built from theDockerfile, and-druns it in detached mode.docker compose up --build -d
-
Verify the Container is Running You can check the status of your running containers with:
docker ps
You should see a container named
mo-byterunning and forwarding port5001to5000. -
Access the container
docker compose exec app bash -
Run the main script
python3 main.py
-
Next: Interact via API Once it’s running, follow the steps in the How to Use section to test your endpoints (e.g.,
/mine_block,/add_transaction,/get_chain, etc.).
Make sure ports are mapped correctly (
5001:5001) in yourdocker-compose.ymlso Postman or curl can access the API.
-
Viewing Logs: To see the output from the Flask application inside the container:
docker compose logs -f
-
Accessing a Shell Inside the Container: For debugging, you can get an interactive shell inside the running container:
docker compose exec app bashThis will place you inside the
/appdirectory, where you can run commands.
To stop and remove the containers defined by Docker Compose:
docker compose down- Add Transactions: Modify the block structure to include a list of transactions, making the blockchain useful for more than just demonstrating proof-of-work.
- Decentralized Network: Implement a network of nodes where chains can be synchronized and consensus is reached across multiple participants.
- Wallet and Signatures: Add the ability to create cryptographic key pairs (wallets) and sign transactions.
- Enhanced Testing: Write comprehensive unit and integration tests for the blockchain logic and API endpoints.
- Web Interface: Create a simple front-end to visualize the blockchain and interact with the API.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
