Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 41 ยท Getting Started

What Is a Blockchain?

Understand what a blockchain is, the problem it solves, how blocks link into a chain, and what it is not. Includes a tiny live demo in Python.

Imagine five friends who lend each other small amounts of money. Someone has to keep the notebook that says who owes whom. If one friend keeps it, everyone must trust that friend not to cheat, lose the book, or quietly change a number. A blockchain is a way to keep that notebook without choosing one trusted keeper: every participant holds a copy, and clever rules make it extremely hard to change the past without everyone noticing.

In this lesson you will learn which problem blockchains try to solve, what the words "block", "chain" and "ledger" really mean, how a distributed ledger differs from a normal database, and, just as important, what a blockchain is not. At the end you will build a three-block chain in about twenty lines of Python.

The problem: a shared record without a middleman

Whenever people need to agree on a record (who owns which money, which land title is valid, who voted), they usually rely on a trusted third party: a bank, a registry, an election office. That works well, but it has costs:

  • The middleman can make mistakes, be hacked, go offline or be pressured.
  • Everyone else sees only what the middleman chooses to show.
  • Moving a record between two middlemen (two banks, two countries) is slow because each keeps its own books.

Computer scientists asked: can a group of people who do not trust each other maintain one shared record that all of them accept as correct, with nobody in charge? A blockchain is the best-known answer. It combines three ideas, which you will study one by one in this tutorial:

  1. Cryptographic hashing makes records tamper-evident (see Cryptographic Hash Functions).
  2. Digital signatures prove who authorized a change (see Digital Signatures).
  3. Consensus rules let strangers agree on the order of changes (see The Double-Spend Problem).

Ledgers: a very old idea

A ledger is a list of entries that records transactions: "Alice pays Bob 5", "Bob pays Carol 2". Accountants have used ledgers for thousands of years. Two properties matter:

  • Append-only in spirit. Good bookkeeping never erases an old line; to fix a mistake you add a correcting entry.
  • The state is derived. Alice's balance is not stored anywhere magic; you get it by replaying the entries.

A blockchain is a ledger where the "append-only" promise is enforced by mathematics instead of by an auditor's goodwill.

Blocks and chains

Transactions are grouped into batches called blocks. Each block has two parts:

  • a body holding the list of transactions;
  • a header holding metadata, most importantly the hash of the previous block.

A hash is a short fingerprint of data: change one character of the data and the fingerprint changes completely. Because each block stores the fingerprint of its predecessor, the blocks form a chain.

flowchart LR
    G["Block 0 (genesis)<br/>prev: none<br/>hash: A1"] --> B1["Block 1<br/>prev: A1<br/>hash: B2"]
    B1 --> B2["Block 2<br/>prev: B2<br/>hash: C3"]
    B2 --> B3["Block 3<br/>prev: C3<br/>hash: D4"]

Each block stores the hash of the block before it, so changing an old block breaks every link after it.

Suppose someone edits a transaction in Block 1. Block 1's fingerprint changes from B2 to something else. But Block 2 still says "my previous block had fingerprint B2", so the link no longer matches, and the mismatch is visible to anyone who checks. To hide the edit, the cheater would have to recompute Block 2, then Block 3, and so on, and, in a real network, convince everyone else to accept the rewritten history. That is the core of tamper evidence.

Centralized, decentralized, distributed

These words are often mixed up:

Style Who holds the data? Example
Centralized One organization A bank's database
Decentralized Many independent parties, no single owner A public blockchain
Distributed Copies spread over many machines (may still be one owner) A company's replicated database cluster

A normal distributed database spreads data across many servers, but one company still controls all of them and can rewrite anything. A public blockchain is decentralized in who controls it, which is the interesting part: no single party can edit the record, so you do not need to trust any single party.

"Decentralized" is a spectrum, not a switch. A chain run by ten companies is far less centralized than a bank, and far more centralized than a network with thousands of independent participants.

A tiny blockchain in Python

Here is the whole idea in code. Each block is a dictionary; its hash is computed from its contents, including the previous block's hash. Run it, then break it.

Python Three linked blocks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Every row prints the first ten characters of the previous hash and of its own hash. Notice that the prev of each block equals the hash of the row above it. That is the chain.

Now tamper with history and check the links:

Python Detecting an edit

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

After the edit, block 2's prev no longer matches the recomputed hash of block 1, so the check fails at index 2. You will extend this toy into a proper chain in Building and Validating the Chain.

What a blockchain is not

Because of the hype, it helps to be clear about what blockchains are not:

  • Not a magic database. They are slow and expensive compared with a normal database. You pay for the ability to work without trusting one party.
  • Not automatically anonymous. Most public chains are pseudonymous: activity is public, tied to addresses rather than names (see Privacy and Zero-Knowledge Proofs).
  • Not a guarantee that data is true. A chain proves that a record was added and has not been changed. If someone writes a lie into it, the lie is preserved faithfully ("garbage in, garbage out").
  • Not the same as Bitcoin. Bitcoin is one application built on a blockchain. The data structure is useful beyond money.
  • Not always the right tool. If one trusted party can run the system, an ordinary database is simpler, cheaper and faster. Enterprise and Real-World Use Cases gives a checklist for deciding.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What main problem is a blockchain designed to solve?

    A blockchain lets mutually distrusting parties agree on one record without a single trusted middleman.
  2. 2. What does each block store that links it to the previous block?

    The header contains the hash of the previous block. If the earlier block changes, its hash changes and the stored link no longer matches.
  3. 3. Someone edits an old transaction in the middle of a chain. What happens?

    The edited block gets a new hash, but the next block still stores the old one, so verification fails from that point on.
  4. 4. Which statement about blockchains is true?

    A chain proves data was recorded and has not changed since, not that the data was true when written, and public chains are usually pseudonymous, not anonymous.

Summary

  • A blockchain is a shared, append-only ledger kept by many participants instead of one trusted keeper.
  • Transactions are grouped into blocks; each block header stores the hash of the previous block, forming a chain.
  • Changing an old block changes its hash and breaks every later link, which makes tampering evident.
  • Decentralized means no single party controls the record; it is a spectrum, and different from merely being replicated.
  • A blockchain does not make data true, anonymous or fast, and often an ordinary database is the better choice.

Next: How a Blockchain Works End to End, where you follow a single transaction from creation to finality.