When you pay with a digital currency, how does the payment end up in a blockchain, and why can nobody take it out again? This lesson follows a payment from the moment it is made, and shows how the blockchain lets anyone track it.
about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
Following one payment
Ana sends 15 units of a digital currency to Ben. No bank is involved. So who checks the payment, and who writes it down? The answer is: a network of many computers, each with its own copy of the whole blockchain. Each of these computers is called a node.
Six computers in a ring, each labelled node, each holding a small picture of the same chain of blocks. In the middle, a new block marked with a time-stamp is being sent to every computer by arrows. A label says that every node adds the same block to its own copy.
Here is how a blockchain tracks the payment.
The payment is made. Ana's digital wallet sends the payment, "Ana pays Ben 15", to the network.
It is checked. Computers in the network check that it is valid: does Ana really own 15 units? They can tell from the records already in the blockchain.
It is put into a block. Valid payments are grouped into a new block, with a time-stamp and the hash of the last block in the chain. The block's own hash is worked out.
The block is added to the chain. The new block goes on the end of the chain.
Every copy is updated. Every computer in the network adds the same block to its copy.
The record is permanent. The payment is now part of a time-stamped series of records that cannot be altered.
How the blockchain tracks money
Because every payment stays in the chain for ever, anyone with a copy can follow the units back through time. Where did Ana's 15 units come from? Look further back in the chain, and you find the payment that gave them to her. This is what we mean when we say a blockchain tracks digital currency transactions.
Why nobody can change it
You saw that changing one block means working out new hashes for every block after it. A blockchain adds two more guards.
Many copies. The network accepts the version of the chain that more than half of the computers hold. An attacker would have to change more than half of all the copies at the same time.
Slow on purpose. Many blockchains make adding a block hard on purpose. A computer must solve a difficult maths puzzle before its block is accepted. So working out new hashes for many blocks takes a very long time, while the honest network keeps adding new blocks.
Practise with new numbers
Try it in Python
The program holds the last hash of the chain as seven computers see it. Two of the copies were changed. It counts the versions, and the version that more than half hold is accepted. Counter from the collections module counts the items of a list for you.
Common mistakes
Saying one central computer checks the payments. Many computers in the network check them and each keeps a copy.
Saying a payment can be deleted later. Records in a blockchain cannot be altered; a mistake is put right only with a new payment.
Thinking half of the copies is enough. It must be more than half.
Remember these
A payment is checked by the network, put into a block with a time-stamp and the previous hash, added to the chain, and copied to every computer.
Every payment stays in the chain, so the history of the units can be tracked.
To change a record, an attacker would need new hashes for every later block, on more than half of all the copies.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Who checks that a payment in a blockchain is valid?
Put these in order: the block is added to the chain; the payment is checked; every copy is updated; the payment is put into a block.
A blockchain is copied on 30 computers. What is the smallest number that must hold a version for it to be held by more than half?
How does a blockchain let someone track where units of a digital currency came from?
Why does a blockchain keep copies on many computers?
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.