DEV Community

Cover image for Part 1: How Blockchain Works: Foundations Behind Bitcoin
Avijit Srivastava
Avijit Srivastava

Posted on

Part 1: How Blockchain Works: Foundations Behind Bitcoin

Imagine a ledger that anyone can read, no one can secretly change, and everyone collectively maintains—this is the core idea behind blockchain.

The question is "What is Blockchain ?"
Blockchain is nothing but a chain of blocks. :) okay, but what do I mean by a block ?
A block is a part of the ledger — a container that stores a batch of transactions.
Hahaha, now what is a ledger ? So many questions right now...
A ledger is kind of a book or a database where we can write down who paid whom, when and how much.

Okay, got it—so a block is basically a box that contains information about transactions.

But a block doesn’t stop there. Along with transactions, it also contains:

  • A reference (hash) to the previous block

  • A timestamp

  • And some additional metadata used for verification

Because each block points to the one before it, they form a chain—hence the name Blockchain.

A block would look something like this:

We will see, all these jargon in later parts of the blog.

This linking is done using cryptography, which means if someone tries to change a past transaction, every block after it would also need to be changed. In practice, that makes tampering extremely difficult.

I will introduce one more jargon here, then we will go in-depth of every thing i mentioned.
There is this one term, you will hear a lot - "Node".
A node is a computer that helps store, verify and distribute blockchain data, ensuring the network remains decentralized and trustworthy.

Okay. so who creates node ?
Literally anyone can create a node in public blockchain. But, we have to understand very important thing here.
Running a node comes with a cost:

  1. Storage costs (Because we are storing every blocks created in a network).

  2. 24*7 up-time (Because a node must be fully up to date).

  3. Running a node requires consistent internet bandwidth.

There are various other factors a well, therefore, we can observe it in any blockchain,there would be millions and billions of users but node will be limited in numbers.

Like in case of Bitcoin, there are millions of users, but i guess, total of approximately, 22000 nodes are present.

Okay, let's create a mind map for summarizing above things:
Blockchain

Okay, so Blockchain fundamentals are clear. Let's move to some of the cryptocurrency. We will start with Bitcoin and go deep into its internals.

The first and important question is, Who creates these blocks ?
The answer is "Miner".
Okay, so is it like, Miner comes with some transactions, creates a block and adds it into the blockchain network ? Hell Noooooo ... :(

Two questions are coming in my mind right now ?

  1. How will Miner know about the transactions to include in the block?
  2. How will Miner create a block ?

Let's answer these questions first, and things will be clear afterwards.

  1. There are various transactions that occurs in the network, it's the work of the Node to verify the transaction and add it to the mempool.

Wtf is this mempool ?
A temporary storage area where transactions wait before being included in a block.

What happens when a transaction is broadcast?

  1. When someone sends a transaction:
  2. The transaction is broadcast to the network
  3. Nodes receive the transaction
  4. Each node verifies it (valid signature, enough balance, etc.)
  5. If valid, the transaction is stored in the node’s mempool.

Then what?
From mempool, Miners pick-up the transactions to include in the block.

Okay, so we got the answer for the first question. Now the point is, how will miner create a block successfully ?

Miners now have transactions, but to create a block, he needs to show "Proof Of Work".
Bitcoin network works on Proof Of Work.
It is a system where miners solve complex mathematical puzzles to prove that they did computational work and earned the right to add block in the blockchain.

Okay, thik hai, But how does the whole process work ?

  1. Miners gather valid transactions into a block.
  2. Miners compete to find a number(nonce) that makes the block's hash meet a specific condition.
  3. The miner broadcasts the block, and if it’s valid, the network accepts it.

I can show you some of the problem statements of Proof Of Work:
Note: these are simplified examples to explain the concept. Bitcoin’s actual difficulty target is more complex.

  1. Find a number (nonce) such that when you hash the block data with that number, the resulting hash starts with at least three zeros.

  2. A miner must find a nonce so that the SHA-256 hash of the block header ends with two zeros.

Okay, so let's just summarize this:
Proof of Work is the process of finding a nonce such that the resulting hash of a block meets a specific condition (difficulty target).

Okay, so now, we know little bit about Bitcoin network. Let's ask ourselves more questions.

What will happen if let's say two miners completes the mining process at the same time ?

Think about it little bit, what could be the best possible answer for this?

In this case, the blockchain temporarily splits into two versions. This situation is known as temporary fork.

Okay, ye sab to thik hai, but what's the solution ?
"Longest Chain Rule": Chain with the most cumulative Proof Of Work wins.

Cool, but what will happen to the discarded block and transactions inside it?

Don't worry :) Transactions from the discarded block are not lost instead,
1. They go back into the mempool.
2. They can be mined again in future blocks.

You know what, this is why confirmation matters a lot.
When you hear: "Wait for 6 confirmations" etc.
It is because:
A transaction in block might be reversed.
Bitcoin’s creator, Satoshi Nakamoto, suggested 6 confirmations as a good balance between:

  1. security
  2. waiting time

Wait Wait Wait !!!
When i transfer money using a wallet, I don't see any confirmation message, instead I see that money is transferred ?

Your wallet shows “money transferred” because it’s tracking the transaction in the mempool, not necessarily waiting for confirmations.

What actually happens when you send Bitcoin?

  1. You create a transaction _Your wallet creates a signed transaction and broadcasts it to the network. _
  2. The transaction enters the mempool _Nodes receive and verify it, then store it in their mempool. _
  3. Your wallet shows it as “sent”
    Because your wallet has successfully broadcasted the transaction and the network has accepted it into the mempool.

  4. Now it waits for confirmations
    Miners pick it up from the mempool and include it in a block.

Most wallets are designed for user convenience, not technical detail.
So instead of showing “0 confirmations” they show:

  1. Transaction sent or
  2. Pending

Because from a user experience perspective:

  • The transaction is already broadcast

  • The user doesn’t need to know the exact confirmation count

So does that mean the money is already transferred?
Technically: Not fully.
It’s pending until it gets confirmed.

Everything is fine, but How does a Miner know what Proof Of Work, he needs to perform to create a block?

There are two possibilities here:

  1. Miner runs their own full node.
  2. Miner does not run a node:
    1. Mining Pool Setup:
      • The pool operator runs full nodes.
      • Miner only:
      • Receives block templates. Pool Operator decides which chain to mine on or which transactions to include.
    2. Connecting to a public / remote node:
      • Miners connects via RPC to someone else's node.

You can read more about Pool Operators and their functionalities in the web.

In the next blog, I will be covering some of the technical aspects of the same. Like, how node verifies the transaction ? What actually happens if someone tries to fraud? etc etc.

_THANK YOU ! _

Top comments (0)