When **mining** (prospecting) two birds are killed with one stone: On the one hand, the so-called “double-spending” problem is solved. This prevents the same bitcoins (by the rightful owner) from being issued multiple times. On the other hand, this also regulates the “production” of new bitcoins. The mining process begins with …

### The verification of (new) transactions by the miners

In the previous part of the Bitcoin basics it is described how wallets can check whether the Bitcoins of a transaction have also been used lawfully (i.e. by the owner). And precisely these checks are also carried out by a miner. After the miner has successfully checked the new transaction, he saves it in his (local) pool, which only contains new transactions. And from now on the real work of a miner begins. The goal of every miner is namely …

### Solving the current puzzle

With Bitcoin there is always a “cryptographic puzzle” in which the puzzle pieces (mainly) consist of transactions. When a miner has solved a puzzle, the puzzle pieces (transactions) that are part of the solved puzzle are considered confirmed. And then it goes straight to the next round. Since new transactions are constantly being created by wallets, the miners can also constantly try to solve new puzzles.

But how does such a Bitcoin puzzle work?

The puzzle pieces consist of …

1. Old and new transactions

2. A random / variable number (“nonce”)

There is also …

3. A valid solution to the puzzle (a number within a specified range) and

4. A puzzle function that generates a number from **any input data**

The “puzzle function” has two important properties:

- the same input data always deliver exactly the same result (number)
- the result (output) is within a certain range of numbers

The puzzle function accepts any input data. The same output is always generated for the same input. In addition, it is not possible to estimate where the result could be based on the input data.

Let’s take a look at the principle of the puzzle game using a (simplified) example: In this example, our puzzle function is programmed so that the result number (output) is always between 1 and 1000. The following three examples illustrate for which input data the function generates which number. In the examples, “old and new transactions” always mean exactly the same transactions.

Input 1 | Old and new transactions |

Input 2 | 1 |

output | 827 |

Input 1 | Old and new transactions |

Input 2 | 2 |

output | 390 |

Input 1 | Old and new transactions |

Input 2 | 3 |

output | 542 |

Important: It is not possible to use the input data to find out in which area or even the exact number is returned as the result of the function.

Valid solutions / difficulty

The puzzle function always generates a number between 1 and 1000. If we were to define exactly this area as the area for all valid solutions, a valid solution would always be found for every type of input data. In other words: it couldn’t be easier / easier! So to increase the difficulty of the puzzle we could, for example, set the range of valid solutions to all numbers below 750. Thus, 25% of all numbers that the puzzle function can produce as a result would be outside the range of valid solutions. In the above examples, the first example would not provide a valid solution. To add to the difficulty, we could only accept all results below 500 as valid solutions. This would mean that half of the results that the puzzle function delivers would be invalid. In the above examples, the first and last example would not provide a valid solution. The following applies: the smaller the range of valid solutions, the greater the difficulty of finding a valid solution.

The goal of a miner is always to find a number (“nonce”) where the “puzzle function” returns a number within a range (from the Bitcoin rules) as a result. And how exactly do you find such a number? It’s very simple: just try one number after the other. Until a valid result is found. Whether the numbers are tried one after the other (1, 2, 3 ..) or randomly (345, 12, 9811 ..) has no effect on the probability of finding the correct result. By the way, on average a miner finds a valid solution every 10 minutes. Before we look at what happens after a miner has found a solution, we first have to answer the following question:

### How are transactions summarized or kept?

So far we have only always viewed the transactions as individual “pieces of data”. This is how new transactions are spread within the Bitcoin network. As soon as a miner tries to find a solution for the current puzzle, these individual transactions are summarized in a data container. Such a data container is comparable to a drawer in a filing cabinet:

The index cards correspond to the transactions. A single drawer (containing transactions) is called a “block” in Bitcoin. By the way: just like the physical drawer, a block also has a limited capacity / size. In other words, a block can only contain a certain number of transactions (at most). The whole filing cabinet is called “blockchain” in Bitcoin.

Kartei-System | Bitcoin |

index card | transaction |

drawer | Block |

closet | Blockchain |

In addition to the actual transactions, a block (drawer) also contains metadata such as the nonce (a valid solution to the puzzle). Incidentally, a valid solution to the puzzle is called a proof-of-work at Bitcoin.

And with this knowledge we can now better understand the answer to the (previously asked) question:

### What happens after a miner finds a solution?

As soon as a miner has found a valid solution to the current puzzle, he will create a new block that contains the following things1:

- a valid solution to the puzzle
- new transactions (which he used to solve the puzzle)

In addition to the normal transactions, he will also insert a special so-called Coinbase transaction that he has created himself into the block. This transaction is the reward for finding a solution and has the following properties:

entrance | (none) |

output | any bitcoin address |

amount | 12.5 BTC |

After the miner has now completed the block, he will send it to the Bitcoin network. Each participant (wallets and miners) will then check whether the block adheres to the currently valid Bitcoin rules. For example, a check is made to determine whether only the permitted amount of 12.5 BTC was actually specified in the Coinbase transaction. Of course, it is also checked whether the “nonce” (solution of the puzzle for this block) is valid.

By the way: In contrast to finding the “nonce”, the computational effort required to check for its validity is minimal.

After a participant has successfully checked a new block, he will append it to the end of his (locally stored) blockchain and consider the transaction contained therein as “confirmed”. And this is exactly how the consensus about legitimate transactions comes about with Bitcoin!

The whole mining process again …

### Summarized

A miner constantly receives new transactions via other miners and wallets. He checks this against the corresponding Bitcoin rules. If the transaction is valid, the miner stores it in his local transaction pool (for new transactions). The miner fetches transactions from this pool in order to solve the puzzle. If he has found a number (nonce) which, together with the new (unconfirmed) transactions selected by him, produces a valid result in the puzzle function, he has solved the puzzle. He then creates a new block with the corresponding transactions and the solution to the puzzle (nonce) and sends them to the Bitcoin network. The new block then spreads within a few seconds among all participants who are currently connected to the Bitcoin network. Each participant checks whether the new block adheres to the Bitcoin rules. If so, it adds it to the end of its local blockchain and sends it to other wallets and miners on request.