Skip to content
Home Tutorials Roadmaps Courses Classroom Training Blog
Log in Join free
Computer Science Beginner Free

How Blockchain Works

Lesson 17 of 17 · Blockchain Basics 100%
1. Introduction to CS
What is Computer Science?
6. Operating Systems
OS Fundamentals
7. Cybersecurity Basics
Security Fundamentals
8. Software Engineering
Software Development Life Cycle
9. Cloud Computing
Cloud Computing Basics
10. Dynamic Programming
Dynamic Programming Introduction
11. AI & Machine Learning
Introduction to AI & ML
12. Internet of Things
IoT Fundamentals
13. Blockchain Basics
How Blockchain Works

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

Syntax

COMPUTER-SCIENCE
# Block structure
{
    index: 0,
    timestamp: 1700000000,
    data: "Genesis Block",
    previous_hash: "0",
    nonce: 0,
    hash: "0000abc..."
}
Blockchain Concept
PYTHON
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")]
chain.append(Block(1, "Transaction: Alice->Bob", chain[0].hash))
chain.append(Block(2, "Transaction: Bob->Carol", chain[1].hash))

for block in chain:
    print(f"Block {block.index}: {block.hash[:16]}...")

Practice

1
Exercise

Why is blockchain called immutable?

Answer
Because each block contains the hash of the previous block, making it virtually impossible to alter past records without detection.

Quick Quiz

1

What makes blockchain decentralized?

Blockchain distributes data across many nodes with no central control.

Choose an answer to continue.

Interview Questions

A blockchain is distributed and immutable. A database is centralized and can be modified by the administrator.

You reached the end

You finished the Computer Science tutorial!

Take a full course for real projects and a verifiable certificate.