How Bitcoin Mining Works
As against the norm of ‘printing money when needed by nations governments’, bitcoin is discovered by computers that compete with each other around the globe in order to ‘mine’ coins.
How mining takes place
There are number of bitcoin transactions taking place across the globe every moment and there is no record of the data about who was paid or what was paid if it isn’t recorded. This is handled in the bitcoin network by collecting all the transactions made during a particular time period in a list called a ‘block’ and the miners’ compile these transactions into a general ledger after confirmation. Each block is turned into a hash.
Making a hash
The general ledger comprises of a list of blocks which is called ‘blockchain’, which can be used to explore all the transaction made on the network at any given time and between any bitcoin address. The length of the blockchain increases whenever a new block of transactions is created as the list of the transaction recorded on the bitcoin network over time increases. Everyone on the bitcoin network is regularly updated as a constantly reviewed copy of the block is circulated to every participant.
This ledger which is held digitally has to be trusted and the miners play an intricate role here. As a new block of transaction is created, the miners turn it into a shorter, as well as random sequence of letters and numbers known as a ‘hash’ by taking the information in the block and applying a mathematical formula to it and it is then stored along with the block at the end of the blockchain.
Hash has an interesting characteristic with the ability of getting easily produced from a collection of data like a bitcoin block. One cannot determine what the data is by looking at the hash. Though it is easy to produce hash using the large amount of data, each hash is different and unique. A hash entirely changes by only changing a single character in the bitcoin block.
Miners don’t only use the transactions in a block to create a hash; they also make use of another piece of data e.g. the hash of the last transaction in the blockchain. And as each block’s hash is created using the hash of the previous block, they become legitimate and remain tightly interconnected as any change made on it or every block after it would be recognized by every individual on the network.
A fake block can instantly be recognized by vetting the block’s originality by running the hashing function as the block’s hash would change and be completely different from the one already stored with that block on the blockchain. Changing the content of the block makes the subsequent block’s hash wrong as each block’s hash was used in the production of the next block’s hash and the same criteria will continue down the chain.
Competing for coins
There is a competition among miners to seal off blocks by using software written specifically to mine blocks. A small amount of crypto currency is given as an incentive, to continue mining and ensure transactions are continuous, to anyone who successfully creates a hash and update the blockchain and everyone on the network is informed. However, producing a hash from a collection of data is very easy and can be done effortlessly using a computer. Therefore, the bitcoin protocol deliberately makes it demanding by introducing the ‘proof of work’ hereby hindering individuals from hashing multiple blocks each second and consequently having all the bitcoins mined in a matter of minutes.
The bitcoin protocol requires a block’s hash to be visible in a particular way and would not accept any old hash. It must contain a particular number of zeroes at the start and there’s no way of predicting what a hash would look like before it is produced. The hash totally changes once a new set of data is introduced.
It is required that the miners change the data used in creating a different hash as they aren’t permitted to tinker with the transaction data in a block. They create a hash using a ‘nonce’- another random piece of data, along with the transaction data in the block and this nonce is constantly changed with the hashing re-done if the hash doesn’t meet the required format. Getting a working nonce can take a whole lot of trials and all the miners in the bitcoin network try to do it simultaneously to earn their bitcoins.