Blockchain Fundamentals: How Distributed Ledgers Work
In this tutorial, you'll learn blockchain fundamentals including how blocks and chains form a distributed ledger. Why it matters: blockchain eliminates trusted intermediaries by enabling peer-to-peer trust through cryptography and consensus. By the end, you'll understand blocks, chains, mining, and how Bitcoin and Ethereum use this technology.
Blockchain is a distributed ledger technology that records data across a network of computers, ensuring no single party controls the information and every participant can verify the history. Each block contains a set of transactions, a timestamp, and a cryptographic hash linking it to the previous block.
What Is a Blockchain?
A blockchain is a chain of blocks, where each block references the previous one through a cryptographic hash. This creates an immutable record — changing any block would require recalculating every subsequent block, which is computationally infeasible on a large network.
flowchart LR A[Block #0
Genesis
Hash: 0x0000
Prev: none] --> B[Block #1
Hash: 0x7A3F
Prev: 0x0000] B --> C[Block #2
Hash: 0xB8E2
Prev: 0x7A3F] C --> D[Block #3
Hash: 0xF1C9
Prev: 0xB8E2]
Each block has three essential parts: a header with metadata, a list of validated transactions, and the hash of the previous block. This structure makes blockchains append-only — you can add new blocks but cannot modify old ones without breaking the chain.
How Consensus Mechanisms Work
Consensus mechanisms ensure all nodes agree on the state of the ledger. The two most common are Proof of Work (PoW) and Proof of Stake (PoS).
| Mechanism | Energy Use | Security | Speed | Example |
|---|---|---|---|---|
| Proof of Work | High | Very high | Slow (7 TPS Bitcoin) | Bitcoin, Ethereum (pre-2022) |
| Proof of Stake | Low | High | Fast (100k+ TPS) | Ethereum (post-2022), Solana |
| Delegated PoS | Low | Medium | Very fast | EOS, TRON |
| Practical Byzantine | Low | High | Fast | Hyperledger |
Proof of Work Explained
Miners compete to solve a cryptographic puzzle. The first to find a valid hash broadcasts the block to the network. Other nodes verify the work and add the block to their copy of the chain.
// Simplified Proof of Work hash target check
function isValidBlock(uint256 blockHash, uint256 target) public pure returns (bool) {
return blockHash < target;
}
// Example usage:
// target = 0x00000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
// If blockHash = 0x00000A3B... it's valid
// If blockHash = 0x00001C4F... it's not valid (too high)
Expected output: isValidBlock(0x00000A3B, 0x00000FFF) returns true
What Is Mining?
Mining is the process of adding new blocks to the blockchain. Miners collect pending transactions, form a block, and race to find a valid hash. The winner receives a block reward (newly minted coins) plus transaction fees.
Mining Difficulty
The network adjusts difficulty every 2,016 blocks in Bitcoin (about two weeks) to maintain a 10-minute average block time. If blocks are found too quickly, the target hash decreases, making puzzles harder.
| Block Range | Avg Block Time | Difficulty Adjustment |
|---|---|---|
| 1–2016 | 9 min 45 sec | -1.2% |
| 2017–4032 | 10 min 12 sec | +0.8% |
| 4033–6048 | 11 min 30 sec | +2.5% |
Transactions on the Blockchain
A transaction transfers value or data between addresses. Each transaction is signed by the sender's private key and broadcast to the network.
// Example transaction object
const tx = {
from: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
to: "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18",
value: "1000000000000000000", // 1 ETH in wei
nonce: 5,
gasLimit: 21000,
gasPrice: "20000000000", // 20 gwei
chainId: 1
};
// Sign the transaction
const signedTx = await wallet.signTransaction(tx);
console.log("Signed transaction:", signedTx);
// Expected output: Signed transaction: 0xf86c058502540be400825208... (hex string)
Expected console output: Signed transaction: 0xf86c058502540be400825208941234567890abcdef...
Understanding Forks
Forks happen when the blockchain splits into two paths. They can be intentional (upgrades) or accidental (two miners find a block at the same time).
Hard Fork vs Soft Fork
| Fork Type | Backward Compatible | Requires Upgrade | Example |
|---|---|---|---|
| Soft Fork | Yes | No (old nodes see longer chain) | SegWit (Bitcoin) |
| Hard Fork | No | Yes (all nodes must upgrade) | Ethereum London, Bitcoin Cash |
flowchart TD A[Block 100] --> B[Block 101] B --> C[Block 102] B --> D[Block 102'
Fork Point] C --> E[Block 103
Main Chain] D --> F[Block 103'
Orphaned] style D fill:#ff9999 style F fill:#ff9999
Common Errors and Misunderstandings
1. Confusing Blockchain with Cryptocurrency
Blockchain is the technology; cryptocurrency is one application. Many blockchains exist without coins.
2. Believing Blockchain Is Completely Anonymous
Most blockchains are pseudonymous, not anonymous. Transactions are publicly visible and can be traced.
3. Thinking All Nodes Store the Full History
Light nodes store only block headers. Full nodes store the complete chain. Pruning removes old transactions.
4. Assuming Immutability Means No Errors
While data is immutable, blockchain logic can have bugs (see The DAO hack). Upgrades via hard forks can fix issues.
5. Confusing Confirmation Time with Finality
A confirmed block can still be reorganized if a longer chain appears. Wait 6+ confirmations for high-value transactions.
Practice Questions
What three components make up each block in a blockchain? A block contains a header (metadata), a list of validated transactions, and the cryptographic hash of the previous block.
How does Proof of Work differ from Proof of Stake? PoW requires miners to solve computational puzzles, consuming energy. PoS selects validators based on the amount of cryptocurrency they stake, using minimal energy.
What happens when two miners find a valid block at the same time? A temporary fork occurs. The network eventually converges on the chain with the most accumulated work (longest chain rule).
Why does Bitcoin adjust mining difficulty every 2,016 blocks? To maintain a consistent 10-minute average block time as network hashrate changes.
What is the difference between a hard fork and a soft fork? A hard fork is not backward compatible and requires all nodes to upgrade. A soft fork is backward compatible — old nodes still see the new blocks as valid.
Challenge
Build a command-line blockchain simulation in Python that creates a chain of blocks, validates the chain integrity, and implements a simple Proof of Work algorithm. Your chain should detect tampering when any block data is modified.
Real-World Task
Create a monitoring script that connects to the Ethereum blockchain via a public node, tracks the latest block number every 30 seconds, and alerts if no new block is found within 5 minutes. This is used by dApp operators to ensure their Node.js infrastructure is syncing correctly.
Frequently Asked Questions
Next Steps
Now that you understand blockchain fundamentals, continue to Ethereum and the EVM to learn how smart contract platforms extend the blockchain concept. Related tutorials include Solidity Basics for writing your first contract and the Smart Contracts design patterns guide.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro