Raj All Practical FBC Final PDF
Raj All Practical FBC Final PDF
:202202100710071
Practical : 5
Case study on a Merkle tree to understand the Blockchain with its example.
Introduction
A Merkle Tree (or hash tree) is a cryptographic structure used in blockchain technology to ensure
data integrity and efficient verification. It enables quick and secure validation of large datasets,
making it a fundamental component of blockchain implementations like Bitcoin and Ethereum.
Code:
import hashlib
transactions): self.transactions =
transactions self.tree = []
self.root = self.build_merkle_tree()
return hashlib.sha256(data.encode()).hexdigest()
def build_merkle_tree(self):
1 < len(leaves):
else:
new_level.append(self.hash_function(combined) leaves =
def get_merkle_root(self):
get_merkle_tree(self):
return self.tree
# Example usage if
__name__ == "__main__":
Tree:", merkle_tree.get_merkle_tree())
OUTPUT:
MerkleRoot:
5b260dbcbff182d10cdbd21d8cb9e4446fe71820bb91c8dced8dcfd0e8a9c8ac
Enrollment no.:202202100710071
MerkleTree:
[['55f743d0d1b9bd86bbd96a46ba4272ddde19f09e3f6e47832e34bb2779a120b5',
'80ed43f7a11b3295850dd90cc0cfc9a80334f433af8d3d88a1c5e78aff14988f',
'13288c2ba4bbc9af05aa9ccd39b0cc603dc9e30471d97565c9ef3c3604b7ca23',
'75af2038a4bcf0230372d08b917047bdcbad80e5f130061bd5b31596df174b67'],
['0971909734e9c49e0f45caeb15a450d717de387a0a27df245e7e924bb7e62b0e',
'2b4b1ceff3308595e26df24646583f4e3b38f4448c692ab80558f69fea74a3d7'],
['5b260dbcbff182d10cdbd21d8cb9e4446fe71820bb91c8dced8dcfd0e8a9c8ac']]
Introduction
A block in a blockchain is a fundamental data structure that stores transactional information
securely and immutably. Blocks are linked using cryptographic hashes, forming a chain of blocks—
hence the term blockchain.
• Block Header: Metadata such as timestamp, previous block hash, and Merkle root.
• Transactions: A list of verified transactions.
• Nonce: A unique number used in the mining process.
• Hash: A unique identifier generated using the block's data.
Code:
import hashlib
import time
class Block:
timestamp=None):
self.index = index
self.previous_hash = previous_hash
self.transactions = transactions
self.timestamp = timestamp or
time.time()
Enrollment no.:202202100710071
self.nonce = 0
self.hash = self.compute_hash()
def compute_hash(self):
block_string=f"{self.index}{self.previous_ hash}
{self.transactions}{self.timestamp}{ self.nonce}"
return
hashlib.sha256(block_string.encode()).he
xdigest()
self.nonce += 1
self.hash = self.compute_hash()
if __name__ == "__main__":
.hash)
new_block=Block(1,genesis_block.hash, ["Charlie
new_block.mine_block(difficulty=4)
new_block.hash)
OUTPUT:
GenesisBlockHash:
773e98aaa966aaad5f8ae7bceec093dad4
f71856352bed4ee4e1ffe482948e0b
Blockmined:
0000d9d181e49cc8b7c04ca26f8e645ce8
d4f66f289dceba2616fdddf987b3fe
Enrollment no.:202202100710071
NewBlockHash:
0000d9d181e49cc8b7c04ca26f8e645ce8
d4f66f289dceba2616fdddf987b3fe
1. Creating a Block: A block stores its index, previous block hash, transactions, timestamp, and
a nonce.
2. Computing Hash: The block’s hash is computed using SHA-256.
3. Mining a Block: A simple proof-of-work mechanism is implemented where the hash must
start with a certain number of leading zeros.
Introduction
An ERC-20 token is a standard for fungible tokens on the Ethereum blockchain. It ensures that all
tokens follow a common interface, making them compatible with wallets, exchanges, and smart
contracts.
Function Description
totalSupply() Returns the total supply of tokens balanceOf(address) Returns the
balance of a given address transfer(address, uint256) Transfers tokens from sender to
another address approve(address, uint256) Approves another address to spend tokens
transferFrom(address,address,
1. Introduction
Decentralization is a key principle of blockchain technology, removing reliance on central
authorities and enabling peer-to-peer (P2P) transactions. By distributing control and decisionmaking
across a network, decentralization enhances security, transparency, and trust.
• Distributed Ledger Technology (DLT): Every participant (node) in the network has a copy of
the ledger.
• Consensus Mechanisms: Transactions are validated through consensus (e.g., Proof-ofWork,
Proof-of-Stake).
• Cryptographic Security: Data integrity is maintained using encryption and hashing.
• Decentralized Lending & Borrowing: Platforms like Aave and Compound allow users to
lend/borrow crypto assets.
• Automated Market Makers (AMMs): Uniswap enables direct trading without
intermediaries.
• Yield Farming: Users earn rewards by providing liquidity to decentralized exchanges.
6. Challenges of Decentralization
Challenge Explanation
Scalability Processing transactions across a decentralized network can be slow.
Regulatory
Governments struggle to regulate decentralized systems. Uncertainty
Proof-of-Work networks (e.g., Bitcoin) require significant computational
Energy Consumption power.
User Responsibility No centralized authority means lost private keys = lost funds.
Practical : 9
Prepare a detailed case study on any two known implementations of
Blockchain.
1. Introduction
Blockchain technology has revolutionized industries by introducing decentralization,
transparency, and security. This case study explores two well-known blockchain implementations:
Both blockchains have unique use cases but share common principles of distributed ledger
technology (DLT).
Challenges of Bitcoin
Impact of Bitcoin
Bitcoin has influenced global finance, inspiring the development of thousands of cryptocurrencies
and blockchain projects. Institutional investors and governments are now exploring Bitcoin
adoption.
✅ Decentralized Finance (DeFi) – Platforms like Aave, Uniswap, and Compound provide financial
services without banks.
✅ NFTs (Non-Fungible Tokens) – Ethereum powers digital ownership through ERC-721 tokens.
✅ Decentralized Autonomous Organizations (DAOs) – Community-led governance models
without central leadership.
Challenges of Ethereum
❌ High Gas Fees – Transaction fees can become expensive during network congestion.
❌ Scalability Issues – Ethereum can process ~30 TPS, leading to delays.
❌ Smart Contract Vulnerabilities – Poorly coded contracts can be exploited (e.g., DAO hack).
Impact of Ethereum
Ethereum has transformed the blockchain ecosystem, enabling innovation in DeFi, NFTs, and the
Web3 movement. The transition to PoS significantly reduced energy consumption, making
Ethereum more sustainable.