LEARN BLOCKCHAIN FROM SCRATCH
Learn Blockchain: Build The Trust Layer
Goal: Demystify blockchain by building every layer of the stack yourself—from hashing algorithms and P2P networking to consensus mechanisms and virtual machines.
The “Why” of Blockchain
Most people think blockchain is just “money” or “crypto.” Technologically, it is a specific type of state machine replicated across a network where no single actor is trusted.
If you want to truly understand blockchain, you must ignore the price of Bitcoin and focus on the Distributed System problems it solves:
- State Management: How do we agree on who owns what?
- Consensus: How do we agree on the order of events without a boss?
- Networking: How do we propagate information efficiently?
- Cryptography: How do we prove identity without a database of passwords?
After these projects, you won’t just know how to use a blockchain; you will know how to invent one.
Core Concept Analysis
The Blockchain Stack
- Cryptographic Primitives: Hashing (SHA256, Keccak), Signatures (ECDSA, Ed25519).
- Data Structures: Linked Lists, Merkle Trees, Patricia Tries.
- Networking: Gossip protocols, Peer discovery.
- Consensus: Proof of Work, Proof of Stake, Nakamoto Consensus.
- Application Layer: Virtual Machines (EVM), Smart Contracts, State transition rules.
Project List
The projects are ordered from the “atom” (a single block) to the “universe” (a full decentralized network).
Project 1: The Immutable Ledger (The Genesis)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Go (Golang)
- Alternative Programming Languages: Python, Rust
- Coolness Level: Level 2: Practical but Forgettable
- Business Potential: 1. The “Resume Gold”
- Difficulty: Level 1: Beginner
- Knowledge Area: Data Structures / Hashing
- Software or Tool: Standard Library (crypto/sha256)
- Main Book: Mastering Bitcoin by Andreas Antonopoulos (Chapter 7: The Blockchain)
What you’ll build: A simple program that creates “blocks” of data, hashes them, and links them together. If you change one character in a past block, the entire chain becomes invalid.
Why it teaches Blockchain: This is the fundamental data structure. You will learn why “modifying history” is computationally impossible in a blockchain.
Core challenges you’ll face:
- The Avalanche Effect: Understanding how changing 1 bit of input changes the entire hash.
- Linking: Ensuring Block
Ncontains the hash of BlockN-1. - Serialization: Converting complex objects (transactions) into a byte string to be hashed.
Key Concepts:
- Cryptographic Hash Functions: Mastering Bitcoin Ch. 2.
- Linked Lists: Basic CS concept.
Difficulty: Beginner Time estimate: Weekend Pre-requirements: Basic programming logic (classes/structs).
Real world outcome:
- You will run your program, manually edit a “transaction” in Block 2, and watch your validation function scream that the chain is broken at Block 3.
Implementation Hints:
Create a Block struct with fields: Timestamp, Data, PrevHash, Hash.
The Hash should be calculated as SHA256(Timestamp + Data + PrevHash).
Create a loop that verifies Block[i].PrevHash == Block[i-1].Hash.
Learning milestones:
- Understanding SHA256.
- Understanding how data dependencies create immutability.
Project 2: The Wallet & Transaction Signer
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Python
- Alternative Programming Languages: JavaScript (Node.js), Rust
- Coolness Level: Level 3: Genuinely Clever
- Business Potential: 2. The “Micro-SaaS” (Custom Wallet tools)
- Difficulty: Level 2: Intermediate
- Knowledge Area: Cryptography / Elliptic Curves
- Software or Tool: OpenSSL or specific crypto libraries (e.g.,
ecdsain Python) - Main Book: Mastering Bitcoin by Andreas Antonopoulos (Chapter 4: Keys, Addresses)
What you’ll build: A CLI tool that generates public/private key pairs, derives an “Address” from the public key, and creates a digital signature for a message (transaction) that can be verified by anyone.
Why it teaches Blockchain: “Not your keys, not your coins.” This project teaches you what ownership actually means on a blockchain. It’s not a record in a database; it’s a mathematical proof that you hold the private key.
Core challenges you’ll face:
- Elliptic Curve Cryptography (ECC): Understanding
secp256k1(Bitcoin’s curve). - Address Derivation: Hashing the public key (SHA256 + RIPEMD160) to get a short address.
- Signing vs. Verifying: Implementing the mathematical flow of proving origin without revealing the secret.
Key Concepts:
- Public Key Cryptography: Code: The Hidden Language (provides good context on codes).
- Digital Signatures: RFC 6979 (Deterministic ECDSA).
Difficulty: Intermediate Time estimate: 1 week Pre-requirements: Project 1.
Real world outcome:
- You generate a file
private_key.pem. You sign a string “I pay Bob 10 BTC”. You give your friend the signature and your public key. They run a verify script and it returnsTRUE.
Implementation Hints: Do not implement ECC math from scratch (unless you are a math wizard); use a library. Focus on the flow:
- Generate Private Key (Random number).
- Derive Public Key (Point on curve).
- Hash Public Key -> Address.
- Sign(Message, PrivKey) -> Signature.
- Verify(Message, Signature, PubKey) -> Boolean.
Project 3: The Miner (Proof of Work)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Go
- Alternative Programming Languages: C, Rust
- Coolness Level: Level 3: Genuinely Clever
- Business Potential: 1. The “Resume Gold”
- Difficulty: Level 2: Intermediate
- Knowledge Area: Consensus Algorithms
- Software or Tool: None
- Main Book: Mastering Bitcoin (Chapter 10: Mining)
What you’ll build: A program that takes a block of data and tries to find a “Nonce” (a random number) such that the hash of the block starts with a specific number of zeros (Difficulty).
Why it teaches Blockchain: This explains why Bitcoin uses so much energy and why it is secure. You will physically see your CPU spin up and understand that “security” is just “cost of computation.”
Core challenges you’ll face:
- The Brute Force Loop: Iterating millions of nonces per second.
- Difficulty Adjustment: Writing logic to increase/decrease the required zeros based on how fast you found the last block.
- Hex Target: Comparing hash strings/bytes numerically.
Key Concepts:
- Proof of Work: Satoshi Nakamoto Whitepaper (Section 4).
- Nonce: “Number used once”.
- Target Difficulty: How the network self-regulates.
Difficulty: Intermediate Time estimate: Weekend Pre-requirements: Project 1.
Real world outcome:
- Output:
Mining block 1... Found nonce: 34251 (Hash: 0000a4f...) Time: 0.2s. - Increase difficulty.
- Output:
Mining block 2... Found nonce: 9812491 (Hash: 000000b...) Time: 15s.
Implementation Hints:
Add a Nonce field to your Block from Project 1.
Hash = SHA256(Data + Nonce).
While Hash > Target: increment Nonce.
Project 4: P2P Network Node (Gossip Protocol)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Node.js (JavaScript/TypeScript)
- Alternative Programming Languages: Go (using LibP2P), Rust
- Coolness Level: Level 4: Hardcore Tech Flex
- Business Potential: 3. Service & Support (Networking Infra)
- Difficulty: Level 3: Advanced
- Knowledge Area: Networking / Distributed Systems
- Software or Tool: WebSockets (
wslibrary) or TCP sockets - Main Book: Computer Networks by Tanenbaum (for theory) OR Mastering Bitcoin (Network section)
What you’ll build: A set of nodes that run on different ports. When you add a block to Node A, it automatically tells Node B and Node C. Node C validates it and adds it to its own chain.
Why it teaches Blockchain: A blockchain on one computer is just a slow database. This project teaches “Decentralization.” You will deal with latency, synchronization, and the “Longest Chain Rule.”
Core challenges you’ll face:
- Peer Discovery: How does Node A know Node B exists? (Hardcode initially).
- Chain Synchronization: When Node D comes online, it needs to download history from A, B, or C.
- Conflict Resolution: Node A and Node B mine a block at the same time. Who wins? (Nakamoto Consensus).
Key Concepts:
- Gossip Protocol: How rumors (data) spread.
- Longest Chain Rule: The truth is the chain with the most accumulated work.
- Socket Programming: Persistent connections.
Difficulty: Advanced Time estimate: 2 weeks Pre-requirements: Projects 1, 3.
Real world outcome:
- You start terminal windows for 3 nodes. You send a command to Node 1 to mine a block. Instantly, Node 2 and 3 log: “Received new block from peer, validating… Added to chain.”
Implementation Hints: Start with a hardcoded list of peers. On connection, exchange “Height” (how many blocks I have). If Peer has more blocks -> Request blocks. On receiving block -> Validate hash -> Add to chain -> Broadcast to other peers.
Project 5: The UTXO Database
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Go or Rust
- Alternative Programming Languages: Python (slower but works)
- Coolness Level: Level 4: Hardcore Tech Flex
- Business Potential: 4. Open Core Infrastructure
- Difficulty: Level 3: Advanced
- Knowledge Area: Database / State Management
- Software or Tool: LevelDB or RocksDB (Key-Value stores)
- Main Book: Mastering Bitcoin (Chapter 6: Transactions)
What you’ll build: The engine that tracks “Who has money.” Unlike a bank (which has a table Bob: $50), Bitcoin uses UTXOs (Unspent Transaction Outputs). You will build a database that tracks every “coin” that hasn’t been spent yet.
Why it teaches Blockchain: This is the most confusing part of Bitcoin for beginners. You don’t “have” 5 bitcoins. You have a key that unlocks 5 specific unspent outputs from the past.
Core challenges you’ll face:
- Inputs vs Outputs: Transaction Inputs consume previous Outputs.
- Double Spend Protection: Ensuring an output is referenced only once.
- Persistence: Storing this on disk (LevelDB) so you don’t lose money on restart.
Key Concepts:
- UTXO Model: Unspent Transaction Output.
- KV Stores: How blockchains store state efficiently.
Difficulty: Advanced Time estimate: 1-2 weeks Pre-requirements: Project 2 (Transactions).
Real world outcome:
- You can query your DB:
get_balance(UserAddress). The system scans the UTXO set, sums up the values, and returns the balance. If you try to spend the same UTXO twice, the system rejects it.
Implementation Hints: You need a database where Key=TxID+Index, Value=Amount+Owner. When a new Block arrives:
- Remove used Inputs from DB.
- Add new Outputs to DB. If step 1 fails (input doesn’t exist), the block is invalid.
Project 6: Merkle Tree Verifier (The Light Client)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Python
- Alternative Programming Languages: TypeScript
- Coolness Level: Level 3: Genuinely Clever
- Business Potential: 2. Micro-SaaS (Audit tools)
- Difficulty: Level 2: Intermediate
- Knowledge Area: Algorithms / Trees
- Software or Tool: None
- Main Book: Mastering Bitcoin (Chapter 7)
What you’ll build: A tool that takes a list of transactions, builds a Merkle Tree, calculates the Root Hash, and generates a “Merkle Proof” that proves a specific transaction exists in the tree without revealing the whole tree.
Why it teaches Blockchain: This is how mobile wallets (SPV) work. They don’t download the whole blockchain (500GB+); they just download the headers and ask for a “Merkle Proof” that their transaction is included.
Core challenges you’ll face:
- Tree Construction: Recursively hashing pairs of nodes.
- Odd Leaf Handling: What if you have 3 transactions? (Duplicate the last one).
- Proof Generation: Finding the “path” of hashes needed to reconstruct the root.
Key Concepts:
- Merkle Trees: Ralph Merkle (1979).
- SPV (Simplified Payment Verification): Section 8 of Satoshi’s Whitepaper.
Difficulty: Intermediate Time estimate: Weekend Pre-requirements: Basic Recursion knowledge.
Real world outcome:
- You provide a Root Hash and a Proof. The program says “Verified: Transaction X is definitely in this block” without seeing the other 2,000 transactions in that block.
Project 7: Stack-Based Virtual Machine (Smart Contracts)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Rust or Go
- Alternative Programming Languages: Python
- Coolness Level: Level 5: Pure Magic
- Business Potential: 5. Industry Disruptor (New Chain L1)
- Difficulty: Level 4: Expert
- Knowledge Area: Compilers / Virtual Machines
- Software or Tool: None
- Main Book: Mastering Ethereum (Chapter 13: EVM)
What you’ll build: A mini-EVM. A program that reads bytecode (e.g., 0x6001600101 -> PUSH1 1, PUSH1 1, ADD) and executes it on a stack, updating the state.
Why it teaches Blockchain: This distinguishes Bitcoin (calculator) from Ethereum (computer). You will understand “Gas” (charging for every opcode loop) and “Turing Completeness.”
Core challenges you’ll face:
- The Stack: Implementing a LIFO data structure.
- Opcode Dispatch: Mapping bytes (0x01) to functions (ADD).
- Gas Metering: Throwing an exception if the user runs out of “fuel” (infinite loop protection).
- Memory vs Storage: Temporary execution data vs Permanent blockchain state.
Key Concepts:
- Stack Machine: Architecture used by Forth, PostScript, and EVM.
- Opcodes: Low-level CPU instructions.
Difficulty: Expert Time estimate: 1 month Pre-requirements: Strong understanding of Data Structures.
Real world outcome:
- You write a script in a custom assembly language:
PUSH 5, PUSH 10, ADD, STORE. You run your VM. You check the storage, and it contains15.
Implementation Hints:
Start simple. Implement 5 opcodes: PUSH, ADD, SUB, STOP, STORE.
The “State” is just a map passed into the execute function.
Project 8: Payment Channel (Lightning Network Basics)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Python
- Alternative Programming Languages: JavaScript
- Coolness Level: Level 4: Hardcore Tech Flex
- Business Potential: 3. Service & Support
- Difficulty: Level 3: Advanced
- Knowledge Area: Layer 2 / State Channels
- Software or Tool: None
- Main Book: The Bitcoin Lightning Network: Scalable Off-Chain Instant Payments (Whitepaper)
What you’ll build: A script simulating two parties (Alice and Bob) exchanging signed transactions off-chain, updating their balance locally, and only broadcasting the final state to the “blockchain” (your Project 1 or 5).
Why it teaches Blockchain: Scaling. Blockchains are slow. This teaches you how to use the blockchain as a judge (settlement layer) rather than a processor (payment layer).
Core challenges you’ll face:
- 2-of-2 Multisig: Constructing a transaction that requires two signatures (simulated).
- Timelocks: Handling “If Bob disappears, Alice gets money back after 24 hours.”
- Revocation: How to prevent Alice from broadcasting an old state where she had more money.
Key Concepts:
- HTLC (Hashed Time Locked Contracts).
- Off-chain scaling.
Difficulty: Advanced Time estimate: 2 weeks Pre-requirements: Project 2 (Signatures), Project 5 (UTXO).
Real world outcome:
- Alice sends 100 micro-transactions to Bob instantly. No blocks are mined. Finally, Bob “closes” the channel, and one transaction appears on the chain reflecting the net result.
Project 9: Simple Zero-Knowledge Proof (The “Zk-Snark”)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Circom (Circuit language) + JavaScript (Groth16 Verifier)
- Alternative Programming Languages: Rust (Bellman)
- Coolness Level: Level 5: Pure Magic
- Business Potential: 5. Industry Disruptor
- Difficulty: Level 5: Master
- Knowledge Area: Advanced Cryptography / Algebra
- Software or Tool: Circom, SnarkJS
- Main Book: MoonMath Manual (zk-SNARKs for beginners)
What you’ll build: A circuit that allows you to prove you know the factors of a number (e.g., A * B = 12) without revealing A or B, and a smart contract (verifier) that accepts this proof.
Why it teaches Blockchain: Privacy and Scalability (Rollups). ZK is the endgame of blockchain tech. It allows verification of computation without re-execution.
Core challenges you’ll face:
- Thinking in Circuits: You can’t use “if” statements or loops in the same way. You build mathematical constraints (
a * b === c). - Trusted Setup: Understanding the “Toxic Waste” ceremony.
- Prover/Verifier separation: Generating the proof file vs generating the verification key.
Key Concepts:
- Arithmetic Circuits.
- Succinctness: The proof is tiny regardless of computation size.
Difficulty: Master Time estimate: 1 month Pre-requirements: High tolerance for math.
Real world outcome:
- You generate a “Proof”. You send it to a verifier. The verifier returns
TRUE. You never revealed your secret inputs.
Project 10: The Full Node (Capstone)
- File: LEARN_BLOCKCHAIN_FROM_SCRATCH.md
- Main Programming Language: Go or Rust
- Alternative Programming Languages: C++
- Coolness Level: Level 5: Pure Magic
- Business Potential: 5. Industry Disruptor
- Difficulty: Level 5: Master
- Knowledge Area: System Integration
- Software or Tool: All tools from previous projects
- Main Book: Mastering Bitcoin
What you’ll build: Integrate Projects 1, 2, 3, 4, and 5 into a single binary. A node that connects to peers, syncs the chain, accepts transactions via API (RPC), mines blocks, and maintains a UTXO set.
Why it teaches Blockchain: This is a blockchain. If you finish this, you are a Core Developer.
Core challenges you’ll face:
- Concurrency: Mining runs on one thread, Networking on another, RPC on a third.
- Deadlocks: Managing shared access to the blockchain database.
- Protocol Design: Creating a robust binary message format for the network.
Key Concepts:
- Event Loops.
- Distributed Consensus.
- RPC (Remote Procedure Call).
Difficulty: Master Time estimate: 2-3 months Pre-requirements: All previous projects.
Real world outcome:
- You deploy your node on an AWS instance. You send the binary to a friend. They run it. You mine a block. They see it. You send them coins. They receive them. You have created your own currency.
Project Comparison Table
| Project | Difficulty | Time | Depth of Understanding | Fun Factor |
|---|---|---|---|---|
| 1. Immutable Ledger | Beginner | Weekend | ⭐⭐ | ⭐⭐⭐ |
| 2. Wallet/Signer | Intermediate | 1 Week | ⭐⭐⭐ | ⭐⭐⭐ |
| 3. The Miner (PoW) | Intermediate | Weekend | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 4. P2P Network | Advanced | 2 Weeks | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| 5. UTXO Database | Advanced | 2 Weeks | ⭐⭐⭐⭐⭐ | ⭐⭐ |
| 6. Merkle Verifier | Intermediate | Weekend | ⭐⭐⭐ | ⭐⭐⭐ |
| 7. Stack VM | Expert | 1 Month | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 8. Payment Channel | Advanced | 2 Weeks | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| 9. ZK Proof | Master | 1 Month | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 10. Full Node | Master | 3 Months | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
Recommendation
Where to start?
Start with Project 1 (Immutable Ledger) and immediately follow with Project 3 (The Miner). Why: These two combined give you the “Aha!” moment of how blocks are linked and why mining is hard. You can do this in a single weekend in Python or Go.
The “Developer” Path
If you want to get hired as a Blockchain Engineer: Focus on Project 7 (Stack VM). Understanding how the EVM works internally puts you in the top 1% of Solidity developers who usually only know the high-level language.
The “Protocol” Path
If you want to design new blockchains: Focus on Project 4 (P2P Network) and Project 9 (ZK Proof). These are the frontiers of current research (Networking scalability and Privacy).
Summary: All Projects
| # | Project Name | Main Language |
|---|---|---|
| 1 | The Immutable Ledger | Go |
| 2 | The Wallet & Transaction Signer | Python |
| 3 | The Miner (Proof of Work) | Go |
| 4 | P2P Network Node | Node.js |
| 5 | The UTXO Database | Go |
| 6 | Merkle Tree Verifier | Python |
| 7 | Stack-Based Virtual Machine | Rust |
| 8 | Payment Channel | Python |
| 9 | Simple Zero-Knowledge Proof | Circom/JS |
| 10 | The Full Node (Capstone) | Go |
Essential Resources
Books
- Mastering Bitcoin by Andreas Antonopoulos (The Bible of Blockchain).
- Mastering Ethereum by Andreas Antonopoulos & Gavin Wood (For VM/Smart Contracts).
- The Bitcoin Standard by Saifedean Ammous (For the economic “Why”).
- Programming Bitcoin by Jimmy Song (Python-heavy, builds from scratch).
Whitepapers (Must Reads)
- Bitcoin: A Peer-to-Peer Electronic Cash System (Satoshi Nakamoto) - Read this first.
- Ethereum Whitepaper (Vitalik Buterin) - Read this when doing Project 7.
Interactive/Online
- Anders Brownworth’s Blockchain Demo: A visual web demo of Project 1 & 3.
- EVM Codes: Reference for every Ethereum Opcode (Project 7).
- ZkREPL: Online playground for writing ZK circuits (Project 9).
Implementation Hints (General)
- Don’t use frameworks: Do not use Hyperledger, Ganache, or Hardhat for these projects. Use standard libraries. The goal is to build the framework, not use it.
- Start with JSON: For networking (Project 4), send JSON strings over TCP first. Optimize to binary formats later.
- Logging is key: In distributed systems, you can’t step-debug easily across nodes. detailed logs (
console.log/fmt.Println) are your best friend.