A complete blockchain implementation written in Rust, featuring a modular architecture with consensus mechanisms, networking, and multiple CLI tools.
- Complete Blockchain Implementation: Full blockchain with blocks, transactions, and merkle trees
- Proof of Work Consensus: Configurable difficulty adjustment and mining
- P2P Networking: Peer-to-peer communication with node discovery
- Wallet Management: HD wallet with key generation and transaction signing
- Memory Pool: Transaction pool with validation and management
- Storage Layer: Persistent storage with RocksDB backend
- CLI Tools: Multiple command-line tools for different use cases
The project is organized into several core modules:
blockchain: Core blockchain logic and validationblock: Block structure and operationstransaction: Transaction handling and validationconsensus: Proof of Work consensus implementationnetwork: P2P networking and peer managementwallet: HD wallet and cryptographic operationsmempool: Transaction pool managementstorage: Persistent data storageutils: Utility functions and helpers
The project includes four specialized CLI tools:
Runs a full blockchain node with P2P networking and mining capabilities.
cargo run --bin node -- --data-dir ./data --listen 0.0.0.0:8333 --miningInteractive command-line interface for wallet and blockchain operations.
# Create a new wallet
cargo run --bin cli -- wallet create --name my_wallet
# Send a transaction
cargo run --bin cli -- transaction send --from <address> --to <address> --amount 10.0
# Check balance
cargo run --bin cli -- wallet balance --address <address>Dedicated mining tool with multi-threading support.
cargo run --bin miner -- --data-dir ./data --address <mining_address> --threads 4Blockchain explorer for viewing blocks, transactions, and addresses.
# View blockchain overview
cargo run --bin explorer -- overview
# View specific block
cargo run --bin explorer -- block --hash <block_hash>
# View transaction
cargo run --bin explorer -- transaction --hash <tx_hash>- Rust 1.70+ (install from rustup.rs)
- Git
# Clone the repository
git clone https://github.com/chord233/rust-blockchain.git
cd rust-blockchain
# Build the project
cargo build --release
# Run tests
cargo test-
Start a node:
cargo run --bin node -- --data-dir ./node1 --listen 0.0.0.0:8333
-
Create a wallet (in another terminal):
cargo run --bin cli -- wallet create --name alice
-
Start mining:
cargo run --bin miner -- --data-dir ./node1 --address <alice_address>
-
Explore the blockchain:
cargo run --bin explorer -- overview
--data-dir: Data directory for blockchain storage--listen: Network listening address--bootstrap: Bootstrap nodes for network discovery--mining: Enable mining--rpc-port: RPC server port--log-level: Logging level (trace, debug, info, warn, error)
--threads: Number of mining threads--intensity: Mining intensity (1-10)--max-time: Maximum mining time per block--max-transactions: Maximum transactions per block
src/
├── bin/ # CLI applications
│ ├── node.rs # Full node
│ ├── cli.rs # Interactive CLI
│ ├── miner.rs # Mining tool
│ └── explorer.rs # Blockchain explorer
├── block.rs # Block implementation
├── blockchain.rs # Blockchain logic
├── consensus.rs # Consensus mechanisms
├── crypto.rs # Cryptographic functions
├── error.rs # Error handling
├── lib.rs # Library root
├── mempool.rs # Transaction pool
├── network.rs # P2P networking
├── storage.rs # Data persistence
├── transaction.rs # Transaction handling
├── utils.rs # Utility functions
└── wallet.rs # Wallet management
# Run all tests
cargo test
# Run specific test module
cargo test blockchain
# Run with output
cargo test -- --nocapture- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Bitcoin and Ethereum implementations
- Built with the Rust ecosystem
- Uses RocksDB for efficient storage
- Implements industry-standard cryptographic primitives
- GitHub: @chord233
- Email: [email protected]
- Twitter: @chord244
- LinkedIn: chord233
Note: This is an educational blockchain implementation. Do not use in production environments without proper security audits.