A simple blockchain implemented from scratch in Rust inspired by Bitcoin. This project is a learning exercise to understand the basic concepts of blockchain technology, including blocks, transactions, and consensus mechanisms.
I go in depth about these features in this Medium article.
- Proof of Work (PoW)
- Peer to peer communication
- Peer discovery
- Fork detection and resolution
- Block creation and validation
- Transaction validation
- Mempool implementation
- Postgres database
- Kubernetes & Helm deployment
- Client wallet GUI
- Rust (latest stable)
- Cargo
- PostgreSQL
- Optional: Docker, Kubernetes & Helm for dockerized deployment
git clone https://github.com/connormck333/blockchain.git
cd blockchain- Ensure PostgreSQL is running and accessible.
- Create a .env file and add the following variables:
POSTGRES_USERNAME=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhostcd node
cargo build --release- Host: the address that the node will listen on. E.g: http://localhost
- Port: the port that the node will listen on. E.g: 8080
- External IP: the address that other nodes will use to connect to this node.
- External Port: the port that other nodes will use to connect to this node.
cargo run full open <host>:<port> <external_ip>:<external_port>- Host: the address that the node will listen on. E.g: http://localhost
- Port: the port that the node will listen on. E.g: 8081
- Existing Node Host: the address of an existing node to join. E.g: http://127.0.0.1
- Existing Node Port: the port of an existing node to join. E.g: 8080
- External IP: the address that other nodes will use to connect to this node.
- External Port: the port that other nodes will use to connect to this node.
cargo run miner join <host>:<port> <existing_node_host>:<existing_node_port> <external_ip>:<external_port>cd ../wallet
cargo build --release
cargo run --releaseIf you prefer to run the blockchain in a Dockerized environment, you can use the provided Docker and Kubernetes configurations. I have provided a simple deployment script that uses Helm to deploy the blockchain nodes:
./deploy.shAnd to uninstall the deployment:
./stop.sh- Consider security requirements and implement necessary measures.
- Add more features like smart contracts, token standards, etc.
- Improve the wallet GUI with ability to view transactions and balances.
- Implement more advanced consensus mechanisms like Proof of Stake (PoS).