Blocks, chains, and hashing
📖 Scenario: You are building a simple blockchain to understand how blocks link together using hashes. Each block will store some data and the hash of the previous block, creating a secure chain.
🎯 Goal: Create a small blockchain with three blocks. Each block should contain data, the hash of the previous block, and its own hash. Finally, print the hashes of all blocks to see the chain.
📋 What You'll Learn
Create a dictionary called
block1 with keys data and prev_hash and exact values 'First block' and '0'Create a variable called
hash1 that stores the SHA-256 hash of the string formed by concatenating block1['data'] and block1['prev_hash']Create a dictionary called
block2 with keys data and prev_hash and exact values 'Second block' and hash1Create a variable called
hash2 that stores the SHA-256 hash of the string formed by concatenating block2['data'] and block2['prev_hash']Create a dictionary called
block3 with keys data and prev_hash and exact values 'Third block' and hash2Create a variable called
hash3 that stores the SHA-256 hash of the string formed by concatenating block3['data'] and block3['prev_hash']Print the three hashes
hash1, hash2, and hash3 each on its own line💡 Why This Matters
🌍 Real World
Blockchains are used to securely store data in a chain of blocks, making it hard to change past information without breaking the chain.
💼 Career
Understanding blocks, chains, and hashing is essential for jobs in blockchain development, cybersecurity, and data integrity.
Progress0 / 4 steps