Cryptocurrency: Beginner's Guide
Cryptocurrencies have exploded in popularity among investors and the public alike, let’s take a look at how much cryptocurrencies have grown since the past few years.
So let’s start with the most fundamental question: What is cryptocurrency?
A cryptocurrency is a digital currency based on blockchain technology. Just like websites are made on the internet, similarly, Cryptocurrencies are made using the technology of Blockchain. Just like websites aren’t the only application of the internet, you can use it to send emails and a million other things as well, similarly, cryptocurrency isn’t the only application of blockchain technology, innovations are being made using blockchain technology such as NFTs and real estate registry, which we will explore in later guides.
So now you know that cryptocurrencies are made using blockchain and you must be thinking, what is blockchain?
Blockchain is quite simply, a chain of blocks, virtual ones. They have 4 main components:
Hash of the previous block
Hash of the current block
Nonce (explained later)
Information (in the case of cryptocurrencies, this is transaction information. A block can record a lot of transactions: Hundreds and thousands of them in the case of Bitcoin.)
No these blocks aren’t drug addicts, it’s a different kind of hash. A hash is a bunch of numbers and letters.
It looks like this: 3c6c55b0e4b607b672b50f04e028a6951aed6dc97b91e103fb0f348c3f1dfa00
Just stay with me, it will make sense in 2 mins.
These hashes are computed by putting input in a hashing function. In the case of Bitcoin, the hashing function: SHA256 is used to compute the hash. A hashing function is like a regular function, but it’s used to compute hashes.
A simple function can be f(x) = x + 1
This function takes the input x and adds one to it, so if you give it the input of 2423 then the function will return 2424.
In other words, f(2423) = 2423 + 1 = 2424
Similarly, SHA256 takes inputs and returns outputs.
(FYI: A function has only one unique output for a given input, but it can have multiple inputs giving the same output.)
SHA256 can literally take any input: photos, videos, text, you name it, SHA256 can hash it!
So we can say that SHA256 can take an infinite amount of inputs, but the output is always a 64 character alphanumeric hash. This unique hash serves as the fingerprint of the information taken as input and is stored inside the blocks.
There’s one major difference between SHA256 and f(x) = x + 1
In the second function, it is possible to know the input if you know the output, in other words, it can be reversed, but there is absolutely no possible way to know the input of SHA256 if you only know the output Hash.
How it works:
The Blockchain works by taking all the information stored inside a block, including the Hash of the previous block, and taking it as the input for SHA256, the resulting output is the Hash of that block. Then this Hash is carried forward to the next block and stored in it as the Hash of the previous block, thus all the blocks point towards the previous one, ultimately pointing to the first block which is called the genesis block. This is how the chain is formed.
This infographic shall clear the concept :
Here you can see that the Data and Previous Hash of a block is taken as input for SHA256 and the output is the current hash of the block, then that Hash is taken forward in the next block and stored in it as the Hash of the previous block.
This concept allows the blockchain to be immune to changes, as any change in a previous block’s data will cause the Hash of that block to change (Since that causes the input of SHA256 to change, consequently changing the output which is the Hash).
This will cause the blockchain to be invalid as the Hash of the previous block after changes won’t match with the Previous Hash stored in the current block. This means that after any changes are made to an old block of the Blockchain, whenever the current Block points towards the previous one, we will see that the Hashes don’t match with each other. This is why the Blockchain is immune to changes.
So after anything is recorded on a blockchain, there’s no going back, no omissions, no edits. Perfect for recording monetary transactions.
Okay so now you know what a blockchain is and why changes cannot be made to it. The next question to answer is: Who even records all of these transactions on a Blockchain? And why are they doing all this?
Suppose you want to buy chocolate and you send 5 Rupees to the shopkeeper from your Bank, in this case, the bank checks if you have enough balance in your account by checking your transaction history, turns out you had a balance of 10 Rupees in your bank. Voila, the transaction is approved and 5 Rupees are deducted from your account, then this money is sent to the Shopkeeper’s bank and added to his account and the transaction is complete. This is an example of a centralized system, where one organization or some organizations handle all your transactions.
Blockchain is a decentralized system. Suppose you want to pay 5 Bitcoins instead of 5 Rupees to your Shopkeeper, first of all, that’s some expensive chocolate you got there since a bitcoin is worth around 30 lac rupees at the time of writing this article.
Let’s dig into how the 5 Bitcoins will be sent from you to your shopkeeper. Firstly you will announce your transaction in the Blockchain network and there are a lot of people recording these transactions on their computers. So first they will check on the blockchain whether or not you even have 5 Bitcoins, turns out you’re a shady millionaire and you have 10 of them, so the transaction is approved. The next step is for all of these people to record the transaction on a block and add it to the Blockchain. So they compute the Hash of your block and voila, it is added to the blockchain and the transaction is recorded on all computers and all of these people recording the transactions know that you’ve sent 5 Bitcoins to your shopkeeper, everybody knows.
And the next time that shopkeeper wants to spend the 5 Bitcoins he has on something, he has to announce that he wants to send 5 Bitcoins to so and so person and since it was publicly recorded that he got 5 Bitcoins once, the transaction gets approved and he can do whatever he wants.
This will explain how a decentralized blockchain is different from a centralized Banking system:
On a decentralized system, everything is transparent, you spend 5 dollars on weird stuff over the internet using your bank, only your bank will get to know.
You spend 5 Bitcoins on weird stuff over the internet and the transaction will be publicly recorded with everyone. Your personal information isn’t recorded anywhere, but the transaction information is recorded everywhere.
By now you would be thinking, all this is great but why are all these people globally recording bitcoin transactions on the blockchain, don’t they have anything better to do? And the short answer to this is NO.
When a person records these transactions successfully and adds a new block to the blockchain, they are rewarded with 6.25 bitcoins which is roughly equal to 2 crores(as of writing this guide). This process of recording transactions and adding blocks on the blockchain for Bitcoin reward is called Bitcoin mining, and now you actually know what that word means whenever it’ll get thrown around next.
So why doesn’t everyone do Bitcoin mining if the reward is 2 crores?
It is really really tough, that’s why. Remember nonce? The part of a block that was mentioned earlier, this is it, everyone.
NONCE stands for ‘number only used once '
It is a 32-bit character (4 bytes) which when input along with all the other data in SHA256 will be able to produce an output hash that starts with 19 zeros.
A nonce looks like this: 01010001010010101010001010111001
You know by now that the output of SHA256 changes if you change the input, and that is the exact role of the nonce, to change the output hash to start with 19 zeros. How do we get a nonce that gives an output hash starting with 19 zeros?
We don’t know the answer to that, so we just try a lot of nonces, and if one of them gives an output hash starting with 19 zeros then boom. That’s our nonce. This means that we systematically change the zeroes and ones in the nonce and keep running SHA256 for each of them in order to get an output hash that starts with 19 zeros.
We apply brute force, which means that people systematically input various characters in the nonce, thousands, and thousands of times to get an output Hash that starts with 19 zeros. Presently, 2.7 Quadrillion Hashes are calculated to generate a block of bitcoin, because it takes that many attempts in changing the nonce to finally get it right till 19 zeroes in the start. Once a person finds the Hash, the block is closed and added to the blockchain, thus getting the 6.25 Bitcoin reward.
So you know now that Bitcoin mining is somewhat like the fastest finger first, whoever finds the hash and closes the block fastest, gets rewarded, so naturally, you would need a very fast computer to do that and yes indeed people have very very fast computers that are solely dedicated to bitcoin mining, people run mining operations on homemade computers and organizations build giant computers as well to participate in bitcoin mining.