How transactions goes on blockchain ?
Tags: blockchain, web3, computerscience
Published: 2022-07-01 19:24:06

> Want to read about basics of blockchain , Read here👇
 >[https://dev.to/taniskannpurna/blockchain-and-how-its-formed-3gpl]

First we need to get a little bit of more details on how blockchain works...

💜**The Decentralized System**

In the last article, we saw that Blockchain is a decentralized system. So how it achieves this....

- Blockchain is chain of blocks that is connected to each other like a Linked List.
- These blocks contain different data with them like transactional, previous block's hash value, block number etc.
- Now this chain of blocks has to run somewhere like a computer or something.
- Those Computer that run these chains are termed as NODE.
- Now, There are multiple nodes that are connected to each other and these nodes keeps the blockchain up and running.

So, Every node running the blockchain actually runs a copy of the blockchain and Whenever there is a  change in the blockchain i.e. a block is added to the blockchain then every other copy of the blockchain is updated.

Ex. -> Suppose there are 3 nodes (N1,N2,N3) running the copy of the blockchain. Now lets say N1 adds a block to the chain then every other nodes i.e. N2,N3 will update itself by taking the copy of blockchain running on N1 as its most updated.

This way blockchain becomes a decentralized system as there are multiple nodes that can change the state of blockchain. So, the power to change the state of blockchain relies on all the nodes that are running the blockchain.

👉 Now, Remember if N1 adds a block to the chain, and majority of nodes (N2,N3) does not believe that the N1 block is valid, they can reject it and N1 copy of blockchain will be rejected i.e. there will be no update to the blockchain.

We will get into more details on what basis other Nodes can reject an update of a node.

In my previous article , I briefly mentioned about NONCE.

💜 **What is Nonce?**

Nonce is just a special number that helps to achieve certain condition in the blockchain.

We will look into it in more details.

💜 **Who/What is a Miner⛏️⛏️**
people who runs the nodes or anyone who is running that node or making sure that node keeps running is known as a Miner.

You may think that what do those miner gets for running a node. Well, They get paid in bitcoins for running those nodes. You may ask how or who, if there is not a single owner of the blockchain then who pays them... Lets look into it with an example : 

- Whenever there is an transaction in blockchain, that transaction does not go directly into the blockchain.
- Instead It goes into a pool of transactions where a miner can pick the transaction of his choice i.e. of course with the highest payment. 
- Now that miner has to solve a hard problem or do any heavy computational task. In Blockchain the miner has to find a special number which when concatenated with the data in the block and then hashed will provide a value in the format of "0x 0000..."(0x is just a way to tell that its a hexadecimal), The first four character(after 0x) should be zero.
- That special number is called NONCE.
- Now there is no shortcut to find value of NONCE, Miner has to use brute force i.e. check every possible combination to find it.
- You may have seen miners creating huge computational power for their system, That is just to find the NONCE as fast as possible. As whoever first finds the value, will be the first to add the block to the blockchain.
- Now once a minor adds the block, Other minors will check the block and see that correct NONCE was found or not. If not they will reject it and blockchain will not update whereas if correct NONCE was found then they will accept it, Blockchains updates.
- Finally, The Miner gets paid.

This is the way the blockchain runs and handles transaction. The blockchain will only update itself if majority of miners approve the next block else it will reject that block and the race to find nonce number begins again.

Remember...

👉 Not every chain will have same pattern to find, It may vary from chain to chain like Ethereum asks to solve a math problem whose answer is a very huge number.

👉POW(Proof of work) -> Miners finding the NONCE value is the proof of work to other miners. Remember this proof of work may change from chain to chain.

👉 Whenever you do a transaction, It takes around 15-30 seconds to go through. This is because miners are finding NONCE value for the next block. The smaller the payment, the more time to go through as minors will not pick that transaction.

👉 By applying Majority rule, It gives the power to a  distributed system i.e. DECENTRALIZED.

So Let's summarize then...

- Not a single miner or anyone alone can add their transaction i.e. change the state of blockchain.
- The transactions has to be verified by other miners, then only it will be added to blockchain.

These are the reasons that makes the transaction in blockchain so secure.

```
Hello, I am Tanisk Annpurna
I post about

    🚀web3, Blockchain, Ethereum
    🐦Smart Contract, Solidity
    🎉JavaScript, ReactJS, NodeJS  

Follow and like for more such threads.
```
> !!✌️!!