Blockchain Basics
Bitcoin and other cryptocurrencies are designed to ensure that you do not need to trust someone in order to receive money from them. Further, you do not need to trust anyone in the bitcoin network to ensure that you receive your money, or that transactions you send will be sent properly. Doing this has special challenges, which the blockchain is designed to solve.
Blockchains underly everything that happens in bitcoin. They are built using hash functions, so if you haven't worked with those before, checkout the linked lesson first. For the purposes of blockchains, hash functions allow us to verify information and ensure that the information cannot be changed.
If you want to send bitcoin to another person, you announce to the network your intention: "I would like to send 3 BTC to the address ABBABABA". However, just because you have stated your intention doesn't mean this has happened. In order for this transaction to be considered completed, it must be verified and written into the blockchain in a specific block.
A single block in the blockchain is comprised of the following information:
- The hash of the previous block
- A set of transactions
- A random number
The block is validated by computing its hash, and then transmitting that hash to everyone else on the network. The blockchain itself is public information, which means anyone can see every transaction on the network and anyone can validate that the blocks are correct.
Blocks are created and verified by programs/people called miners, and in return they get a payment in bitcoin for doing so. There is an important question that we will leave for a later lesson - who decides which miner verifies a given block? The short answer is that all the miners are racing to create a specific form of hash, and we will come back to the details of that puzzle in a future lesson.
What we have so far, is a miner will take a set of transactions, and verify a block. This is then added to the blockchain, which is a sequence of these blocks, remembering that each block contains a reference to the block before it. This means two things:
- Transactions in the bitcoin network are performed in a specific order, denoted by which block they appear in.
- Anyone can go back through the entire blockchain and verify every transaction.
In order to properly and completely work out how many bitcoins someone has, you need to go through the entire blockchain, and trace where all the coins have gone. There are quite a few optimisations for doing this in practice, however, so this computation is not always needed.
The blockchain allows for distributed transactions without the need to trust anyone in the network. Block cannot be easily forged after they are created (in practice, this equates to "cannot be forged", but there are small chances of this happening), and because everyone knows about all transactions, it is very difficult to alter the history of past transactions. Blockchains underly Bitcoin and other cryptocurrencies, but also enable a whole range of technologies from smart contracts (that are automatically processed), verifiable applications, and the ability to perform trusted actions with complete strangers. In conclusion, blockchain is an algorithm worth investigating for more than just bitcoin - it will usher a whole new set of technologies in the future.