Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

How blockchain works: Mining

The structure of the blockchain itself is fairly simple. The clever things happen when new blocks are added to the blockchain.

As you learnt in the last two steps, a blockchain is built up of blocks, each of which contains data. These blocks are arranged in an order and linked together using the hashes.

The structure of the blockchain itself is fairly simple. The clever things happen when new blocks are added to the blockchain. In the video above Evangelos explains the process of mining, and how the blocks come together to form the blockchain.

How does the data get chosen to be include in the blockchain? Who gets to choose which block will be added next? How do you ensure that all nodes in the network have the same version of the blockchain? All of these questions are part of the challenge of implementing a blockchain.

So how does data get chosen to be included?

This depends on the blockchain itself, and whether it is a public or private blockchain. Let us consider a specific example that you may have heard of: Bitcoin. Bitcoin is a cryptocurrency, it is a digital asset with a value and is traded on exchanges in much the same way the foreign currency is traded.

In the Bitcoin blockchain, the data that is stored are transactions of transfers of bitcoin between one person and another. When a transaction request takes place the request gets broadcast to all nodes in the network. The person sending the money incentivises the nodes in the network to include the transaction in the next block by including a transaction fee. The transaction fee is a small amount of bitcoin that the node will get if they include the transaction in the block and the block becomes the next block on the blockchain.

Who gets to choose which block will be added next ?

Again, this depends on the blockchain. Many blockchains use a technique called proof-of-work. In the proof-of-work technique mining nodes compete to solve a hand problem. The mining node chooses which transaction to include in their block; they take the list of transactions, the previous hash, the block identified, and a piece of data called the nonce and hash it. The nonce is just a short sequence of bytes.

The hash of the block will have some value, but to be allowed to include the block in the blockchain, the hash must meet some criteria. For example, the hash might have to start with 10 zero characters. The probability of this happening first time is very low, so the miner changes the nonce and tries again. And they try over and over again until the hash meets the criteria. This is incredibly computationally expensive. This is what is called mining.

As soon as a miner finds a nonce that causes the hash to meet the criteria it broadcasts the block to be validated by the other nodes in the network. As soon as over half of the nodes validate the block it is included in the blockchain.

How do you ensure that all nodes in the network have the same version of the blockchain?

When a node mines a block, they broadcast the block to all nodes for the block to be validated. When the majority of the nodes validate the block then it is included in the blockchain. But wait! What happens if more than one miner finds a nonce for their block and broadcast it at the same time?

Well, the nodes on the blockchain temporarily have different versions of the blockchain. The difference is resolved when the next block is added. The nodes in the network are instructed to always favour the longest chain. Whichever version of the blockchain gets the next block first will become the longest chain and the nodes will favour that. Sometimes many blocks are added before one chain becomes longest. It’s that simple!

This article is from the free online

How to Get Into Blockchain

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now