Cryptography & Block Structure
Blockchain uses cryptographic hashing to link blocks together and ensure data integrity. Learn what a hash is and how blocks are structured. This is a foundational concept in decentralized application development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Blockchain/Web3 experience. Take your time with each section and practice the examples
Cryptographic Hashing
A hash function takes any input and produces a fixed-length output (the hash). The same input always produces the same hash. Even a tiny change in input produces a completely different hash. It's impossible to reverse a hash to get the original input. Blockchain uses SHA-256 (Bitcoin) and Keccak-256 (Ethereum). Each block stores the hash of the previous block — this is what creates the 'chain'.
What's Inside a Block?
- Index — Block number in the chain (0 = genesis block)
- Timestamp — When the block was created
- Transactions — List of all transactions in this block
- Previous Hash — Hash of the block before it (creates the chain)
- Nonce — Number used in mining (Proof of Work)
- Hash — This block's own cryptographic fingerprint
- Merkle Root — A single hash representing all transactions in the block
Block Structure Example
// A simplified blockchain block structure
const genesisBlock = {
index: 0,
timestamp: "2009-01-03T18:15:05Z",
transactions: ["Satoshi → Satoshi: 50 BTC (coinbase reward)"],
previousHash: "0000000000000000000000000000000000000000000000000000000000000000",
nonce: 2083236893,
hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
};
const block1 = {
index: 1,
timestamp: "2009-01-12T03:30:25Z",
transactions: [
"Satoshi → Hal Finney: 10 BTC", // First real Bitcoin transaction!
],
previousHash: genesisBlock.hash, // Links to genesis block
nonce: 1639830024,
hash: "00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee",
};
console.log("Genesis Block:", genesisBlock.hash.substring(0, 20) + "...");
console.log("Block 1 links to:", block1.previousHash.substring(0, 20) + "...");
console.log("Chain is valid:", block1.previousHash === genesisBlock.hash);
console.log("\nIf we change Genesis Block data, its hash changes,");
console.log("breaking the link to Block 1 — tampering is detectable!");Try It Yourself: Block Explorer
Line 30: Malformed tag: "< str.length; i++) { h ^= str.charCodeAt(i); h = (h * 0x01000193) >"
Tip: Tags must use valid HTML names and be properly formed. Example: <div>, <p class="text">