How Blockchain Works: A Closer Look | by Saumya Kasthuri | Jan, 2024

Blockchain technology is a decentralized and distributed digital ledger that records transactions securely and transparently. Here are the six steps involved in the process of creating, validating, and recording a transaction on the blockchain:

  1. Initiate the transaction
  • The user initiates the transaction using wallet software, which allows them to generate and store sign-in keys, manage cryptocurrency funds, and communicate with the blockchain on their behalf.
  • The transaction is signed with the sender’s private key.

2. Broadcast the transaction

  • The transaction is broadcast to the blockchain network using a protocol such as the gossip protocol.
  • This ensures that the information reaches every other node in the network.

3. Validate the transaction

  • Miner nodes on the network validate the transaction to ensure that it is not malicious and that the funds being transferred have not already been spent (to avoid double spending).
  • They also check that the total value of the output is equal to the value of the input, and that the digital signatures are valid.

4. Mine the transaction

  • Once a group of transactions is ready, the miner nodes add them to a block and update the header with a timestamp and the hash of the previous block.
  • They then compete to solve a puzzle called mining, which involves calculating the hash of the new block until it exceeds the target hash value.
  • The miner that solves the puzzle first gets to append their block to the blockchain and earn a reward in cryptocurrency.

5. Validate the block


  • The miner broadcasts the proposed block to the network for other nodes to validate.
  • The block is only accepted if it meets certain criteria, such as having a valid header and containing valid transactions.

6. Record the transaction

  • Once the block is accepted, it is added to the blockchain and the transaction is recorded.
  • The transaction is now immutable and cannot be changed or deleted.

By following these six steps, blockchain technology ensures the security, transparency, and immutability of the transactions recorded on the blockchain, making it an ideal platform for recording and verifying transactions.

Blockchain Demo by Anders Brown Worth:

Here you can type any data and generate the hash. Sha 256 is used here to create hash.

I have typed the string Message 1 and as you can see the hash adbbe0fa0a1192250a00582811bd8e1a664cd6263ebf92c827f008714514fd68

If I removed the space Message1 the hash is completely changed: 960c9384c0db44a860f1309fa04b2d2ec34370ee0148838b659f65d75bf1c85c

That is what unique about the hashes.

Now let’s look what is inside a block.

Look at the hash there is something unique about it. The first 4 characters are zeros. they are trailing zeros, which is the condition that is used to create proof of work and in order to create the puzzle for the miners to solve.

The miner has to change the nonce a bunch of times with the data that he or she has been given to get a hash which has four trailing zeros or the number of trailing zeros can vary according to different blockchains.

Add the Data Message 1

Click on mine, a new hash was created.

The nonce has been changed and this hash again has four trailing zeros.

What happens here is that the data and the nonce are hashed together to see what kind of hash comes out. If you change the nonce, the hash will change. The miner is throwing multiple nonce with the data into the hashing function, getting a bunch of hashes and checking if each of the hash has this trailing zero or not.

That is exactly how a miner tries to solve the puzzle that he has been given for proof of work.

Now let’s take a look at this blockchain section in that there are multiple blocks here.

There’s a block number one, two, three, and so on. These data, the previous hash and the current hash

Genesis Block : The block in the block chain also known as Block 0
Only block that doesn`t refers to its previous block.
Level of difficulty and consensus mechanisms are defined by this.

For block number 1 ie. Genesis block having the previous hash that is equivalent to zero. That is because this is the first block and there is no other block behind this block.

We have the hash of this specific block with the empty data. It’s nonce is, of course, 11316.

Now, if you look at the next block, which is the block number two, it has some other nonce 35230. The data is empty, but in the previous hash, there is a hash right here.

This previous hash and this current hash of block one, these are the same hashes,

which means block number two is holding the hash of the previous block, which is the block number one, and it has its own current hash as well.

Look at the chain Data as Apple : 9749, Banana: 46377, Citrus 1827

If I change the data in block 2 as “Mango”, see the blocks turned red.

Because when I change the data, the previous hash here was not changed. The current hash has changed; using this nonce (46377) and this different data (Mango) some other hash is produced. The rest of the hashes have completely changed.

There are no trailing zeros in any of these hashes, which means that these are unsolved.

So these have to be mined again, which means that if you try to tamper the data in a blockchain, you will have to mine all these blocks all over again.

Now, although if you see, you may say that you can just click on mine on these three ones and just make sure that it is correct again.

Well, you see for an example of only three blocks, that is possible.

But if you have, let’s say, just about 100,000 blocks or one lakh blocks or ten lakh blocks, then how many blocks are you going to keep mining in order to get the right hashes?

That is exactly what makes a blockchain tamper proof that if you change the data, an entire set of blocks will be null and void, which means that your blockchain won’t be accepted as the right blockchain.

Since the blockchain is set on distributed decentralized network, every peer on the network has its own copy of the blockchain.

Consider here 3 peers: Peer A, Peer B, Peer C.

Peer A is now holding a tampered blockchain. But Peer B and Peer C are still holding the right blockchain, which means that these are the ones that will be accepted.

There are three peers, then why the blockchain of Peer B and Peer C are accepted as the correct one?

In real life, the distributed decentralized network will have thousands and thousands of nodes.

These 1000 nodes have each a copy of the blockchain, and as long as a majority of these peers have the right blockchain, the right blockchain will always stay untampered.

It is only when an attacker has the control of more than 51% nodes on a decentralized network that he or she can tamper the data.

If not, then no one can tamper with the data of the blockchain.

That is essentially what carries the essence of the blockchain in that the blockchain has 100% integrity and it is completely tamper-proof.

References
https://www.blockchain.com/
https://andersbrownworth.com/
https://www.ibm.com/cloud/learn/blockchain-explained https://www.investopedia.com/terms/b/blockchain.asp
https://blockgeeks.com/guides/cryptocurrency-cryptography/