DEV Community

Cover image for Blockchain and Bitcoin Explained in 6 Episodes — Episode 3
Christian Ahrweiler
Christian Ahrweiler

Posted on Originally published at Medium

Blockchain and Bitcoin Explained in 6 Episodes — Episode 3

Episode 3: Bitcoin as an Application of Blockchain Technology

Episode 3: Bitcoin as an Application of Blockchain Technology*In the first two episodes, we explained how a blockchain is built, secured, and stored across many independent nodes.*Now we look at a practical application of this technology: Bitcoin.

Bitcoin has its own blockchain, its own network, and its own rules.

The data blocks in this blockchain store Bitcoin transactions.

What Is a Bitcoin Wallet?

To use Bitcoin, you need a wallet — something similar to a purse or a physical wallet.

A wallet is an app or a small device that allows you to receive, hold, and send Bitcoin.

It displays the available amount and provides basic functions similar to those of a banking app:

  • Receive Bitcoin
  • Display the available amount
  • Send Bitcoin
  • Display previous payments For now, we can imagine that the Bitcoin is stored directly in the wallet.

Anna has 1.0 Bitcoin in her wallet and wants to send 0.3 Bitcoin to Anne.

Anna’s wallet
Available 1.0 Bitcoin
Send 0.3 Bitcoin
Recipient AnneAnna confirms the payment. Her wallet creates a Bitcoin transaction and sends it to the Bitcoin network.

How Does a Wallet Receive Bitcoin?

Every wallet can generate a receiving address.

This address can be shared like a bank account number. Anyone who wants to send Bitcoin to Anna enters Anna’s receiving address as the destination of the transaction.

Payment to Anna
Recipient Anna’s Bitcoin address
Amount 1.0 BitcoinThe address does not contain a name and does not automatically reveal who owns it.

Anna can also use multiple receiving addresses. The wallet manages these addresses and combines the associated amounts into one displayed balance.

Where Is the Bitcoin Actually Stored?

The idea that the Bitcoin is stored directly in the wallet is helpful — but technically, it is not entirely correct.

A banking app does not contain the euros in a bank account either. It only displays the balance and provides access to it.

With Bitcoin, there is no central bank. The information about the available amounts is stored in the Bitcoin blockchain.

The wallet reads this information and shows Anna the amount she can use.

The wallet also manages secret information that allows it to digitally authorize a payment for Anna.

How this authorization works is not yet important for understanding the next steps. What matters for now is:

  • Only Anna’s wallet can authorize the use of her Bitcoin.
  • The secret information is not published.
  • Other participants can still verify that the authorization is valid.
  • Changing the payment afterward would invalidate the authorization. The wallet therefore does not contain the Bitcoin itself. It manages access to the amounts recorded in the blockchain.

How Does Bitcoin Store an Amount?

The Bitcoin blockchain does not contain a simple list of account balances:

Account balances
Anna 1.0 Bitcoin
Anne 0.5 BitcoinInstead, it contains transactions.

An earlier transaction may have established that Anna can use an amount of 1.0 Bitcoin:

Earlier transaction
Available amount 1.0 Bitcoin
Available to AnnaAs long as Anna has not transferred this amount, it is considered unspent.

Bitcoin calls such an available amount an Unspent Transaction Output, or UTXO.

This simply means:

*A UTXO is an amount from an earlier transaction that has not yet been transferred.*The wallet finds the available amounts that Anna can use, adds them together, and displays the result as her balance.

Anna Pays Anne

Anna wants to send 0.3 Bitcoin from her available amount of 1.0 Bitcoin to Anne.

Her wallet creates a new transaction.

A Bitcoin transaction does not simply subtract 0.3 Bitcoin from a stored account balance. It uses an existing amount in full and creates new available amounts from it.

New transaction
Uses 1.0 Bitcoin from Anna
To Anne 0.3 Bitcoin
Back to Anna 0.6999 Bitcoin
Fee 0.0001 Bitcoin
Authorization by Anna’s walletThe original amount of 1.0 Bitcoin is now considered spent.

In its place, two new available amounts are created:

New available amounts
0.3 Bitcoin for Anne
0.6999 Bitcoin for AnnaThe amount returned to Anna is called change.

This is similar to paying with cash. If someone uses a 10-euro note to buy an item for 3 euros, the complete note is spent and 7 euros is returned as change.

The small remaining amount of 0.0001 Bitcoin is the transaction fee.

The Wallet Authorizes the Transaction

Before sending the transaction, the wallet adds a digital authorization.

This authorization belongs specifically to this transaction.

If the amount or recipient were changed afterward, the authorization would no longer be valid.

Other participants can verify the authorization without knowing Anna’s secret information.

For understanding the rest of the process, the following is sufficient for now:

*Anna’s wallet can clearly authorize a payment without revealing its secret information.*We explain how this is technically possible separately in Episode 5.

The authorized transaction is now sent to the Bitcoin network.

The Nodes Verify the Transaction

The nodes do not accept Anna’s transaction without checking it.

Among other things, they verify:

  • Does the amount being used exist?
  • Has this amount not already been spent?
  • Is the digital authorization valid?
  • Do the newly created amounts match the amount being used?
  • Does the transaction follow all the rules of the Bitcoin network? If any of these conditions is not met, the transaction is rejected.

If the transaction is valid, the node initially stores it as a waiting transaction and forwards it to other nodes.

This is how the transaction spreads across the Bitcoin network.

