HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Digital Currency and Blockchain
  1. 1What a digital currency is and how it is used
  2. 2Blocks, hashes and the chain
  3. 3How a blockchain tracks transactions
  1. Computer Science
  2. /Digital Currency and Blockchain
  3. /Blocks, hashes and the chain

Course 5.2·Lesson 2 of 3

Blocks, hashes and the chain

A blockchain is a ledger that nobody can change in secret. This lesson opens one block: its data, its time-stamp, its own hash and the hash of the block before. Then it shows why changing one old record breaks the chain.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Digital Currency and Blockchain
  1. 1What a digital currency is and how it is used
  2. 2Blocks, hashes and the chain
  3. 3How a blockchain tracks transactions

Try the code and the simulations beside the lesson.

A ledger that cannot be changed

Imagine a class diary where each page ends with a code worked out from everything on that page. The next page starts by copying that code. If someone rubs out a word on page 3, its code no longer fits the one copied on page 4. Anyone can see that page 3 was changed.

A blockchain works like that diary. In its basic form, a blockchain is a digital ledger: a time-stamped series of records that cannot be altered.

What is in a block?

The records are grouped into blocks. Each block holds four things.

  1. The data: the records, such as the payments "Ana pays Ben 15".
  2. A time-stamp: the date and time when the block was made.
  3. The hash of the previous block: a copy of the hash of the block just before it in the chain.
  4. Its own hash: a value worked out from everything in the block.

The first block in a chain has no block before it. It is often called the genesis block.

Three blocks in a row, joined by arrows. Each block lists its number, its data, a time-stamp, the previous hash and its own hash (the first six characters of a SHA-256 hash). Block 1: data Ana pays Ben 15, time 09:00, previous hash 000000, hash 8aa926. Block 2: data Ben pays Chen 30, time 09:10, previous hash 8aa926, hash df8c20. Block 3: data Chen pays Ana 5, time 09:20, previous hash df8c20, hash 422c41. Each arrow joins a block's hash to the previous hash stored in the next block.

What is a hash?

A hash is a short value, like a fingerprint, that a hashing algorithm works out from data.

  • The same data always gives the same hash.
  • A tiny change in the data, even one digit, gives a completely different hash.
  • You cannot work the data back out from the hash.

So the hash of a block is a fingerprint of all its contents, including the hash of the previous block.

Why a change breaks the chain

Suppose someone changes the data in block 2, for example to make a payment bigger. Block 2 now has a different hash. But block 3 still stores the old hash of block 2. The two no longer match, so the chain is broken at that point. Every computer that checks the chain sees it.

The same three blocks after the data of block 2 has been changed to Ben pays Chen 80. Block 2's own hash is now 7a6886, shown in red. Block 3 still stores the previous hash df8c20. The arrow from block 2 to block 3 is red, with the label: does not match.

To hide the change, the person would have to work out a new hash for block 2. Then they would have to change the stored previous hash in block 3, which changes block 3's own hash. And so on, for every later block. The older the block, the more blocks must change.

Practise with new numbers

Try it in Python

The program uses hashlib, which comes with Python, to work out SHA-256 hashes. SHA-256 is one widely used hashing algorithm. The program keeps only the first 666 characters of each hash, as the pictures do, so it fits on the screen. First it hashes two records that differ by one digit. Then it builds a chain of three blocks, each storing the hash of the block before. To keep it short, it leaves out the time-stamp.

Read it first. Then run it. Compare the first two hashes. How many characters are the same?

1. Change "Ben pays Chen 30" to "Ben pays Chen 80". Which hashes in the chain change, and which stay the same?

2. Change the first record instead. What happens to the rest of the chain?

Common mistakes

  • Saying a hash is the data encrypted. A hash cannot be turned back into the data. Encryption can be undone with the key.
  • Forgetting the previous hash. It is what links a block to the one before. Without it there is no chain.
  • Saying only the changed block is affected. Every later block would need a new hash to hide the change.

Remember these

  • A blockchain is a digital ledger: a time-stamped series of records that cannot be altered.
  • Each block holds its data, a time-stamp, the hash of the previous block and its own hash.
  • Changing a block changes its hash, so the next block's stored hash no longer matches.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Name the four things that each block of a blockchain holds.
  1. The data in a block is changed by one character. What happens to the hash of that block?
  1. A chain has 151515 blocks and block 111111 is changed. How many blocks need a new hash to hide it?
  1. Why does the first block of a chain store no real previous hash?
  1. What does the time-stamp of a block record?

Enroll free in Digital Currency and Blockchain

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A blockchain records payments of a digital currency…Easy · High School (9–10) · by StemPy Lab
A blockchain has 9 blocks. A person changes the amount of a payment in block 4…Medium · High School (9–10) · by StemPy Lab
A student designs a "blockchain" in which each block holds only its data, a time-stamp and its own…Hard · High School (9–10) · by StemPy Lab
Next: lesson 3How a blockchain tracks transactions
← Digital Currency and Blockchain
← What a digital currency is and how it is usedHow a blockchain tracks transactions →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Python Labs (1)

Build and check a blockchainPython Lab · by StemPy Lab