What Is Blockchain
What Is Blockchain
Example :
Think about a shop at your area. Suppose you want to buy a cold drinks which price is 20 tk. but you
don’t have any money at that time. You will pay that later. So you went to the shop buy the cold drinks and
told the shop kepper that you will pay it later and requested him to write it on ladger book. What if the
shop keeper will cheat you and write the price 30 tk!
Yes! This times comes blockchain and online transaction. Here all the datas will be saved on ladger or blocks
and this blocks are totally immutable. No one can change this. Once a data has been saved here, no one can
change this. This is also distributed
blockchain
Suppose you have updated something on this block. Then this will also update simultaneously on the whole
system which are affiliated on this blockchain system. Thats why it’s called distributed and transparent
system.
After all the notifications should be updated on the whole system simultaneously and shuold be visible to
all. Publics can’t see that transaction directly. Because that transaction is visible to the system using a secret
code.
Applications of Blockchain:
• Product Tracking
• Health Cares
Hashing Algorithm
In blockchain, each block attached with each other. For this reason, it is very much important to identify
each blocks. Thats why hashing algorithm comes. Hashing algorithm generates unique hash codes for each
blocks.
hashing algo
hashing algo
1. One way
2. Deterministic
3. Fast computation
4. Withstand collition
5. Avalanche effect
Block architecture
There are main 3 parts of a block in blockchain.
1. Data
2. Hash
block
data of a block
hash of a block
hash of previous block
Each block has an unique hash and its immutable. So, if any hacker tries to change the hash, then the whole
system should be notified.
unique hash
Immutable ladgers:
If hackers tries to hack a blockchain server, then he will not be able to hack because of previous hash. Look
at the image:
If hacker tries to hack any of the block then he will generate a new hash on that block because he will make
change. For that reason from the affected block to rest of the blocks… all the blocks should be disabled
because of missing the actual previous hash. This is why it is called immutable ladger. All the blocks or
ladgers are immutable because of hashing algorithm.
P2P network:
Blockchain Mining
Blockchain mining is a peer-to-peer computer process that involves adding transaction data to Bitcoin’s
public ledger of past transactions. It’s a metaphor for the computational work that network nodes
undertake to validate the information contained in blocks.
Suppose you want to do a transaction. You have send a data to your friend. While you will do this, first the
data should be saved on mempool. What is mempool? An area where a group of miners pick the
transaction then they tries to save the transaction into the block. Every miner wants transactions to happen
on his block. When they will add the transaction to their block, a mathematical problem have to solve them
as the prove of work. The miner who will solve the problem at first will create a block. The miner who have
the block will communicate that they have created the block. Now the distributed p2p network will revise
the task and will determine that whether the block is valid or not.
Byzantine fault tolerance (BFT) is a consensus approach that allows a distributed system to continue
operating even if some nodes are faulty or malicious. BFT is named after the Byzantine Generals’ problem, a
hypothetical logical dilemma about a group of Byzantine generals.
Consensus Protocol
A consensus mechanism is a protocol that brings all nodes of a distributed blockchain network into
agreement on a single data set.
2. Proof of Shake
This is a consensus mechanism in blockchain that verifies the accuracy of new transactions. It’s the earliest
consensus model for blockchains and is used in about 60% of the total crypto market capitalization.
Blockchain wallets
Blockchain wallets are digital wallets that allow users to store, manage, and trade cryptocurrencies, such as
Bitcoin and Ether. They also allow users to transfer cryptocurrencies and convert them back into their local
currency. Blockchain wallets are secure because they use cryptography to sign transactions, and there are
no intermediaries in transactions carried out using blockchain wallets.
Public Blockchain
A public blockchain, also called a permissionless blockchain, is a decentralized network that anyone can join,
read, write, and audit.
Private Blockchain
A private blockchain, also known as a permissioned blockchain, is a decentralized ledger that is only
accessible to a specific group of people or organizations. A single entity or group of participants controls
who can access the network, create data, and view information. Private blockchains are different from
public blockchains, like Bitcoin or Ethereum, because they don’t use anonymous miners, but instead use a
controlled network of validators. Need permission.
Consortium blockchain
A consortium blockchain is a hybrid model that combines the access of public blockchains with the
restrictive nature of private blockchains. It is also known as a Federated Blockchain. Need permission.
Hybrid blockchain
All the benefits of Public, Private and Consortium blockchain should be merged here. This is called future of
Blockchain.
An unspent transaction output (UTXO) is the amount of cryptocurrency that remains after a cryptocurrency
transaction. UTXOs are recorded in a database and can be used in new transactions.
• When a transaction is completed, any unspent outputs are recorded into a database as inputs that
can be used later for a new transaction.
• The owner signs a message (transaction) transferring ownership of their UTXO to the receiver’s
Public Key.
• The condition that only unspent outputs may be used in further transactions is necessary to prevent
double-spending and fraud.
• The Bitcoin protocol uses the UTXO model to track balances as they move between crypto wallets.
What is Bitcoin?
Bitcoin is a digital currency that uses blockchain technology to support transactions between users on a
decentralized network.
What is Nonce?
A nonce is a random number that is assigned to a block in a blockchain during the mining process. The term
is short for “number used once”. This used to solve complex mathematical problems during blockchain
mining. Different nonce generate different hashes.
What is Ethereum?
Vitalik Buterin, a Canadian computer programmer have created this technology! When he was only and
only 19!!!
Actually ethereum is a ecosystem. We can develop any kind of DAPPS or Decentralozed Applications. We
can do decentralized gaming or financing anything in this ethereum network. Ethereum provides a network
named Ether! In the network named Ethereum, mineres accept fees here using ether. The programming
language is used here named Solidity.
Ethereum 2.0
Ethereum 1.0, the transaction capability was 25–30 per second! This was really littly while the transaction
was increasing very fast also transaction fee was increasing which was expensive for Ethereum! Thats why
Vitalik Buterin have decided to launch ethereum 2.0. Here the transaction capability shouldbe one hundred
thousand (100 000) per second.
In ethereum 1.0, they have used Proof of work (PoW) to verify the transaction but now in ethereum 2.0,
they will use Proof of Stake to verify the transaction. Here node will verify transaction instead of miners.
Ethereum Nodes
Ethereum nodes are like individual computers in a network that store and maintain a copy of the Ethereum
blockchain. They help to validate and relay transactions, execute smart contracts, and ensure the network
remains decentralized and secure. Essentially, they’re the backbone of the Ethereum network, working
together to keep everything run
There are 3 types of nodes. They are:
1. Full node: Full nodes store all the blockchain’s data and participate in block validation. Verify and
validate all blocks of a blockchain.
3. Archive node: It stores everything kept in the full node and build an archive of historical data. This is
also a full node. The difference is it has all the history that full node doesn’t have! It requires
terebyte of diskspace.
[ OBS: This is a public blockchain. This means what ever transaction you do is visible to the public
network!]
Ethereum account
1. Externally owned account: When we will create a wallet, the it generated. To open the wallet, we
will be needed a private key!
2. Contract account: A contract account refers to a type of account on the Ethereum blockchain that is
associated with a smart contract. In simple terms, it’s like a digital wallet that holds funds and
executes code according to predefined rules set within the smart contract. These smart contracts
enable automated and trustless transactions, allowing for various functionalities such as token
transfers, decentralized applications (dApps), and more, all without the need for intermediaries.
Smart Contract
It is a program which runs on etereum blockchain. You can say this… Smart contract is an if…else statement.
Cause if…else is often used here. In a smart contract, a condition will arise and it should be fullfilled must
and then the expected output should be generated.
Smart contract can’t be used in blockchain. Cause turing can’t be performed here. The reason is in bitcoin
script, there isn’t any concept of loop. Thats why you can’t do turing! In soldity, you can easily do this.
Ethereum is Turing complete, which means it can execute any smart contract or program, no matter how
intricate. This is possible because Ethereum has two Turing complete elements:
It means decentralized application. It will run all the nodes which will be a part of etereum.
Think about youtube. There is a central server, from where the whole youtube systems are being controlled.
If we need something, we search on the search bar and it try to finds the data from the main server as it is
called central server!
In dapp, there isn’t any central cerver. Instead of central server, the program will run on all the nodes which
is affiliated to the blockchain.
EVM
Ethereum Virtual Machine! If you have used any virtual machine, then this concept will be clear to you. For
example, lets imagine virtual box. What you will do there? You will install system software or application
software. Like that, you will do the same thing in the EVM. Here you will also install the softawares
regarding ethereum to keep safe your actual system. This the actual concept of evm.
Ethereum Gas
Imagine a car. To travel from one place to another, the car will need patrol or gas. That means, to run a car,
we need gas! Same here, to run a program in ethereum blockchain, we will be needed a gas value.
Suppose, we have a smart contact that have to perform a mathematical operation. As you know smart
contract is a program. The mathematical operation should be this: 10 * 3 — 6 = ?
So, how much amount of gas will be needed for this particular operation?
You know that octane and digale has different prices! Same here in etereum gas each operation has their
own gas value. That means in the equation, *, — , = … each operations have their own gas value!
So, here…
“ * ” gas value is = 5
2. The user that generated the transaction pays for the Gas.
Gas Price
It is an amount the sender wants to pay per unit of gas to get the transaction mined. Gas price is set by the
sender.
Imagine, to travel from one district to another, you car will be needed Octane per km 20 tk. This rate is fixed
by your government. But in ethereum blockchain, you will fix the gas rate.
To perform that mathematical operation from the image, we will be needed 11 gas! And previously I have
said that you will set the gas price.
Here 11 gas will be needed. You have set the price for 100 tk accourding to your currency. You can set any
number! No problem. If you want to set 10 tk, then its ok.
The main problem of setting lowest cost is the performace. The higher the gas price the faster the
transaction will be mined.
In ethereum, Gwei is used to denote the network’s gas fees. This is a unit of measurement.
Maximum amount of Gas a transaction can consume. You have to set the limit of using gas in the ethereum
blockchain for the transaction starting.
Normally ethereum gas limit is: 21000. This is actual limit for a parfect transaction.
What if any sender will set the limit 20,000 after the payment? The transaction will be failed. Because he
have already paid the amout 0.0021 ETH by calculating the actual limit that is 21,000 and the price that is
100.
This will be nonsence to set the limit lower then actual limit that the sender paid for the transaction. There
are two loss, 1st one is transaction failure and the 2nd one is the mone will not be refunded.
What if sender will set the limit higher then the actual one? Suppose a sender have set the limit 22,000 and
the actual one is 21,000. This time the rest of the gas should be returned.
Suppose, you have set the limit to 22,000 and the actual limit is 21,000! Then there were 21,000 were used.
Then the rest 1000 should be returned.
Why gas limit needed?
If a hacker or an inexperienced person have created a program that has infinite loop. For that program,
unlimited ether will be generated from that code that is terrible loss for the network and the another
another problem is the Ethereum network should be down.
Ethereum Block
DAO
What happens here? There are several tasks assigned here. Each members do perform their own task. For
example manager have to plan, organize, direct, and control resources to achieve specific goals. Employee
have to do different task, that may be coding or other. The key power have to the MD or Director.
In DAO, the organization will work with blockchain. There will not be any central app. The members will take
decision according to the operation. Fully democratized. To take decision, voting happens here. Majority
gets the priority.
In simple words….
Decentralized autonomous organization (DAO) is an entity in which all members participate in decision-
making, because there is no central authority.
DAO Attack
Because of the bug of the code in smart contract, this attack happended and 6.5 million us doller was
hacked. Imagine total 6.5 million us doller has been looted by the hacker!
The software on which The DAO was created contained a bug introduced by a programming error, making
the project vulnerable to exploit. DAOs to syphon over one third of the invested Ether into a child DAO
under control of the attacker.
Hard Fork
A hard fork is a radical change to a blockchain’s protocols that splits the blockchain into two separate
versions, each operating independently. The new version is created when network participants, including
users, upgrade to the new rule set and reject the old rules. The new version is not backward compatible
with the old version, causing a permanent split.
Soft Fork
In blockchain technology, a soft fork is a change to the software protocol that makes previously valid
transaction blocks invalid, but not vice versa. This means that old nodes will recognize the new blocks as
valid, making the fork backwards-compatible. Here end product remains unchangable.
IPO and ICO are same. In IPO, when a private company sells shares of its stock to the public for the first
time, making it a public company.
In ICO, companies and individuals to raise capital or participate in investment opportunities by selling new
cryptocurrencies to investors in exchange for their financial contributions.
Serenity/Ethereum 2.0
Proof Of Stake
There aren’t any miners rather instead of miners, there will be validators. In PoW, miners have to solve
some mathematical peroblems to create block, here in PoS, the validators will provide some ETH to the
system to become a validator.
When a person becomes a validator, the system will let him create block. If a validator will create a block in
a parfect way, the ether which he provided will be refunded and also the transaction fee will be provided.
If a hacker wants to do malicious activity, the ether will not be refunded and the transaction fee will not be
given.
The more you give them ether, the more of getting randomly selected you here.
Sharding
Sharding is a database partitioning technique that splits a blockchain network into smaller partitions, called
shards. Each shard contains its own data, making it distinct from other shards. Sharding improves
blockchain scalability and allows them to process more transactions per second. It can also help reduce
network latency. Sharding comes from traditional databases, where it involves splitting up a large database
into more manageable units for easier access to information.
Altcoins
Altcoins are cryptocurrencies that are not Bitcoin (BTC). The term is a combination of the words
“alternative” and “coin”. Altcoins are designed for the blockchains they belong to, and some have unique
uses and services. Altcoins often share code and functionality, and include coins such as Ether, Litecoin, and
Dogecoin.
Hyperledger
Distributed ledger technology is a platform that uses ledgers stored on separate, connected devices in a
network to ensure data accuracy and security. Blockchains evolved from distributed ledgers to address
growing concerns that too many third parties are involved in too many transactions. Distributed ledgers
(DLT) can be categorized as either public or private, depending on who can access the ledgers. DLTs can also
be permissioned or permissionless
Hyperledger is a global, open-source project that provides tools and standards for building blockchains and
related applications. This is private blockchain.
This is a voting based distributed consensus algorithm. Works for asynchronous system that enables it to
function correctly and reach consensus even when some of its nodes (computers) fail or behave maliciously.
In this system, there are order nodes. There one is primary nodes and other are secondary nodes.
1. Replication: In a Byzantine fault-tolerant system, the data and processes are replicated across
multiple nodes. This redundancy ensures that even if some nodes fail or act maliciously, there are
still enough honest nodes to reach a consensus.
2. Voting or Consensus Mechanism: To reach agreement on a particular value or decision, the nodes
engage in a voting or consensus mechanism. Each node shares its proposed value or decision with
the other nodes.
3. Communication and Verification: Nodes communicate their proposed values to each other. They
then verify the received values to ensure they are consistent with the majority of other nodes.
Nodes may also need to validate the authenticity of messages to prevent tampering by malicious
nodes.
4. Consensus Decision: Once a node receives responses from a certain threshold of other nodes
(often a two-thirds majority), it decides on the final value based on these responses. This decision-
making process ensures that the network reaches a consensus even if some nodes are faulty.
5. Redundancy and Fault Detection: Byzantine fault-tolerant systems often incorporate redundancy
and fault detection mechanisms to identify and isolate faulty nodes. This helps prevent the spread
of misinformation and ensures the integrity of the system.
Byzantine fault tolerance allows distributed systems to continue operating reliably and reaching consensus
despite the presence of faulty or malicious nodes, making them more resilient to attacks and failures.
Q) Then a question arises that how pbft deal when a malicious node comes in?!
Well, the answer is… In the Practical Byzantine Fault Tolerance (PBFT) algorithm, the system is designed to
tolerate up to one-third of the total number of nodes being malicious or faulty. When a malicious node
enters the network, PBFT employs several mechanisms to detect and mitigate its impact:
1. Replication: PBFT replicates the execution of transactions across multiple nodes. Each replica
processes the same set of requests and the system reaches a consensus on the order of
transactions. This redundancy helps in mitigating the impact of a malicious node as long as the
majority of nodes are honest.
2. Quorum: PBFT requires a two-thirds majority (or more) of honest nodes to reach a consensus on
the order of transactions. Malicious nodes can deviate from the protocol, but they cannot subvert
the system as long as the honest nodes constitute a quorum.
4. View Changes: PBFT employs a view change protocol to handle situations where the primary node
is faulty or becomes unresponsive. If a node detects that the primary is faulty, it initiates a view
change to select a new primary node. This mechanism helps in ensuring that the system can
continue to make progress even in the presence of faulty nodes.
5. Byzantine Agreement: PBFT requires nodes to exchange messages and reach agreement on the
order of transactions through a multi-phase process involving pre-prepare, prepare, and commit
messages. Malicious nodes can try to disrupt this process, but they cannot succeed unless they
control a significant portion of the network.
PBFT is designed to provide resilience against Byzantine faults, including the presence of malicious nodes.
By employing replication, quorum-based decision making, message authentication, view changes, and
Byzantine agreement protocols, PBFT ensures that the system can continue to operate correctly and reach
consensus even in the presence of malicious actors.
Hyperledger Frameworks
As you know hyperledger is a tool which contains a lot of frameworks reagarding blockchains. I am writing a
short description about all of the frameworks.
Hyperledger Fabric
Hyperledger Fabric is a permissioned blockchain platform developed under the Linux Foundation’s
Hyperledger umbrella. It is designed for enterprise use cases, offering flexibility, scalability, and privacy
features
This is the main functionality of hyperledure which makes it more efficient for the companies.
Chain code: The programming language required for this network is chain code. That maybe Solidity,
Python, JS, Kotlin, Java which runs a prescribe.
MSP: Member Service Provider is used to manage the identities of the blocks in a blockchain.
Channel: This is a path way by which companies communicate with each other. This means this is a private
communication highway.
ACL: This is a list of rules that specifies which users or systems are granted or denied access to a particular
object or system resource.
Committing nodes:
Endorsing nodes:
Ordering nodes:
Nodes that maintain the sequence of transactios. This means which node will perform the operation is
being controlled by this node.
1. Here client will initiate a transaction at first then this will be verified by the MSP or ACL.
2. Then the transaction will goto the endorsing nodes for validation.
3. Then the output of the validation should be sent to the clients and…
4. Then if tolal 51% endorsing nodes are positive then that should be accepted. After all at least 51%
nodes output should be same. This means varifying by the clients.
5. Then the orederer will make a particular sequence according to the transaction and will make a
block.
7. At the ending if every thing is correct from the beginning to the 6th step… the block should be
updated to the ledger.
Hyperledger Test Network is an environment provided by the Hyperledger project for developers to
experiment with Hyperledger Fabric, one of the prominent blockchain frameworks for building enterprise-
grade blockchain solutions. The test network is designed to simplify the process of setting up a local
blockchain network for development and testing purposes.
Purpose: The primary purpose of the test network is to allow developers to quickly set up a local blockchain
network for experimenting, developing, and testing Hyperledger Fabric-based applications.
• Peer Nodes: Nodes that maintain the ledger and execute chaincode transactions.
Setup: Setting up the test network involves configuring the various components mentioned above, such as
defining the network topology, configuring cryptographic materials, and creating channels.
Features:
• Easy Deployment: Hyperledger Test Network offers scripts and tools to simplify the deployment
process, allowing developers to quickly spin up a local network.
• Chaincode Development: Developers can deploy and test their chaincode (smart contracts) on the
test network before deploying them to a production environment.
• Experimentation: Test networks provide a sandbox environment where developers can experiment
with different configurations, policies, and consensus mechanisms.
Use Cases: Developers often use the test network for various purposes, including:
• Prototyping: Quickly prototype blockchain applications without the need for a full-scale network.
• Learning: Learn about Hyperledger Fabric’s features and capabilities in a controlled environment.
Limitations: While the test network is useful for development and testing, it may not accurately reflect the
performance or behavior of a production environment. It typically runs on a single machine or a small set of
machines, which may not scale to the same extent as a real-world deployment.
Activity:
• Hyperledger Fabric enables organizations to build private, permissioned blockchain networks where
participants have control over access and visibility of data.
• Participants on a Fabric network can transact with each other while maintaining privacy,
confidentiality, and integrity of their data.
• Activities on a Fabric network include creating and endorsing transactions, ordering and validating
transactions, and committing transactions to the ledger.
Here ledger has been divided into two part. First one is World state and the second one is Transaction log!
World state means current data.
This system generally needs linux based setup also we can setup this into windows but this time you will be
needed windows 10/11 professional. Without that you can’t setup that.
1. Curl
2. NodeJs
3. Git
4. Python
5. Libtool
6. Docker CE
7. Docker Compose
Implementation
• Hyperledger Fabric is implemented in GoLang, with support for smart contracts written in various
programming languages such as Go, JavaScript, and Java.
• Key components of a Fabric network include peers, orderers, and membership services (Certificate
Authorities) for identity management.
• Participants on a Fabric network interact with each other through channels, which are private
communication pathways. Each channel has its own ledger and smart contract instances.
• Transactions are initiated by clients and then proposed to endorsing peers. Endorsing peers execute
the smart contract logic and return a proposal response.
• The proposal responses are collected by the client and sent to the ordering service, which orders
them into blocks and delivers them to committing peers.
• Committing peers validate the transactions, update their ledgers, and send an acknowledgment
back to the client.
Fault Tolerance
• Hyperledger Fabric employs several fault tolerance mechanisms to ensure the resilience of the
network.
• It uses a consensus mechanism called Practical Byzantine Fault Tolerance (PBFT) for ordering
transactions, which ensures that the majority of orderers are honest and can tolerate up to one-
third of malicious nodes.
• Fabric also supports fault tolerance through its modular architecture. For example, if a peer fails,
other peers can continue to operate, and the network remains functional.
• Additionally, Fabric provides features such as identity management, access control, and data
encryption to enhance security and fault tolerance.
Hyperledger Fabric is a robust blockchain platform designed for enterprises, offering privacy, scalability, and
fault tolerance features necessary for building permissioned blockchain networks. Its modular architecture
and PBFT-based consensus mechanism make it suitable for a wide range of use cases across industries.
CORDA (basic)
Corda is a blockchain platform specifically designed for businesses. It enables enterprises to transact directly
and privately with each other, without requiring a central authority. Here’s a brief overview of Corda’s use,
activity, and implementation, focusing on Python:
Use:
• Corda is primarily used for building decentralized applications (CorDapps) that facilitate secure and
private transactions between parties.
• It is commonly used in industries such as finance, supply chain, healthcare, and more, where there
is a need for secure and auditable transactions.
Activity:
• Corda operates as a distributed ledger platform where multiple parties can transact securely and
directly.
• Nodes on the Corda network communicate and share data using secure channels, enabling trustless
transactions.
• Activities on the Corda network include creating transactions, validating transactions using smart
contracts, and reaching consensus among network participants.
Implementation:
• Corda supports building CorDapps using Kotlin and Java. However… Python can be used for building
clients and interacting with the Corda network through the RPC interface.
• Python developers can use Corda’s RPC client library to connect to and interact with a Corda node.
This allows them to query node data, initiate transactions, and retrieve transaction history.
• The Corda RPC client library provides Python developers with a convenient way to integrate Corda
functionality into their applications, enabling them to leverage the power of Corda’s distributed
ledger technology.
Corda is a powerful platform for building decentralized applications in industries that require secure and
private transactions..