In the previous article we talked about what a hash function is, and we looked at an example of a hash function. Now let’s talk about what nonce is.
Imagine that we have some kind of text again, let’s say the text is “Hello”. And we are given a task: when we run this text through hash function, we need three zeros at the beginning of the hash result (notably from the previous article, we can’t predict what the hash result will be).
The hash of “Hello” can be only this. Not too much space for creativity!
“This task is nonsense” you would think. How can we influence the result of hash function that is always the same while input is the same?! Obviously, the text should not be changed. So the task is: append any string you like to the text so that the result of applying hash function to (text + string) would have three zeros at the beginning. Therefore, the so-called nonce appears: in simple words it is a string appended to our file.
Now I can hear your resentment: “Oh my! Without being able to predict the result of hashing, I would need to sort through trillions of variations to get a suitable one!” Well… not trillions! The amount of work goes up to 10^20 variations, that’s waay more than just trillions. That is why all the world’s miners spend whopping 10 minutes to get just one nonce so that hash starts with three zeros.
it takes 4 million miners in the world to come up with only one correct nonce in 10 minutes
There are some about 4 million miners in the world. All the world miners are more or less coordinated in searching for the nonce. Our approach is slightly different. We coordinate not whole pool to solve one big task with three zeros, but through the pool we coordinated who goes through what variation, so that one miner calculates with only one string, the other calculates with two, and so on. Keep in mind that we are trying to get such a hash that starts with 000.
Calculating for reward
For example, imagine you have a string.
We need to encrypt this string and at the end we are accepted to write anything.
Here is the expression itself, from which we consider hash function.
This is nonce.
We will get some kind of hash function (there will not be 000 at the beginning, most likely) but we are starting to sort all the variations. One miner goes through 13.5 trillion different nonces in one second. It still takes 10 minutes to find one such combination.
*pic about successful combination*
So what happens next? This miner who came up with the right combination gets the opportunity to award himself 12.5 BTC. That actually happens by adding a new block with recorded info about this bounty. It is so-called block reward. Who creates the next block, that receives the reward, because he has the opportunity to record such a bounty transaction on the new block. Finally, mining in simple words is just a really laborious counting.