How does Blockchain work?
In the context of cryptocurrencies, a blockchain consists of a stable chain of blocks, each one storing a list of previously confirmed transactions. Since the blockchain network is maintained by a myriad of computers spread around the world, it functions as a decentralized database (or ledger). This means that each participant (node) maintains a copy of the blockchain data, and they communicate with each other to ensure that they are all on the same page (or block).
Therefore, blockchain transactions occur within a peer-to-peer global network and this is what makes Bitcoin a decentralized digital currency that is borderless, and censorship-resistant. In addition, most blockchain systems are considered trustless because they do not require any kind of trust. There is no single authority in control of Bitcoin.
A central part of almost every blockchain is the process of mining, which relies on hashing algorithms. Bitcoin uses the SHA-256 algorithm (Secure Hash Algorithm 256 bits). It takes an input of any length and generates an output that will always have the same length. The output produced is called a "hash" and, in this case, is always made of 64 characters (256bits).
So the same input will result in the same output, no matter how many times the process is repeated. But if a small change is made to the input, the output will change completely. As such, hash functions are deterministic, and in the cryptocurrency world, most of them are designed as a one-way hash function.
Being a one-way function means that it is almost impossible to calculate what was the input from the output. One can only guess what the input was, but the odds of guessing it right are extremely low. This is one of the reasons why blockchain is secure.
Example:
Now that we know what the algorithm does, let's demonstrate how a blockchain works with a simple example of a transaction.
Imagine that we have Alice and Bob along with their Bitcoin balance. Let's say Alice owes Bob 2 Bitcoins. For Alice to send Bob that 2 bitcoin, Alice broadcasts a message with the transaction that she wants to make to all the miners in the network. In that transaction, Alice gives the miners Bob's address and the amount of Bitcoins she would like to send, along with a digital signature and her public key. The signature is made with Alice's private key and the miners can validate that Alice, in fact, is the owner of those coins.
Once the miners are sure that the transaction is valid they can put it in a block along with many other transactions and attempt to mine the block. This is done by putting the block through the SHA-256 algorithm.
Once the block is mined the miner broadcasts that newly mined block to all the other miners. They then check to make sure that the block is valid so that they can add it to their copy of the blockchain and the transaction is complete. But in the block, the miners also need to include the output hash from the previous block so that all blocks are tied together, hence the name blockchain. This is an important part because of the way trust works in the system.
Every miner has their own copy of the blockchain on their computer and everyone trusts whichever blockchain that has the most computational work put into it, the longest blockchain. If a miner changes a transaction in a previous block, the output hash for that block will change which leads to all the hashes after it changing as well due to the blocks being liked with hashes. The miner would have to redo all of the work in order to make anyone accept his blockchain as the right one.
Storage Structure.
One key difference between a typical database and a blockchain is the way the data is structured. A blockchain collects information together in groups, also known as blocks, that hold sets of information. Blocks have certain storage capacities and, when filled, are chained onto the previously filled block, forming a chain of data known as the “blockchain.” All new information that follows that freshly added block is compiled into a newly formed block that will then also be added to the chain once filled.
A database structures its data into tables whereas a blockchain, as its name implies, structures its data into chunks (blocks) that are chained together. This makes it so that all blockchains are databases but not all databases are blockchains. This system also inherently makes an irreversible timeline of data when implemented in a decentralized nature. When a block is filled it is set in stone and becomes a part of this timeline. Each block in the chain is given an exact timestamp when it is added to the chain.
Types of consensus algorithms on which blockchain works:
The model of making computers work in order to produce blocks is called Proof-of-Work (PoW) there are also other models like Proof-of-Stake (PoS) which do not require as much computing power and are meant to require less electricity while being able to scale to more users.
Cryptocurrency-Blockchain Mechanism.
Every cryptocurrency works on top of a blockchain, a blockchain works according to a predefined set of rules (i.e. an underlying protocol). The protocol is what defines how the blockchain and the cryptocurrency system should operate.
Last updated
Was this helpful?