How Cryptocurrency Works Explained Visually

Narottam04 - Jan 29 '22 - - Dev Community

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

In this article, we will explore how cryptocurrency actually 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 the technology of Blockchain. Protocol is set of rules that guides the participants on the network how to communicate with one another. An example of a protocol for bitcoins is how public and private keys for authentication should be managed, 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.

This protocol, like Bitcoin and Ethereum, has a coin that is typically named after the protocol name, which enables human interaction. This coin is used to reward people who mine, to add blocks to the blockchain, and, most importantly, to buy stuff from one another.

Tokens are layer 3 and rely on smart contracts that are constructed on protocols from layer 2. Ethereum is the most popular protocol for creating smart contracts and for creating token. Bitcoin protocol does not have token because it does not support creating smart contract on their protocol.

blockchain protocol

A Secure Alternative to Traditional Banks 🤔

To truly comprehend cryptocurrencies, let us first examine how blockchain and traditional client-server architecture function.

Client Server Architecture

Basic concept of this architecture is, client(user) will make a http request to the server and if everything is correct it will send back that webpage served from the centralized database as a response.

Client server architechture

The fact that 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 is at risk.

Blockchain

Blockchain solves major two flaws that are present in traditional client server architecture i.e. data privacy and security of data. Blockchain is a distributed immutable ledger which 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 it is added to the blockchain, it can never be changed.

Blockchain transactions are pseudonymous, so you can see other people's transactions but not alter the data contained within them. Some cryptocurrencies do allow you to encrypt a data payload or require it by defualt.

p2p network

Bitcoin Mining

Now that we've covered the fundamentals of blockchain, 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 in order 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 miner 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.

It should be noted that the miner who solves the mathematical problem first will receive a reward or transaction fee in the form of bitocin.

blockchain mining

Mathematical Problem

Now that we have a fundamental grasp of mining, let us look at the mathematical problem that miners are solving in order 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.

The block number, as the name implies, is the current block number that is to be added to the blockchain. Data contains the transaction details of Bob wallet to Alice 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 that is already mined in the blockchain.

blockchain blocks

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 by nature and cannot be changed by anyone.

SHA 256 Algorithm

When a file is processed by this algorithm, SHA 256 creates an encrypted data file with 64 hexadecimal characters and 4 bits per character.

SHA 256 algorithm

Hash is generated when we pass block no, data and prev hash & nonce in SHA 256 algorithm. Miners are given a target value by the bitcoin protocol,

The hash generated by miners should be less than the bitcoin protocol's target value in order to be successfully added to the blockchain. Miners change the nonce number to generate hash numbers, and the miner who generates the hash that is less than the target value first receives a reward for successfully solving the mathematical problem.

To explore the demo yourself visit to this website: https://demoblockchain.org/block

blockchain demo

Above is a demonstration of the transaction that 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 have a basic understanding of how bitcoin is mined using the SHA 256 algorithm, let's look at how a successfully mined block is added in the blockchain.

The first block on the blockchain is also known as the Genesis block, and it’s 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.

chain of blocks

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 benefit of this P2P network is that it cannot be hacked by a hacker since the data is kept in many locations and if one data is tampered with, the other data will stay safe. We will look at the benefits of p2p in the following section, but first let's see how the successfully minned 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.

P2P network initial

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 own block. Below is an animation that will help you visualize it.

p2p mining gif 1

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.

p2p mining gif 2

When the block is successfully added, our peer-to-peer network will resemble the following image.

p2p network after adding block

Resources

https://media.giphy.com/media/l4pTjOu0NsrLApt0Q/giphy.gif?cid=ecf05e47dtlkk3fe19ovkz96zbsihgjhtu6injewu9oy5v8e&rid=giphy.gif&ct=g

So, that’s all folks. This was a quick introduction of 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 following sources mentioned below.

For more such insights, checkout my blog website blog.webdrip.in

. . . . . . . . . . . . . . . .