A blockchain implementation built from scratch in Rust. Supports wallet creation, Ed25519-signed transactions, a persistent mempool, proof-of-work mining, and chain inspection — all driven from the command line.
- SHA-256 block hashing with chain linkage
- Proof-of-work mining with configurable difficulty
- Ed25519 wallet key pairs for transaction signing and verification
- Persistent mempool — pending transactions survive between process runs
- Chain and mempool state saved to disk as JSON
- Simple CLI built with clap
- Rust 1.85 or later (edition 2024)
git clone https://github.com/darrenhjle/rust_blockchain.git
cd rust_blockchain
cargo build --releaseAll commands are run via cargo run -- or the compiled binary.
Generates a new Ed25519 key pair and saves it to wallet.json.
cargo run -- walletOutput:
Address: a3f9c1...
Wallet saved to wallet.json
Creates a signed transaction and adds it to the pending mempool (mempool.json).
cargo run -- send --to <recipient-address> --amount <value>Example:
cargo run -- send --to a3f9c1d2e4b5... --amount 10Drains all pending transactions from the mempool, mines a new block, and appends it to the chain.
cargo run -- mineOutput:
Mining block with 2 transactions...
Mined block 1 | nonce: 14823 | hash: 000a3f9c1d...
Block mined! Chain length: 2
Prints a summary of every block in the chain.
cargo run -- printOutput:
#0 | hash: 000abc12... | data: genesis
#1 | hash: 000f3a91... | data: [{"sender":"a3f9...
State is stored in three files in the working directory:
| File | Contents |
|---|---|
wallet.json |
Hex-encoded Ed25519 private key |
mempool.json |
Pending transactions waiting to be mined |
chain.json |
Full blockchain state |
These files are created automatically on first use.
src/
├── main.rs CLI entry point
├── lib.rs Module declarations
├── block.rs Block struct, SHA-256 hashing, proof-of-work
├── blockchain.rs Chain management and disk persistence
├── transaction.rs Transaction struct, signing, and validation
├── mempool.rs Pending transaction pool with disk persistence
└── wallet.rs Ed25519 key pair, address derivation, sign/verify
See docs/architecture.md for a full breakdown of each component.
- Wallet — An Ed25519 key pair is generated. The public key (hex-encoded) serves as the wallet address.
- Transaction — A transaction records sender, receiver, and amount. It is signed with the sender's private key and validated against their public key before entering the mempool.
- Mempool — Validated transactions are queued in
mempool.jsonand persist until mined. - Mining — All pending transactions are serialized into a block's data field. The miner increments a nonce until the block's SHA-256 hash has the required number of leading zeros.
- Chain — Each block references the previous block's hash, forming a tamper-evident chain. Any modification to a block invalidates all subsequent hashes.
- P2P networking with tokio and TCP
Merkle tree for transaction integrityDone- UTXO-based balance model
- Adjustable difficulty retargeting
- REST API
MIT