How does blockchain work?
In this article in the newsletter, I explained exactly how blockchain is working. Most people in the #crypto space may not be aware of this core concept in the #blockchain. Here is an explanation of the technical aspect of the blockchain. Why is it important? Security measures, and creating custom Dapps, and DAOs are some complex use cases of the blockchain. Most importantly, if you want to build a startup on the blockchain, you must understand how it works.
What is a Blockchain? ?
A blockchain is a distributed ledger technology that records transactions across a network of computers. It can be used to store and transmit data in a decentralized, secure manner that is hard to alter or hack. In a blockchain, each block contains a record of multiple transactions, and once data is added to a block, it cannot be changed or removed. Maintaining a record of transactions is thus reliable and transparent.
Unique features of the blockchain
Distributed
When you write data to the blockchain, data is replicated to multiple nodes. A node may hold a copy of the entire database on the blockchain which is sometimes known as a ledger.?
Decentralized
Blockchain is a decentralized distributed system. The nodes on the blockchain communicate with each other with specific core protocols to ensure that are recorded in a manner the user intended.
Immutable
Blockchain is an append-only database. That means someone can’t go back and alter the blocks of data at a previous time. Once data is written into the blockchain, it cannot be altered. This is known as immutability.
Consensus Driven
There is no central authority or governing body to approve the data written into the blockchain. But does it mean anyone can write to blockchain whatever and whenever they want to? Wouldn’t that be a security problem? Blockchain has the feature that data is written into the blockchain if multiple participating nodes approve the data on the blockchain network. In other words, nodes must reach a consensus on what block is added to the chain of blocks.
Highly Available
Since the blockchain is distributed, if some of the nodes malfunction and leave the network or in the worst case, they become rogue, blockchain protocols will ensure the blockchain network continues to remain functional and the data remains accessible at all times.
Blockchain records are public, meaning anyone can see the records of transactions published on the blockchain ledger. Obviously, the public nature of the blockchain allows anyone to audit and spot any discrepancies but it can also be a privacy concern.?
What is smart contract and dApp?
In simple words, a smart contract is a computer program that is a collection of code and data that is stored and executed on the blockchain. Since smart contracts deployed on the blockchain are by nature, distributed and transparent. Any user can interact with a smart contract and execute its function. This feature makes smart contracts vulnerable to attacks. Now, with regular applications, you can patch and redeploy apps frequently and get rid of the code issues. But once you have a buggy code deployed on the blockchain, it is extremely difficult to replace it.
What is the role of smart contracts? Well, think of smart contracts as important building blocks that other users can leverage. Smart contracts are deployed in blockchain-specific languages such as Solidity.?
Decentralized applications or Dapps deployed on the blockchain are a new breed of applications which are also known as Web 3.0 applications. Dapps allow users to trade digital art via Non-fungible tokens or NFTs. E-voting and identity management are specific use cases addressed by many upcoming decentralized apps.?
Decentralized apps are also heavily used in the world of finance today. Many industrial-specific applications are also emerging in the field of legal supply chains and the internet of things.
领英推荐
How does blockchain work?
Let’s see how a transaction is created, validated, and finally recorded on the blockchain. As I mentioned above, a blockchain is a chain of blocks but what is a block? A block is a collection of data structures that includes a header and a list of transactions.?
The blockchain header contains multiple fields that are necessary for blockchain protocols to do their job. Some examples are timestamps, the hash of the previous block, Merkle root, and so on. In that way, the very first block of a blockchain is known as the Genesis block. It doesn’t contain a hash of the previous block since there is none.?
A block contains multiple transactions that are recorded in the blockchain. When a user wants to record a transaction onto the blockchain network, the process follows six steps.?
A node in the blockchain network is a physical entity that can play different roles. Some nodes play the role of a user’s crypto wallet, some play the role of a miner, and some of a validator.?
A user initiates the transaction by using wallet software or hardware. The transaction is signed with the sender’s private key. Wallet software is a utility software used by end users for multiple purposes such as generating and storing sign-in keys, managing the crypto funds, and communicating with blockchain on behalf of the user. Next, the transaction is broadcast to the blockchain network. Broadcast ensures that the information makes it to every other node of the network.?
A commonly used protocol for broadcasting on P2P networks is the Gossip protocol. A blockchain network is a peer-to-peer network of nodes. A node can be someone’s personal computer, a VM in the cloud, or a dedicated data center for blockchain. As the blockchain sits on top of the existing network layer, from a security perspective, it inherits the strengths and vulnerabilities of the underlying network.?
Not all nodes are made equal. At a broad level, there are two types of nodes: full nodes and lightweight nodes. Full nodes maintain a copy of the entire blockchain ledger. Depending upon the role of a full node, it may validate the transaction, add blocks to the blockchain, or may just perform administrative tasks of permitting or denying other nodes from joining the network.?
In contrast, to the full nodes, lightweight nodes keep only a copy of the block headers instead of the entire ledger. Many of the end-user clients act as lightweight nodes and perform transaction validation for one user only. Before the incoming transaction is recorded to the blockchain network.?
First, the miner node validates the transaction is not malicious and that it follows some basic rules such as cryptocurrency funds to be transferred are not already spent. That is, avoid double-spending. The total value of the output is equal to the value of the input of the transaction, basic accounting 101. And lastly, digital signatures are valid to ensure that the transaction is not malicious.?
After validation, miner nodes continue to cache these transactions in their local memory pool in preparation to add them to a transaction block. Recall that a block contains multiple transactions. Once a group of transactions is ready, the miner node adds them to the block, updates its header with a timestamp, and includes the hash of the previous block.?
Many miner nodes follow the same process and arrive at their own version of the block. They all wish to append their block to the blockchain, but only one will succeed. In order to succeed, the miner nodes must solve a puzzle. Solving a puzzle in blockchain lingo is known as mining. Each block header contains 32-bit nodes. By the way, a nonce is just a technical term for a number that can only be used once. To solve the puzzle, the miner must keep calculating the hash of the new block until it exceeds the target hash value, and the only parameter a miner can change is the nonce value.?
No other attribute of the header can be changed after the miner solves the puzzle and arrives at a final hash value which is then stored in the block header, but why mine in the first place? The mining process ensures that miners have spent personal resources which can be computing, storage, or personal stake. Basically, they need to have skin in the game. As a result, the miners are awarded cryptocurrencies.?
Multiple miners may come up with their own version of the proposed block which will contain a different set of transactions. Only the miner that solves the puzzle first will have the opportunity to append its block and hence earn the reward, but what if more than one miner solved the puzzle at the same time?
?In that case, there will be two branches or chains of the blockchain, but that’s not desired. There should only be one branch. As more blocks are added to the chain, only the longest branch shall prevail and others will purge. Transactions from the purged branches shall be mined again and added to a future block.?
After successful mining, the miner broadcasts the proposed block to the blockchain network for other nodes to validate. The step of validating the block should not be confused with the step of validating a transaction that the miner performed before starting the mining process. After successful validation, the new winning block is appended to the blockchain. The winning miner received its award.
It is how blockchain works and what happens every time a transaction is performed. It was my pleasure to share that with you. We offer reliable blockchain and dApp development services at BlockchainFar . Please feel free to contact me if you have any questions about this field or how we work. Let's build together.
Java Developer for FNB
2 年#helpful #content #awesome