A step-by-step Proof-of-Concept to build a Bitcoin-style mini blockchain in Rust.
Learn core blockchain concepts: blocks, hashing, Proof of Work, transactions, mining rewards, and optional networking.
This project is designed for educational purposes.
You'll build a simple blockchain from scratch, understand how Bitcoin works under the hood, and gradually add more features.
Core concepts covered:
- Block structure and linking
- SHA-256 hashing
- Proof of Work (mining)
- Transaction mempool
- Mining rewards
- Chain validation
- Optional REST API and node synchronization
Goal: Understand the basic block structure.
Tasks:
- Create a
Blockstruct with:index: u32timestamp: u64transactions: Vec<Transaction>(can be a simple struct or string for now)previous_hash: String
- Add a method to serialize the block into a string (for hashing later).
Success criteria:
- You can create a block and print its serialized form.
Goal: Understand cryptographic hashes.
Tasks:
- Add a method
compute_hash(&self) -> Stringto compute SHA-256 on the block's serialized content. - Ensure the hash changes if the block is modified.
Crates:
sha2for hashingserde+serde_jsonfor serialization
Success criteria:
- Printing
block.compute_hash()works. - Changing block data changes the hash.
Goal: Link blocks into a chain.
Tasks:
- Create a
Blockchainstruct withchain: Vec<Block>anddifficulty: usize. - Create a genesis block (
previous_hash = "0"). - Implement
add_block()to create new blocks, setprevious_hash, compute hash, and append to the chain.
Success criteria:
- You can create a chain with multiple linked blocks.
Goal: Ensure blockchain integrity.
Tasks:
- Implement
is_chain_valid() -> bool:- Verify each block’s hash matches its contents.
- Verify
previous_hashmatches the previous block.
- Test by manually modifying a block.
Success criteria:
- Any tampering breaks validation.
Goal: Implement mining similar to Bitcoin.
Tasks:
- Add
nonce: u64toBlock. - Implement
mine(&mut self):- Increment
nonceuntil the hash starts withdifficultyzeros.
- Increment
Success criteria:
- Mining changes the hash to meet the difficulty.
Goal: Simulate a mempool.
Tasks:
- Create a
Transactionstruct:from: String,to: String,amount: f32. - Add
pending_transactions: Vec<Transaction>inBlockchain. - Implement
add_transaction(tx: Transaction)andmine_pending_transactions():- Create a block with pending transactions.
- Mine it and add to the chain.
- Clear pending transactions.
Success criteria:
- Multiple transactions can be mined into a block.
Goal: Mimic Bitcoin’s block reward.
Tasks:
- Automatically include a special transaction in mined blocks:
from = "network"to = <miner_name>amount = <reward>
Success criteria:
- Miner earns coins each time a block is mined.
Goal: Turn blockchain into a node.
Tasks:
- Use
warporactix-webto expose endpoints:GET /chain→ returns full blockchainPOST /transaction/new→ add new transactionGET /mine→ mine pending transactions
Success criteria:
- Interact with the blockchain via browser or HTTP client.
Goal: Learn distributed consensus.
Tasks:
- Allow nodes to know each other.
- Implement “longest valid chain wins”:
- Compare chains between nodes
- Keep the longest valid chain
Success criteria:
- Nodes synchronize and resolve conflicts automatically.
- Implement a UTXO model
- Sign transactions with ECDSA (
k256crate) - Add dynamic difficulty adjustment
- Build a peer-to-peer network (TCP/WebSocket)
- Limit block size and mempool rules
sha2— SHA-256 hashingserde+serde_json— Serialization / JSON handlingchrono— Optional, for timestampswarp/actix-web— Optional, REST APIk256— Optional, for ECDSA signatures
MIT / Educational use