Skip to content

connormck333/Blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Blockchain

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.

Features

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

Requirements

  • Rust (latest stable)
  • Cargo
  • PostgreSQL
  • Optional: Docker, Kubernetes & Helm for dockerized deployment

Usage

1. Clone the repository

git clone https://github.com/connormck333/blockchain.git
cd blockchain

2. Set up the database

  • 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=localhost

3. Build the project

cd node
cargo build --release

4. Run the opening node

  • 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>

5. Run miner nodes

  • 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>

6. Build and run the wallet GUI

cd ../wallet
cargo build --release
cargo run --release

Alternative: Dockerized Deployment

If 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.sh

And to uninstall the deployment:

./stop.sh

Future Work

  • 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).

About

Building a blockchain in Rust from scratch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published