How does Blockchain work?
By: Verified On Chain
Tags: Blockchain Technology, Blockchain Development, Blockchain, Peer To Peer, Bitcoin

Before starting with how Blockchain works, we must understand what Blockchain is and how it’s different from traditional systems.

What is Blockchain?

A Blockchain is like a ledger where transactions are stored. However, this Blockchain is shared in a network that contains many participants. Here, the meaning of sharing is that every participant of the network has a copy of the ledger in his system. These participants join the network by downloading a copy of Blockchain and connecting to other participants. In a nutshell, Blockchain is simply a data structure to store transactions.

How is Blockchain different from traditional systems?

Network architecture: The traditional system is centralized and works on a client-server architecture. In a client-server architecture, the data is stored in one place (the server) and clients have to request for access. The server then provides this access.

Blockchain does not follow a client-server architecture. It is, rather, based on the peer-to-peer model.

There is no server in a peer-to-peer model. Here, nodes are connected to each other directly, forming a mesh type of network. The data is not present in one place. Suppose, the above picture represents a Blockchain network. The systems present in this network are called as nodes, which are essentially computers or any other systems with internet connectivity. A node must download a copy of the Blockchain to participate in the network and must connect with other nodes. The data that is downloaded comes from the connected nodes; for example, BitTorrent. In centralized systems, data is vulnerable to a denial of service attack, because it is centralized. If anyone attacks the server, the server will also be down for others and won’t respond to their requests. Essentially, a centralized system has a single point of failure and if an attacker attacks a node in Blockchain network, even if it is a successful attack, it won’t affect the network as there are multiple copies of ledgers.

Central authority: In a traditional system, you need to trust a single central authority for data management. For example, when you send money to someone, the bank decides whether the transaction will go through or not. But in Blockchain, there are multiple nodes that verify a transaction and decide which transaction will go through. Thus, Blockchain is a decentralized network

Censorship: A centralized system is prone to censorship; for example, Twitter banning accounts or deleting tweets. The central authority has complete access to the system and can perform any action on it. But, once a piece of data is in the Blockchain, it cannot be changed since it is an immutable data structure. Thus, making Blockchain censorship resistant.

Accessibility: In centralized systems, there can be a restriction on viewing something. However, in Blockchain, there is no restriction on access. A user can see every transaction happening on the Blockchain network, without his/her personal identity being revealed.

Note: The centralized database discussed here very traditional. Nowadays, a decentralized database is used owing to the single point of failure. But the degree of decentralization of these systems is inferior to the degree of decentralization in Blockchain.

How does a Blockchain work?

Blockchain is a ledger which contains transactions. To transact in Blockchain, one needs the following:

An address

An address in Blockchain is like an account number in banks. If you are sending money to someone, you are essentially sending the money to an account number. In Blockchain, your account number is your address. In banks, you have your personal details linked with your account number; in Blockchain, you never upload your personal data. Thus, an address cannot be linked to a real identity. Blockchain is also pseudonymous, where your pseudonym is your address. An address is an alphanumeric text which is unique to each user. While it is generated from a public key, it is an address that cannot be used to generate a public key

A private key

As the name suggests, it is a key that is meant to be kept secret. It is used to identify the authenticity of a transaction in Blockchain and provides you access to your funds. Whenever you transact in Blockchain, you digitally sign your transaction.

Since you’re the only one who knows the details of the private key, if have put your signature in a transaction, it means that only you have sent the transaction for verification; it wasn’t sent by an imposter.

A public key

A private key is private to its signer and used to verify a signature without revealing any information of private key. So, how can one verify the transaction? The verification of a transaction is done using the public key, generated using a private key. The public key is generated using a complicated mathematical function called the Elliptic Curve Digital Signature Algorithm (ECDSA).

Now that you know these three keys, let’s see what a transaction in Blockchain looks like

A typical transaction in Blockchain consist of 2 things:

Inputs

Inputs contain 2 things.

Previous transaction hash: Since Blockchain is a ledger that stores transactions. So, to spend a value, you must prove that you own the amount you are transferring. The verification is performed by referencing a previous transaction in which you received a certain amount.

Suppose, Bob received $2 from Alice. If Bob wants to send $2 to Dave, he will reference the transaction in which Alice paid Bob $2.

The digital signature: In order to authenticate the transaction, Bob will sign this transaction digitally; he will further use his public key to verify this signature. Now, the input contains a reference to the previous transaction’s signature and public key.

Output

The output contains 2 things:

Address of the recipient: An output consists of the address of the recipient to whom Bob is sending the money (Dave in this case). Dave will give Bob the address where the money is to be sent. Just like in banks, the recipient gives you his account number.

Amount: It is the value of the money being transferred, in this case, it is $2.

This is how a transaction looks like in Blockchain.

(Note: A transaction has transaction fees as well. But for this blog, it is not important)

Once a transaction is created, it will be broadcasted to the network. Basically, Bob will send this transaction to the other nodes. Until now, the transaction is only created and is unconfirmed. It needs to be verified before it is entered into the Blockchain. This verification is done by miners, who are essentially systems in the network, which verify transactions and add it to the Blockchain. While miners are nodes, they have the additional responsibility of verifying unconfirmed transactions and adding it to the Blockchain. So, whenever a transaction is broadcasted, it gets stored in the miners’ systems, in a place called the ‘unconfirmed mempool of transaction’. Miners never add single transactions to the Blockchain; they take multiple unconfirmed transactions from their mempool, create a block, and then add the block to Blockchain. Thus, a Block is a structure which contains many transactions.

Hence, the difference between a miner node and a verifier node is that a verifier node never creates a block. It will simply add the block created by a miner into his ledger without verifying the entire block.

Along with the transaction, a block contains one more part: a block header. In every block header, there are multiple components, which might make it a little too complex for this post. We can probably come back to it another time.

In order to create a block, a miner takes the unconfirmed transactions, verifies them, and creates a block; this can end up becoming a challenging process. To create a block, a miner must solve a mathematical puzzle, which is very expensive (in terms of electricity consumption). This puzzle helps eliminate bad players from the Blockchain. For using this expensive method, miners may be rewarded with network tokens. For example, in Bitcoin Blockchain miners get Bitcoins on a successful addition of Blockchain. Bitcoin is a virtual currency, of which Blockchain is the underlying technology. So, miners compete to add a block in Blockchain. The first one to solve the puzzle and thereby creates a block, wins. He will get the reward, also known as a block reward, and the transaction fees from the transaction in the block.

When a miner creates a block, he adds the block to his own ledger. But, there are many copies of Blockchain. To get the reward and fees, the block that this miner has created needs to be present in the majority of copies of the Blockchain. This synchronization is done using the consensus algorithm where the network approves the block created by the miner.

The example that we have used here is a proof-of-work consensus algorithm in which a miner must work to create blocks. The work involves solving the mathematical puzzle.

Now, when a miner creates a block he will add it to his copy of Blockchain.

2. He will then broadcast this block to the network, along with the solution to the puzzle.

3. Other miners will verify the transactions and the solution. If everything is correct, this block will be added to their ledger.

4. An important thing to be noted here is that that verification of the solution is simple and inexpensive, even though finding the solution may have been challenging.

This is how a Blockchain network works. To be more specific, this how a proof-of-work Blockchain works.