Blockchain is a disruptive subject and is very different from the traditional systems. That's why in my opinion the best way to understand and learn it, is studying the first successful implementation of it. The Bitcoin !
With Bitcoin the subject started to be at the spot, with the valorization of it a lot of tech and financial people started to look closer to the technology below Bitcoin, and what makes this so secure and better than the traditional way we care about money today ?
The first point that I want to share with you today is how the bitcoin network works. The network used in the bitcoin's is a very old one and we use today to download torrents. The bitcoin and other implementations of blockchain uses P2P network !
Then you are going to ask yourself, how that works ? I know that this looks really crazy at first, but when you open your mind for blockchains you see that this makes sense and works very well when you aim decentralization and immutability !
First we have to understand the differences between Centralized, Decentralized and Distributed network.
As you can see in the centralized network we have only one central point where all peers send data to. This is how the traditional client-server works today, where the central point is the sever and it have all the data authority.
In the other hand we have the decentralized one that is how the internet works today, we have some backbones that communicate to each other, but the peers still sending data to one backbone. In that case we yet have some central point that have the data authority. That's why we have the distributed network, where the central point of data doesn't exist and every peer in the network works as a server. This is the Peer-to-Peer also known as P2P network ! Now I can ask you:
- Between those three what is the best network to handle your money ?
- Do you think its fair or trusty that only some peers handle your money ?
- What if this central peer is a bad person/ company ?
That is one of the problems that bitcoin is trying to solve, but how that works ?
Let's say that Sender wants to send 1 Bitcoin to Receiver. This is what is going to happen:
- Sender creates a transaction.
- Sender's bitcoin wallet validates the transaction.
- The transaction is sent to Mempool.
- Miners get the transaction from Mempool and start mining the block using a consensus algorithm.
- After the block is fully mined, it is added to the network.
- The chain validates the new block and every peer in the network will get the blockchain with the new block added.
- Finally, the Receiver get your BTCs
Here are some question you might have:
- What is the Mempool ?
- What the heck is Consensus Algorithm ?
- What happens with Sender's BTCs after the transaction is done ?
Hope that I thought in the same questions of you :) .
The Mempool (Shortcut for Memory Pool) is where the transactions stay until the miner is ready to get them. In the bitcoin's blockchain, the miner prioritize the biggest transactions over the smallest ones. This happens because here is where the miner makes money. Wait.. what? Yes, every transaction in the blockchain has a fee, and the miner get that fee to him plus the reward for mining the block.
Ok, but how the miner "mine" the block ? This is done through the consensus algorithm.
The consensus algorithm is probably the most important part of any implementation of blockchain. Here is where you achieve democratization of your network !
The Bitcoin uses one consensus algorithm called Proof Of Work, also you'll find written as PoW. There are some other strategies for getting consensus in a blockchain network that I'll write more about them later, but for now let's focus in the basics of PoW.
What this basically does is: try to get the right nonce number by checking the hash created for the block until the result hash have the same number of zero's in it's prefix as the current difficulty set in the Blockchain. This difficulty exists to control how fast the block will be mined in the network. Bitcoin uses a number to try to have the time of mining near of 10 minutes. If the mining is faster than it, the network increases the difficulty and if this is getting slow, the network decreases the difficulty.
That sounds familiar? This is how Bitcoin controls inflation !
This execution to try to get the right nonce number takes a lot of energy cost and computational work, and that's why the miners get the fees from the transaction. Also the miners are rewarded for mining the block, but this decreases over time until some day the miner will get only the transaction fees.
Hoping that you understand everything until here, as you can see that in the picture above Sender sent 1 BTC and Receiver got 1 BTC, but as I said in this post there is transaction fees that should be deducted here.
Let's suppose that Sender is sending 1 BTC to Receiver and he got 1.50 BTC in your wallet. Also lets assume that the transaction fee is 0.20 BTC. Here is what happens below the blankets over there:
- Sender says that he wants to send 1 BTC to Receiver.
- The transaction will have as a input 1.50 BTC, but one output of the transaction is going to be 1 BTC that Receiver should receive.
- The other output is going to be the change that Sender will get from this transaction: 1.50BTC - 1 BTC - 0.20 BTC = 0.30 BTC is the other output of the transaction. Those outputs are called UTXO( Unspent transaction Output)
- Then sender gets your change and your balance now is 0.30 and the Receiver gets your 1 BTC.
The UTXO have an important part inside in the bitcoin's network, but that is subject to other post :)
I know that there is a lot of information over here, but I think that these concepts are really important to understand together before going deeper in each component in a blockchain's network.
Cheers ! See you in the next post.