Everwhy Open Everwhy
Computing

Could you build a working blockchain yourself, one tested piece at a time?

Build a Blockchain 201 · about 13 minutes a level

Build a small blockchain in Python, step by step: hashing with canonical data, blocks and a validated chain, proof-of-work mining with difficulty that adjusts, transactions and balances, keys and digital signatures, Merkle trees, a simple peer network that settles on the valid chain with the most work, a wallet, and a test suite that attacks your own code. Everything runs on your own computer with toy coins that have no value; nothing touches a real network or real money.

Open in Everwhy Continue on the web

Go deeper, level by level

  1. Blocks and hashes in Python: Hashing data in Python: bytes, JSON and SHA-256, A Block class, Linking blocks and validating the chain
  2. Proof-of-work mining: Difficulty: hashes that start with zeros, Mining: searching for a nonce, Adjusting difficulty to keep block times steady
  3. Transactions and balances: A Transaction class and its ID, A mempool, and building blocks from it, Balances, and refusing overspends, Rewarding miners: the coinbase transaction
  4. Keys and signatures: Key pairs with a trusted library, Signing transactions, Verifying signatures and rejecting forgeries, Stopping replays with account nonces
  5. Merkle trees: Computing a Merkle root, Merkle proofs for light clients
  6. A small peer network: A node with a small HTTP API, Sharing transactions and blocks with peers, Resolving conflicts: the chain with the most work wins, Simulating forks and reorganisations
  7. Wallets: Addresses from public keys, Keeping test keys safe on disk, A command-line wallet
  8. Testing, attacks and next steps: Unit tests with unittest, Testing attacks: tampering, double spends and forged signatures, From toy to real: what production blockchains add

Every lesson shows its sources and how sure we are, and is checked by Everwhy.