Blockchain: The technology behind Bitcoin
Learn how blockchain works the easy way.
Blockchain. Some may heard of it, some may not. But most are familiar with Bitcoin. To make clear, blockchain and Bitcoin are not the same, but it’s often used in the same context. In this blog I’ll want to give you an overview of this whole topic and want to explain the blockchain technology. There are going to follow more blogs of this kind, because there is much to talk about and it’s a current hot field in technology.
Introduction
So what is blockchain? Before I can answer this to you, you have to understand first off, how the internet works today. Let’s pick Facebook as an example. On Facebook we can send messages, write comments, post things and can do so much more activities. Somewhere all these information have to be stored. Facebook itself is handling that for us. They are saving all those things on their servers. So Facebook is a service and people, who use Facebook, are the clients.
Now if Facebook has some trouble with their servers, the clients might not be able to access Facebook, until the servers are fixed again. Also Facebook is able to see all the information people send to each other, because they are stored on their servers.
So Facebook is in control of this whole network.
The same is true for Google, Instagram and most of the services on the internet. But also for banks. We give them our money and the bank is managing it. In the case of a bad bank, we might lose our money, so we have to rely on them. And that’s the thing all those services have in common. Like I said, they have full control about the system and we as clients depend on them. These services are centralized and we have to trust them in some way.
Now I want to illustrate the difference between centralized and decentralized systems on the basis of a banking system. Let’s consider having person A and person B and both have a bank account. A wants to send B 100€. In order to transfer the money to B, the bank has to confirm and validate the transaction by storing it on the database of the bank. So the bank is the middleman and without the bank we wouldn’t be able to transfer money in a digital form…. actually we can.
Let’s try to build a system without the bank in the middle. Because we have no bank account any longer, we have to save our money in a different way. We could store the money in a file on a computer by putting in the number of the amount we own. This t ime we have person A, B and C and they all own a file with their money on their computer. They can transfer money b etween each other.
This is already a decentralized network, because their is no middleman and each person is independent in this network. What I mean is that, in the the centralized system, we aren’t actually in control of our money, but in the decentralized case we are in control as long as our computer works.
Now A sends B 100€ again.But no one confirms this transaction, so A still has these 100€ and could send it to person C. This is called the double-spending problem. How can we make sure, that A actually spent the money and can’t send it more than once? That’s the point, where blockchain comes into play.
Blockchain
In simple terms a blockchain is an immutable linked list. Or differently said, combining blocks of data, so that you get a chain of blocks. Okay maybe, that didn’t really help. Actually blockchain is in it’s core a simple concept and I try to explain it as easy as possible.
Like I said, the blockchain consists of blocks. These blocks contain information like a timestamp or transactions, if we use the blockchain for money transferring.
Now this is a block. It contains the index showing the block number, a timestamp, when it was created, and a data field. In our case we put the transactions into the data field. At last we have the hash. What is a hash and what does the number 0xf61e21j9 stand for?
A hash is created by a hash function. You simply put something inside the function and generate a number out of it and that is the hash. By putting in the same data over and over again you always get the same hash. By manipulating the data just slightly, you will get a completely different hash. You will see later, why this is very useful. If you get your hash you can’t reverse the process and extract the input data out of the hash. So it’s a one way function and it’s like a fingerprint.
Let’s say we use the hash function h(x) for our blockchain. Now what we do is, we put in the index, the timestamp and the data field as the argument for h.
That is how we generate the hash for the Block 1. In a moment you will understand, why we need the hash.
We see, we have one transaction in our block. A wants to send B 100€. But what is, if B wants to send something to C or someone else wants to make a transaction. We can’t just add those transactions into the Block 0 , because how I said, the blocks are immutable. There is no way to add or remove something from the block.
So what we do is, we create a new block, where we can put the next transactions. If we have again new transactions, we create another block. This process goes on and on.
Now we added two more blocks. Those two blocks have a new property prevHash. This one means previous hash and shows the hash of the block before. So in our case:
prevHash of Block 1 = hash of Block 0and
prevHash of Block 2 = hash of Block 1
Block 0 doesn’t have a previous hash, because this is the first block we have created and it is also called the genesis block.
The blocks are linked together now, since the previous hash references to the previous block.
Let’s assume C is a hacker and he wants to manipulate the transaction (B → C, 50 €) of Block 2 and replaces 50€ by 75.000€.
Remember, changing the data of the block also changes the hash of the block.
The result is, that the previous hash of Block 2 doesn’t match to the hash of Block 1. So Block 2 breaks the link to Block 1 and our blockchain becomes invalid. The hacker would need to change all block’s hashes to make the chain valid again, but that is almost impossible, if we have thousands of blocks. That’s it for the basics of blockchain. To actually use the blockchain in a decentralized network, we have to concern some things and add mining and a consensus protocol. You can find that in my next blog.