DEV Community

Cover image for How Cryptocurrency Works Explained Visually
Narottam04
Narottam04

Posted on • Updated on

How Cryptocurrency Works Explained Visually

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

Top comments (36)

Collapse
 
johnkazer profile image
John Kazer

You imply that a Blockchain and cryptocurrency are more secure than data held by a bank. But evidence suggests that hacks of crypto systems are frequent and NFT markets full of fraud.
I can accept that in principle security is better but practice currently suggests a lot of poor coding practice and lack of user protections.

Collapse
 
gklijs profile image
Gerard Klijs • Edited

If so, banks are less secure because?
At least banks have a lot of regulation, and for example here in the Netherlands, if a bank fails your money is still to a degree guaranteed by the government.
And yes they can be hacked, but we can easily discount that by the same reason right? It's not the bank system as a whole, it's just a single bank that made a mistake?

Thread Thread
 
yournewempire profile image
Archie Smyth

Hello. I totally agree with your point about your money being guaranteed to a degree. It would be tragic if a bank did not resolve something like that, and this rarely happens from my perspective. Traditional banks are not necessarily absolutely less secure and I totally understand your point. Security is not crypto's best talking point in my opinion. As Fran says, you must accept the possibility of poor smart contract code before slamming the protocol that the developer has written the code on. Even the smart contracts that inherit the secure ERC-20 token standards, may have some custom functionality which handles the tokens that is insecure. Sending and receiving the native Ether token on the protocol layer is working securely.

The ability for people from developing countries to have the same access is a huge positive that fiat currency cannot offer.

Collapse
 
maceypratt profile image
MaceyPratt • Edited

Hey everyone! I'm bumping this old thread to add my thoughts. It's incredible to think of how much growth and innovation has come in the world of cryptocurrency as a result of the 2008 financial crisis. Satoshi's whitepaper and vision have truly been revolutionary. Thanks for bringing this fascinating discussion to the forum! For anyone looking to get into trading and investing, I'd definitely recommend doing some research. A great way to start is by checking out books on trading for beginners. I found this article with 3 new books to consider: fbs.com/blog/top-3-new-books-of-tr.... I'm sure y'all will find something amazing to jumpstart your journey!

 
yournewempire profile image
Archie Smyth

Yes, I agree. This point you have made here reveals another benefit of crypto - the user has control over there assets, provided that the network is stable. As you say, it is the users fault for any mistakes. Nicely put. This would most likely teach users to be more meticulous and careful with their wallet. Fun discussion !

Collapse
 
iamaer4fa profile image
Andres Magalang • Edited

Blockchain transactions in Bitcoin are not encrypted. They are public, it is pseudonymous not anonymous.

Unlike in other cryptocurrencies like Pascalcoin where you have the option to encrypt a data payload or mandatory.

Collapse
 
narottam04 profile image
Narottam04

Thank you for correcting my mistake. I have made the necessary changes.

Collapse
 
iamaer4fa profile image
Andres Magalang

:)

Collapse
 
cess11 profile image
PNS11

If your threat model is 'cops will soon be involved in my finances because I deal in contraband' BTC might be "a [more] secure alternative".

But that's about it. You really, really need the absurd friction costs of doing criminal business to make the gas fees, lacking regulation and unaccountable or fraudulent institutions worth the effort to endure.

Collapse
 
johnkazer profile image
John Kazer

Gas fees do seem to vary a lot by platform. Which also seems an area in need of greater clarity and transparency.

Collapse
 
johnkazer profile image
John Kazer

@franjurinec I think you missed my main point, which was not about the principle (where I mostly agree with you) but about the practice, or implementation. So for example software linked to Solana just got hacked and coins to the tune of $320 million stolen. The Solana dev team are now responsible for retrieval of those coins - and have asked for them back... Which isn't much in the way of user protection.

Collapse
 
dhanmoni profile image
Dhanmoni Nath

That clears up a lot of confusion. Thank you!

Collapse
 
leewynne profile image
Lee

This is such an good post, I have added it as a guide to crypto on the MetaPunk Forem

Really enjoyed reading it

Collapse
 
narottam04 profile image
Narottam04

Thank you for sharing ❤️

Collapse
 
leewynne profile image
Lee

No probs -feel free to cross post with the original Canonical URL of course! Would love to have this on MetaPunk

Collapse
 
sahilpisal3105_44 profile image
SAHILPISAL3105

Very well explained!!! Good Work

Collapse
 
narottam04 profile image
Narottam04

Thank you!

Collapse
 
kamranation profile image
Kamran Baghirov

Thank you!

Collapse
 
aliraza211 profile image
AliRaza211 • Edited

I greatly appreciate your honesty and how this worked out for you. I’m trying to learn this and integrate this strategy into my portfolio, just wanna do it right. This helps a lot.

Collapse
 
narottam04 profile image
Narottam04

Glad you liked it!

Collapse
 
aman0210 profile image
aman0210

Very well explained!! Great work vro

Collapse
 
narottam04 profile image
Narottam04

Thank you bro❤️

Collapse
 
rockhold profile image
Brandon Rockhold

Thank you for this write up. The depth of detail here feels perfect!

Collapse
 
narottam04 profile image
Narottam04

Glad you liked it! ❤️

Collapse
 
andrewbaisden profile image
Andrew Baisden

Great explanation this is a topic that comes up a lot.

Collapse
 
narottam04 profile image
Narottam04

Thank you! Glad you liked it❤️

Collapse
 
omkarrgavhane profile image
Omkar Gavhane

Nice article ...Very well explained !!

Collapse
 
narottam04 profile image
Narottam04

Thank you❤️