Must a Node Search the Entire Blockchain?

No.

As explained in Episode 2, a fully synchronized node has already verified the Bitcoin blockchain from its first block onward.

During this verification, it created a current list of all amounts that have not yet been spent.

This list is called the UTXO set.

Currently available amounts
1.0 Bitcoin for Anna
0.5 Bitcoin for Anne
2.0 Bitcoin for another ownerWhen Anna’s transaction arrives, the node does not have to search the entire blockchain again.

It checks the UTXO set to see whether the amount of 1.0 Bitcoin is still available.

When Anna’s transaction is later added to the blockchain, the node removes the old amount and adds the newly created amounts:

Before the transaction
1.0 Bitcoin for AnnaAfter the transaction
0.3 Bitcoin for Anne
0.6999 Bitcoin for AnnaThe UTXO set is therefore the current state calculated by a Bitcoin node from all previously verified blocks.

This is exactly why a pruned node can delete old block data and still verify new transactions.

Where Does the Transaction Wait?

A valid transaction is not automatically part of the Bitcoin blockchain.

It is first placed in storage for waiting transactions.

This storage is called the mempool.

Every node has its own mempool. The transactions it contains can differ slightly because they arrive at different nodes at different times.

Waiting transactions
Anna sends 0.3 Bitcoin to Anne
Paul sends 0.1 Bitcoin to Maria
Robert sends 0.5 Bitcoin to LisaThe transactions have already been verified, but they are not yet included in a block.

Who now assembles the next block from these waiting transactions?

The Miners

This task is performed by miners.

A miner is a participant in the Bitcoin network that assembles a possible new block from waiting transactions.

The miner selects transactions from its mempool and combines them into a block.

Possible new block
Previous hash Hash of the latest Bitcoin block
Transactions Selected transactions
Nonce Not yet found
Hash Condition not yet metAt first, this block is only a candidate.

Before it can be appended to the Bitcoin blockchain, its hash must meet the current Proof-of-Work condition.

What Does Mining Mean?

Mining is the search for a suitable nonce for a new Bitcoin block.

The selected transactions and the other properties of the block have already been determined. The nonce is now changed and the block’s hash recalculated repeatedly until the difficulty target is met — just like our 00 condition from Episode 1.

Mining
Nonce 1 Condition not met
Nonce 2 Condition not met
Nonce 3 Condition not met
Nonce 4 Condition not met

Nonce 8,245,912 Condition metIn the real Bitcoin blockchain, the condition is far more difficult. An enormous number of possibilities are therefore tested worldwide.

All participating miners work simultaneously on a possible new block.

Mining is not the process of solving a complicated mathematical problem. It is the extremely fast testing of many possibilities until a hash happens to meet the required condition.

Why Does a Block Take About Ten Minutes?

The more computing power participates in the search, the faster a suitable nonce would normally be found.

Bitcoin therefore adjusts the difficulty of the condition regularly.

If blocks are found too quickly on average, the condition becomes more difficult. If they are found too slowly, it becomes easier.

Over the long term, this results in a new Bitcoin block being found approximately every ten minutes on average.

An individual block may still be found after only a few seconds or take significantly longer than ten minutes. The search is based on chance.

A Miner Finds a Valid Block

When a miner finds a suitable nonce, the complete block is sent to the Bitcoin network.

The other nodes do not accept it automatically.

Every node independently verifies:

  • Does the block point to the correct predecessor?
  • Does the block actually produce the stated hash?
  • Does the hash meet the Proof-of-Work condition?
  • Are all included transactions valid?
  • Has any amount been spent twice?
  • Does the complete block follow the Bitcoin rules? Only if all checks are successful does a node accept the block as valid and add it to its copy of the Bitcoin blockchain.

The included transactions are then removed from the mempool and the UTXO set is updated.

Miners can therefore propose new blocks. They cannot arbitrarily change the rules of the blockchain.

The independent nodes determine whether a published block is valid by verifying it themselves.

What Is a Confirmation?

As soon as Anna’s payment to Anne is included in a valid block, it has one confirmation.

When another block is appended, the transaction has two confirmations.

Confirmations
Block containing Anna’s transaction 1 confirmation
Next block 2 confirmations
Another block 3 confirmationsWith every following block, the amount of Proof of Work building on Anna’s transaction increases.

A confirmation does not mean that a central service approved the payment.

It means that the transaction was included in a valid block.

Further confirmations show how many valid blocks have since been built on top of it.

What Does the Bitcoin Blockchain Store?

The Bitcoin blockchain does not store digital coins or simple account balances.

It stores a chronological chain of valid transactions.

From these transactions, every full node calculates which amounts are currently still unspent.

The wallet displays these amounts and allows its owner to transfer them.

The nodes verify transactions and blocks.

The miners assemble possible new blocks and use Proof of Work to search for a suitable nonce.

Together, these components create a payment system without a central bank and without a single operator controlling the database.

Further Episodes

In Episode 4, we examine the history, current size, and future of Bitcoin — from Satoshi Nakamoto’s white paper to the limit of nearly 21 million Bitcoin.We have deliberately left one technical question unanswered:How can a wallet clearly authorize a transaction without revealing its secret information?We explain this in Episode 5 using private and public keys and digital signatures. Anyone who wants to skip this technical excursion can continue directly with Episode 6: How Beaver Proof uses the Bitcoin blockchain to create verifiable timestamps.

Top comments (0)