A Blockchain-Based Messaging and Transaction Platform
BlockChat is an innovative platform developed as part of the Distributed Systems course at the National Technical University of Athens, School of Electrical and Computer Engineering. It leverages blockchain technology to provide a secure and decentralized environment for exchanging messages and conducting transactions with BlockChat Coins (BCC). By implementing a Proof of Stake (PoS) consensus algorithm, BlockChat ensures a secure and efficient mechanism for transaction validation and consensus across the network.
- Altan Avtzi - el19241
- Xhonatan Lukaj - el19230
The primary goal of BlockChat is to create a distributed platform where users can safely and reliably send messages and conduct transactions without the need for a central authority. This project aims not only to demonstrate the practical application of blockchain technology beyond cryptocurrencies but also to explore the advantages of the Proof of Stake mechanism in ensuring network consensus and security.
- Wallet Implementation: Each user (node) must have a unique wallet containing a pair of public and private keys. The public key serves as the wallet address for receiving messages and transactions, while the private key is used for signing transactions to ensure their authenticity.
- Transaction Types: The platform should support two types of transactions: coin transfers and message exchanges. Each transaction must be signed by the sender's private key and verified by network nodes.
- Consensus Algorithm: Utilize a Proof of Stake algorithm to select validators for new blocks based on the amount of BCC staked by each node. This approach aims to provide a more energy-efficient alternative to Proof of Work systems.
- Network Communication: Nodes should communicate over a distributed network, with capabilities for transaction broadcasting and block validation following the consensus rules.
- Security Features: Implement security measures such as transaction nonce for preventing replay attacks and ensuring the integrity and order of transactions.
Throughout the development of BlockChat, several key learnings emerged:
- Blockchain Fundamentals: Deepened understanding of blockchain technology's core principles, including decentralization, immutability, and consensus models.
- Proof of Stake Mechanism: Gained insights into the PoS algorithm, exploring its advantages in energy efficiency and stake-based validator selection over traditional PoW systems.
- Cryptographic Security: Enhanced knowledge of cryptographic techniques such as digital signatures for securing transactions and ensuring the authenticity and integrity of messages within the network.
- Distributed Systems Challenges: Faced and addressed common challenges in distributed systems, including network synchronization, consensus achievement, and data consistency across nodes.
- Practical Application of Theoretical Concepts: Applied theoretical concepts from the Distributed Systems course to a real-world project, bridging the gap between academic learning and practical implementation.
BlockChat is developed in Python, leveraging its versatility and the extensive libraries available for building secure and efficient blockchain applications. The project is structured to run in any environment where Python is supported, including Windows, macOS, and Linux operating systems.
- cryptography: Public/private key pairs, sign transactions, and verify signatures.
- prompt_toolkit: CLI prompts.
dist/: Distributable packagesdocs/: Documentation, including the project assignment.scripts/: Utility scripts.src/: Source code directory.blockchat/: Main package folder.input/: Sample transaction files.main/: Application entry point.cli/: Command-line interface.gui/: Placeholder for future graphical interface.
util/: Utility modules, e.g.,termcolor.pyfor colored console output.- Core modules:
block.py,blockchain.py,bootstrap.py,client.py,node.py,transaction.py,wallet.py.
tests/: Testing directory with transaction samples.Dockerfile: Docker container setup.pyproject.toml,setup.py: Build and distribution configuration.requirements.txt: External dependencies list.
After cloning the repository, you can install blockchat as a package, or run on docker container:
- Create a virtual environment and activate it (optional):
python -m venv venvthen:
source venv/bin/activate- Install
buildif not already installed:
python -m pip install --upgrade build- Install dependencies from
requirements.txt:
pip install -r requirements.txt- Build package with
build:
python -m build- Install the package from
dist/
pip install dist/*.whl- Build the
blockchatimage:
docker build -t blockchat-image .- Create the
blockchatblockchain network:
docker network create blockchat-networkpython -m blockchat -h- Example for 5 nodes and 10 block capacity and stake 10BCC:
python -m blockchat --nodes=5 --capacity=10 --stake=10Note
With this command, a new client node connects to the blockchain network and provides a console-prompt cli for commands. To see more options, emit the -h flag.
- To start a bootstrap node, example:
python -m blockchat --bootstrap --nodes=5 --capacity=10 --stake=10- Example options:
docker run --name client-node --network blockchat-network blockchat-image:latest python -u -m blockchat -n 2 -c 5 -s 10 -td- Bootstrap example:
docker run --name bootstrap-node --network blockchat-network blockchat-image:latest python -u -m blockchat -n 2 -c 5 -s 10 -td -bImportant
Make sure you emit -d at the end and --name is always bootstap-node for bootstrap when using with docker
- To run a node again:
docker start -a client-nodepython tests/test_main.py -n 5 -c 10 -s 10 -vdBlockChat is released under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. This means the software is free to be used for any purpose, to be modified and shared without any restrictions. For more details, see the LICENSE.