A blockchain is a system of recording transactions in a way that is not controlled by any single entity or organization, thereby reducing the chances of the data being tampered with. Since it is a decentralized network, it is almost impossible for any single person or organization to change the information the nodes contain. All the cryptocurrencies like Bitcoin, Ethereum, etc. use blockchain technology to operate.
To use these cryptocurrencies it is not necessary to know the underlying way these transactions work but it is very interesting to know how these transactions actually take place and what safeguards are present in the protocol which makes this decentralized system of blockchains so reliable and available.
I will start with an analogy to show how blockchains work.
Suppose there are a group of friends and they frequently exchange money with each other. They decide to maintain the transactions in a common ledger rather than actually exchanging cash.
A ledger is a book in which account transactions are recorded.
Whenever someone records a transaction and adds an entry to the ledger, they sign it with their signature. This signature can be created digitally using the SHA256 algorithm.
The SHA256 consists of public key - secret key pair. The secret key pair is only known to the person creating the signature. While the public key is shared with everyone to verify that the signature was created using the secret key present with that person. This makes the signature authentic. Without the secret key, the signature cannot be created.
For every new entry added to the ledger, everyone else verifies that the signature corresponding to the transaction is valid using the public key. This ensures that only valid transactions are recorded in the ledger. Each signature is a hash of the transaction and its unique id. This makes sure that no one else can just digitally reuse the signature of a previous transaction.
Theoretically, with this ledger system, there would be no need for actual currencies. The amount of money a person has can be found using the ledger (history of transactions). Isn’t it interesting! This is exactly what a cryptocurrency is - a history of transactions.
In the above analogy, I have used a common ledger. But this would make the system centralized since there is only one server where the is ledger maintained. To make it decentralized, I will let everyone have their own copy of the ledger.
Whenever a transaction is made, the people broadcast the information out for everyone to record the entry into their private ledgers.
Yes of course, when any transaction is made, how can everyone be sure and believe that the transaction was actually made. Also, how can anyone be sure that everyone is also recording the same transaction and in the same order? This is the problem addressed in the original bitcoin paper by Satoshi Nakamoto- (an unknown person who developed the bitcoin protocol.)
Record any block that has the proof of work with it. The proof of work, in this case, is the work in which the most amount of computational work has been put. The idea here is that if there is any fraudulent broadcasted message, it will require an infeasible amount of computational work to fool the system. Let me elaborate -
Each block will have a
list of transactions and a
hash. Suppose a person says that he has found a number that makes the hash of the whole block start with 30 zeroes. It is a computationally rigorous task and it can be said that the
block associated with this proof of work might be authentic.
Now that we have a distributed ledger system, we want a way for everyone to agree on what the correct ledger is and what is the order of this transaction. The core idea is to trust the block which has the most work put into it. The transactions on the ledger are divided into blocks along with the proof of work. The proof of work is the number when added to the block makes its hash start with a certain number of 0s.
A transaction is valid if it is signed by the sender. A block is valid if it has proof of work. To make sure that the order is correct, a block contains the hash of the block proceeding it.
If someone changes the order of the block or the information in the block, all the subsequent hashes will change and it is impossible for anyone to do such large computational work, hence making any such change is impossible.
Since blocks are chained together, it is called a blockchain.
There are a whole bunch of people who create blocks. They listen for transactions, create a block for these transactions, do the proof of work for the blocks and broadcast the blocks so that everyone can add these transactions to their ledger. As a reward for the block creators, for each block that is accepted, the block creators are paid a certain amount in cryptocurrencies. This is just money coming out of thin air. This is called a block reward.
Creating a block is also called mining since it requires a lot of work and with each block that is accepted, new money is added to the system. The block creators who create this block are called Miners.
From a miner’s perspective, creating blocks is highly competitive since everyone is listening to the same transactions and creating blocks. The miner whose blocks will be accepted will get rewarded.
They will wait for some time and listen for more blocks and the
blockchain which is longer will be accepted, since it has more computational work put into it.
With the increasing number of miners, the challenge or the proof of work actually gets harder. For bitcoin, it takes typically 10 minutes for a miner to complete the proof of work but for other cryptocurrencies, this time is shorter.
All of the money in bitcoin comes in the form of some block reward. For every 210,000 blocks, the reward gets cut in half. Currently, for bitcoin, a miner gets 12.5 bitcoins for each block. Since this reward decreases to half, there is only a fixed number of bitcoins that can exist. There cannot be more than 21 million bitcoins that can exist.
Miners can also charge transaction fees for mining. The way this works is for each transaction, the sender can specify a miner fee(optional) and it is kind of obvious that miners would give priority to the transaction having more transaction fees.
In bitcoin, each block is limited to 2400 transactions. but this number varies for different cryptocurrencies.