DAY 28 / 40

>> Module 03 / Day 28 / Lecture

Wallets & Transactions

Keys, addresses, and moving value

Our blockchain has blocks and chains. But blocks are empty. Today we add transactions — and understand the key pair that authorises every move of value.

Lecture 75 min | Lab 60 min · Create transactions, add to blocks | M3 · Blockchain Basics

>> Today's Roadmap

Six stops today

  1. What IS a wallet? Not what most people think
  2. Public key and private key — the asymmetric pair
  3. Addresses — where your coins live
  4. Transactions — the movement of value
  5. Adding transactions to our blocks
  6. Lab — build and pack transactions

>> 01 / 04 · Wallets

A wallet doesn't hold coins — it holds keys

Your bank balance is a number in the bank's database. Crypto is different: coins exist as entries on the blockchain. Your "wallet" is really just a program that stores your private key and shows you your balance by reading the blockchain.

Analogy: The blockchain is a safety deposit vault at a public bank. Anyone can see the boxes. Only the person with the private key can open their box.

HOT WALLET

Connected to the internet. Convenient for frequent use. MetaMask, Polkadot.js extension, Trust Wallet.

COLD WALLET

Offline device (Ledger, Trezor). Safer for large amounts. Private key never touches the internet.

>> 02 / 04 · Key pairs

The asymmetric key pair

Every wallet has exactly two keys. They are mathematically linked — but knowing the public key tells you nothing about the private key.

PUBLIC KEY / ADDRESS

Your address on the blockchain. Share it freely — this is how people send you tokens. Like your bank account number.

5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

PRIVATE KEY — NEVER SHARE

Your master password. Anyone with this can spend all your tokens. Never store it online. Never share it. If lost — tokens are gone forever.

0x5e0be...NEVER REVEAL THIS

>> 03 / 04 · Transactions

A transaction is a signed message

"Alice sends 10 DOT to Bob." But how does the network know it's really Alice? She signs the transaction with her private key. Anyone can verify the signature using her public key.

transaction.py
# A transaction in our simplified model transaction = { "from": "Alice_address", "to": "Bob_address", "amount": 10, "signature": "signed_with_alice_private_key", } # In our toy blockchain, we skip real cryptography. # We just trust the 'from' field. # Real blockchains verify the signature before accepting.
We simplify here. Real signature verification requires ECDSA (elliptic curve cryptography). We'll represent transactions as dicts with a "signature" field but not implement the actual crypto — that's a university-level topic.

>> 04 / 04 · Packing the block

A block's data is a list of transactions

block_with_txns.py
def make_block(index, transactions, previous_hash): block = { "index": index, "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), "transactions": transactions, # list of dicts "previous_hash": previous_hash, "hash": "", } block["hash"] = hash_block(block) return block # Create two transactions txns = [ {"from": "Alice", "to": "Bob", "amount": 10}, {"from": "Carol", "to": "Dave", "amount": 5}, ] block = make_block(1, txns, "0" * 64) print(f"Block 1 contains {len(block['transactions'])} transactions")

>> Real world

In Polkadot, transactions are called extrinsics

WHAT WE CALL IT

transaction = {from, to, amount}

Simple movement of value between addresses.

POLKADOT'S TERM

"Extrinsic" = any external message sent to the chain. Transfer DOT, vote in governance, stake tokens, call a smart contract — all are extrinsics.

Go to Subscan → click any block → look at the "Extrinsics" tab. You'll see a list of operations exactly like our transaction dicts. Each one has a sender, an action, and arguments.

>> 11:00 – 12:00 · Lab

Today's lab — Transactions in Blocks

CORE

Transaction builder

Create 5 transactions (using dicts). Update make_block() to accept a list of transactions. Build a 3-block chain where each block has 2 transactions. Print each block's transactions.

★ STRETCH

Balance tracker

After building the chain, scan all transactions and calculate the final balance for each address. Print a leaderboard of who has the most.

How to submit. Create students/<username>/D28_transactions.py. Full brief in lab/module_3_blockchain/D28_transactions/problem.md. PR before 12:00.

>> End of Day 28

Value can now move

✓

A wallet is a key pair: public (your address) and private (your password — never share it).

✓

A transaction is a dict: {from, to, amount, signature} — the signed instruction to move value.

✓

A block's data is now a list of transactions, each changing the state of who owns what.

01 / 8
←/→ navigate   F fullscreen