How does the blockchain work?
This distributed-structure blockchain scheme is what makes Bitcoin (and eventually other cryptocurrencies) so reliable. To better understand how this works, let’s take a closer look at the elements that make up the system, starting with the blocks.
blocks
You already know that blocks contain the records themselves. All confirmed transactions — such as the transfer of a Bitcoin amount from one computer to another — must be recorded in them. New transactions generate new records which, as such, must be inserted into new blocks.
In Bitcoin, by default, every ten minutes a block is closed containing all transactions in that period. I must emphasize that this time interval can be different at other times and on other systems that use blockchain.
In addition to the set of transactions, a block must have a code that links it to the previous block (after all, they are connected in a chain), as well as its own code that serves to connect it to the next block.
But how to generate these blocks securely, without the connections being changed to direct to an illegitimate block, for example? Here, the main weapon of the system is the figure of the miner (or miner).
Miners
Remember when I said that one of the ways to earn Bitcoin is by mining? Well then, the complex problems that miners have to solve concern the creation of new blocks and, in effect, the validation of transactions.
A miner is nothing more than a computer (or a set of machines acting as one) that uses specific software to perform the calculations. Whenever the process is completed, the miner is rewarded — here, with Bitcoins.
It works like this: the software analyzes all the information referring to the block and applies a specific mathematical formula on that dataset. The result of the calculation done with this formula is a code called hash . Typically, this code uses hexadecimal base, which, in practical terms, makes it consist of letters and numbers.
Each dataset is unique, so every time this mathematical formula is applied to the block, the generated hash code will be the same. But if the dataset undergoes any modification, no matter how small, the hash code will be totally different. Then you can’t go any further.
In addition to its own hash, the block contains the hash of the previous block. This way, a verification process will be able to notice when a block is not legitimate, as its hash code will be different from the registered ones.
We
As you already know, Bitcoin is a network. Each member of the network is a node . So, if you have a computer with software to transact with Bitcoins, that machine ends up being a node.
This software maintains and helps distribute real-time, up-to-date copies of the block chain in use. Every time transactions are performed and therefore blocks are added, all nodes are communicated so that they can update the records with the new information.
The encrypted communication mechanism (remember, that method of private and public keys) prevents this network from being hacked or nodes from being inadvertently added.
Also take into account that nodes participate in the validation of transactions. A series of procedures is applied to verify if there is a consensus on carrying out a given transaction. So, if you are receiving Bitcoins from someone as a form of payment, a verification process with us will confirm the transaction.
This transaction will then be recorded on the blockchain. As this record cannot be deleted, in theory, no one can take these Bitcoins from you by making changes to the blocks.