In 2008, when Lehman Brothers Holdings Inc. filed for bankruptcy, it shook people's faith in banks so much that a new class of assets appeared without formal bank backing. The first cryptocurrency named Bitcoin was invented in 2008 by an unknown person or group of people using the name Satoshi Nakamoto. The idea was to make a decentralized open-source digital currency, without a central bank or single administrator. Here, is the link to the proposed whitepaper by Satoshi Nakamoto
This article will explore how cryptocurrency works, from transactions to data storage. Since Bitcoin is the first and most well-known cryptocurrency, I will focus on it in this article.
Bitcoin ≠ Blockchain
It is a common misconception that people use the word blockchain and Bitcoin interchangeably, but that's not true
Bitcoin is not just a coin but a protocol based on blockchain technology. A protocol is a set of rules that guide the participants on the network to communicate with one another. An example of a protocol for bitcoin is how bitcoin should manage public and private keys for authentication, how mining should be done for transactions to be confirmed, etc. Ethereum, waves, neo, and ripple are a few other examples of similar protocols like bitcoin.
Like Bitcoin and Ethereum, a protocol has a coin typically named after the protocol name, enabling human interaction. This coin is used to reward people who mine, add blocks to the blockchain, and, most importantly, buy stuff from one another.
Tokens are layer three and rely on smart contracts constructed on protocols from layer 2. Ethereum is the most popular protocol for creating smart contracts and for creating tokens. Bitcoin protocol does not have tokens because it does not support creating smart contracts on their protocol.
A Secure Alternative to Traditional Banks 🤔
Let us first examine how blockchain and traditional client-server architecture function to comprehend cryptocurrencies truly.
Client Server Architecture
The basic concept of this architecture is that the client(user) will make an HTTP request to the server, and if everything is correct, it will send back that webpage served from the centralized database as a response.
All data is stored on a centralized server controlled by the bank and companies is a huge issue. Furthermore, because the data is housed on a centralized server, the likelihood of the server being hacked is very high, implying that your data and privacy are at risk.
Blockchain
Blockchain solves two significant flaws in traditional client-server architecture, i.e., data privacy and data security. Blockchain is a distributed immutable ledger that is completely transparent.
Let's break down the definition in simple terms. Distributed means that the data is stored in a network of computers, eliminating the need for centralized servers. You can think of ledgers as an account book, keeping track of all the transactions taking place on the blockchain, and it is immutable, meaning that once data is added to the blockchain, it can never be changed.
Blockchain transactions are encrypted with cryptography, so not everyone can see them. Transactions are shown using a secret code.
Bitcoin Mining
Now that we've covered blockchain fundamentals let's look at how transactions work in the bitcoin protocol. As an example, suppose Bob wishes to send 1BTC to Alice.
Bob conducts a transaction to send money to Alice. The transaction initiated by Bob is initially saved in Mempool (It is an area where all unconfirmed transactions are stored). To add a transaction from mempool to the bitcoin blockchain, miners must first solve a mathematical problem that takes an average of 9 minutes to solve. The miner who solves the mathematical problem first will tell all other miners in the network that it has successfully solved the problem.
Now, other miners in the network will first check if the mined block is genuinely from Bob or a hacker attempting to penetrate the chain. After double-checking everything, the transaction is successfully posted to the blockchain, and Alice receives 1BTC from Bob.
The miner who solves the mathematical problem first will receive a reward or transaction fee in the form of a bitcoin.
Mathematical Problem
Now that we have a fundamental grasp of mining let us look at the mathematical problem miners are solving to add it to the bitcoin network.
When Bob conducted a transaction with Alice, the transaction looked like the one shown below. Each transaction is identified by a Block number, a nonce, data, a previous hash, and a hash.
As the name implies, the block number is the current block number that is to be added to the blockchain. Data contains the transaction details of Bob's wallet to Alice's wallet. In the blockchain, hashes are like fingerprints, and they are used to remember previous blocks. The previous hash contains the hash value of the previous block already mined in the blockchain.
A nonce is a variable value or number that the miner can alter to get the proper hash. All other data in the block, such as the block number, data, and previous hash, are immutable and cannot be changed by anyone.
SHA 256 Algorithm
When this algorithm processes a file, SHA 256 creates an encrypted data file with 64 hexadecimal characters and 4 bits per character.
A hash is generated when we pass block no, data, and prev hash & nonce in SHA 256 algorithm. The bitcoin protocol gives miners a target value, miners change the nonce number to generate hash numbers. The hash generated by miners should be less than the bitcoin protocol's target value to be successfully added to the blockchain. The miner who generates the hash less than the target value first receives a reward for successfully solving the mathematical problem.
To explore the demo yourself, visit this website: https://demoblockchain.org/block
Above is a demonstration of the transaction we were attempting; you can try it yourself on the website. Be sure to observe how the hash changes when you change the block no, nonce, or data in the block. A change like this prevents hackers from hacking blockchains, which we will discuss in the following sections.
Chain Of Blocks
Now that you understand how bitcoin is mined using the SHA 256 algorithm, let's look at how a successfully mined block is added to the blockchain.
The first block on the blockchain is also known as the Genesis block, and its Previous Hash value is 0. Our Bob and Alice transaction is the third block that has been successfully added, with the previous hash value equal to the value of the second block's hash.
Distributed P2P Networks
Let's zoom out a bit to see how this blockchain is kept on decentralized distributed Peer to Peer networks or P2P networks.
If one peer in a distributed P2P network requires data, it will contact the peer who has that data stored. The advantage of a P2P network is that it cannot be hacked by a hacker because the data is stored in multiple locations, and if one data is tampered with, the other data remains safe. We will look at the benefits of P2P in the following section, but first, let's see how the successfully mined block of Bob and Alice is stored in P2P networks.
Let the figure below serve as an example of a P2P network with miners and users.
Consider 'A' to be the miner who, successfully solves the mathematical problem of the transaction between Bob and Alice and adds it to the local blockchain i.e. at block 3. Once uploaded to the blockchain, it will alert the other user on the network of the newly mined block and instruct them to include it in their block. Below is an animation that will help you visualize it.
The other user will first verify that the block mined by 'A' is correct, and then the block will be successfully added to the blockchain.
When the block is successfully added, our peer-to-peer network will resemble the following image.
Resources
So, that’s all folks. This was a quick introduction to how cryptocurrency works, and I hope you learned something new from this blog today. If you want to learn in more depth about blockchain and cryptocurrency in general I recommend you follow the sources mentioned above.