Blockchain is a decentralized, immutable ledger that records transactions across many computers.
Key Properties
- Decentralized — no single authority
- Immutable — can't alter past records
- Transparent — all can verify
- Consensus — agreement mechanism
Blockchain is a decentralized, immutable ledger that records transactions across many computers.
# Block structure
{
index: 0,
timestamp: 1700000000,
data: "Genesis Block",
previous_hash: "0",
nonce: 0,
hash: "0000abc..."
}
import hashlib import json class Block: def __init__(self, index, data, previous_hash): self.index = index self.data = data self.previous_hash = previous_hash self.hash = self.calculate_hash() def calculate_hash(self): content = json.dumps({ "index": self.index, "data": self.data, "previous": self.previous_hash }) return hashlib.sha256(content.encode()).hexdigest() # Create blockchain chain = [ Block(0, "Genesis Block", "0"), Block(1, "Transaction: Alice->Bob", chain[0].hash), ] for block in chain: print(f"Block {block.index}: {block.hash[:16]}...")
Why is blockchain called immutable?
Because each block contains the hash of the previous block, making it virtually impossible to alter past records without detection.
What makes blockchain decentralized?
Blockchain distributes data across many nodes with no central control.
A blockchain is distributed and immutable. A database is centralized and can be modified by the administrator.