Let's think about this for a second
This lesson doesn't teach anything new — it's about writing your own code to get hands-on with the hashing, blocks, and immutability ideas already explained in the Basic chapter. The goal is to actually see SHA256's avalanche effect (a tiny change in input completely changes the output). The tasks are short — you can open node in the terminal and run them directly.
Exercises
Task 1 — Require Node.js's crypto module, hash the two strings 'Hello Blockchain' and 'hello Blockchain' (differing only by the capital/lowercase H) with SHA256, and compare the outputs. Task 2 — Write a genesis block object yourself containing {index:0, timestamp: Date.now(), data:'Genesis Block', previousHash:'0'}, then combine it with JSON.stringify() and compute its SHA256 hash. Task 3 — Change the data field of the block object you wrote in Task 2, recalculate the hash, and compare it against the original hash to see whether they match.
Build a Complete Mental Model
This exercise set tests independent reasoning about hashing, block structure, links, and tamper detection. For each exercise, record exact serialized input, expected digest or link, one mutation, and the validation result. Do not confuse toy difficulty output with cryptographic collision or security guarantees; state assumptions clearly.
Apply It Safely
Submit each task as input specification, expected hash or tree, mutation, detected failure, and explanation.
Code Example
const crypto = require('crypto');
function sha256(input) {
return crypto.createHash('sha256').update(input).digest('hex');
}
// Task 1: string နှစ်ခု hash ယှဉ်ပါ (H စာလုံးကြီး/သေးပဲ ကွာပါတယ်)
const hashA = sha256('Hello Blockchain');
const hashB = sha256('hello Blockchain');
console.log('hashA:', hashA);
console.log('hashB:', hashB);
// Task 2: genesis block object ရေးပြီး hash တွက်ပါ
const genesisBlock = {
index: 0,
timestamp: Date.now(),
data: 'Genesis Block',
previousHash: '0',
};
const genesisHash = sha256(JSON.stringify(genesisBlock));
console.log('genesisHash:', genesisHash);
// Task 3: data ပြောင်းပြီး hash ကို ပြန်တွက်ကြည့်ပါ (TODO — ကိုယ်တိုင်ရေးပါ)
// const changedBlock = { ...genesisBlock, data: 'Genesis Block v2' };
// const changedHash = sha256(JSON.stringify(changedBlock));
// console.log('changedHash:', changedHash);
Once you finish all three tasks, you'll see three hash strings in the terminal: two completely different hashes for strings that differ by just one character, and a block's hash.Try It Yourself
Rebuild the Blockchain Exercises — Set 1 (Hashing & Block Basics) example on a local simulation or testnet without real funds, seeds, or private keys. Define two normal cases, one tampered or adversarial case, and one failure case, writing expected state and verification evidence before execution.
Security Warning
A long random-looking digest is not by itself a proof of correct or secure use.