What do you think about when you hear the word “blockchain”? Most people think about bitcoin. And that makes sense, as it has been the most popular implementation of blockchain till now. But blockchain goes much further than that. Actually, we can use blockchain in many fields such as health, security, government, even virtualizing some assets. And that’s only the tip of the iceberg.
From the beginning
To figure out how the blockchain works, let’s first separate the concept into block and chain.
When we talk about a block, we can say that it is a data structure that contains three main fields. “Id” of the previous block, “id” of the current block and “payload”. The main idea in blockchain is to improve the concept of id. We are not talking about a simple id. We refer to a hash. So, just clarifying , the id of the blocks are hashes.
Giving us the consequent structure of a block:
The hash is produced by a hash function. These functions take any input and transform it into a specific string as output. You can think of it as a sign for specific input. Hash functions can be implemented by many algorithms for that purpose, such as, for example, sha-256, which is used in bitcoin blockchain. There are a lot of hash functions, but they all have some common specifications:
Hash functions are irreversible
Hash functions are deterministic
Hash functions has Avalanche effect : “Minor input change causes big output difference”
Hash functions has same output length always
Hash functions respond to integrity and authenticity security objectives
So when a block is created (something we’ll talk about later) it has the previous block hash, its content and finally with these two things it’s generated the current block hash number. These three things will be the input for the next block.
So now we know a block and hash definition, it’s pretty clear where the “chain” part of the sentence is. We are basically talking about a linked list where the main difference is that the id are hashes generated with the information of all parents of the current block/item/instance.3
Once we know the details, let’s figure out how the architecture is made of. We have some adjectives that describe the architecture overview.
The blockchain network works based on these concepts and also they are what have made it famous.
Distributed refers to an architecture which is all around working nodes. Decentralized refers to the fact that information and decisions are also distributed between nodes, and not only the network. Secure refers to the main idea that is pretty difficult to corrupt some blockchain due the hashes characteristics and the “chain” part in all of it. And transparent refers to the main idea that blockchain is a clear ledger in which we could see the content of each block because identities are hidden by some nickname that every person in the network has.
When do we use it?
So now we have an idea about blockchain basics, you may wonder, what’s all this for? Should we use it every time we can?
If you think about new use cases, they must have transactions into them. But we will talk about several points to consider whether you should or you shouldn’t use blockchain in your project.
Wonder about your databases:
Do you use databases in your project? Are there multiple writers over them? Can you trust these writers? Blockchains are a technology for databases with multiple non-trusting writers.
Wonder about actor’s interactions:
Do you need disintermediation in your process? Blockchains remove the need for trusted intermediaries by enabling databases with multiple non-trusting writers to be modified directly.
Wonder about interactions:
Blockchains truly shine where there is some interaction between the transactions created by multiple non trusted writers.
Learn more about these points here.
How is a new block made?
So how do you add a new block to the chain? Since we are using hashes as id’s the middle part of the blockchains has integrity and is secure, but what happens at the end of it? Well, blockchain offers a kind of mechanism that will help keeping its blocks secure and avoiding new corrupted blocks. There are several of these mechanisms called consensus algorithms.
The first created was proof of work (PoW). To create a new block over a blockchain using PoW you have to challenge other participants called miners. This challenge is about trying to solve an algorithm that returns the new block ID. The only way for doing this is a brute force search. The miner who discovers the new block hash, recibe a profit for it and can add it’s block to the chain.
As this algorithm consumes a lot of resources, there are new green solutions such as proof of stake (PoS) algorithm. To create a new block over a blockchain using PoS you have to own more vote power than other participants in that chain. This vote power it’s delivered by some criteria on each blockchain. For example, if there is a cryptocurrency chain, the more coins you have, the more vote power you own. There are other criteria for delivering vote power such as amount of transactions you’ve processed over time, or time you were participating in the blockchain.
So in conclusion, we’ve put ourselves face to face with a technology that’s very simple to understand but very difficult to implement. That has many use cases, even some we don’t even know yet. That may change the way we create apps, deliver security, share information and even save our values.
We’ll try to get deeper into this whole new world in next posts, but hope you get excited with this introduction.