0% found this document useful (0 votes)
28 views4 pages

Detailed Lecture Notes For Unit 3 and Unit 4

The document covers Units 3 and 4, focusing on smart contracts, decentralized applications, and advanced blockchain concepts. It details the functionality of smart contracts using Solidity on Ethereum, the deployment process, gas fees, and Hyperledger Fabric's permissioned model. Additionally, it explores decentralized identity management and blockchain interoperability, highlighting the importance of DIDs and cross-chain communication solutions like Polkadot and Cosmos.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Detailed Lecture Notes For Unit 3 and Unit 4

The document covers Units 3 and 4, focusing on smart contracts, decentralized applications, and advanced blockchain concepts. It details the functionality of smart contracts using Solidity on Ethereum, the deployment process, gas fees, and Hyperledger Fabric's permissioned model. Additionally, it explores decentralized identity management and blockchain interoperability, highlighting the importance of DIDs and cross-chain communication solutions like Polkadot and Cosmos.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DETAILED LECTURE NOTES FOR UNIT 3 AND UNIT 4

UNIT 3: Smart Contracts and Decentralized Applications


(DApps)
No. of Hours: 9

Section 1: Introduction to Smart Contracts and Solidity Programming

Smart contracts are self-executing digital agreements where the terms are directly written in
code. These contracts run on blockchain networks and automatically execute when the
predefined conditions are met. Since smart contracts are stored on a blockchain, they are
immutable (cannot be altered) and transparent (publicly viewable), making them highly
secure and trustworthy. They eliminate the need for intermediaries, reducing costs and
increasing transaction efficiency.

Solidity is the primary programming language used to create Ethereum smart contracts. It is
statically typed and has syntax inspired by JavaScript, Python, and C++. Solidity allows
developers to define state variables, functions, and events that interact with the Ethereum
Virtual Machine (EVM). For example, a basic contract may include a constructor to initialize
the state and public functions to modify or retrieve data. Here’s a simple Solidity contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
string public message;

constructor() {
message = "Hello, Blockchain!";
}

function setMessage(string memory newMessage) public {


message = newMessage;
}
}

In this contract, the setMessage() function allows users to update the stored message. When
deployed, the contract runs on the blockchain, and its state is publicly visible.

Section 2: Deploying Smart Contracts on Ethereum

To deploy a smart contract on Ethereum, developers use platforms like Remix IDE, Truffle,
or Hardhat. Remix IDE is a web-based tool that offers an integrated environment for
writing, compiling, and deploying Solidity contracts.

The deployment process involves:

1. Writing the Contract: The smart contract is written in Solidity.


2. Compilation: The contract is compiled into bytecode that the Ethereum Virtual
Machine (EVM) can interpret.
3. Connecting to MetaMask: MetaMask is used as a wallet to interact with the
Ethereum network. It allows you to pay for gas fees (the cost of executing a contract).
4. Deploying to a Testnet: The contract is deployed on a test network like Rinkeby or
Goerli for testing purposes before being launched on the mainnet.

Once deployed, the smart contract address becomes permanent on the blockchain. Users can
interact with it by sending transactions, triggering its functions.

Section 3: Gas Fees and Execution Costs

On Ethereum, every transaction, including the execution of smart contract functions, requires
a gas fee. Gas is a measure of the computational effort required to process a transaction. The
gas price is measured in Gwei (1 Gwei = 10^-9 ETH). The total cost of a transaction is
calculated using the formula:

Gas Fee=Gas Used×Gas Price\text{Gas Fee} = \text{Gas Used} \times \text{Gas Price}

For instance, a contract function that requires 100,000 gas at a gas price of 50 Gwei would
cost:

100,000×50=5,000,000 Gwei=0.005ETH100,000 \times 50 = 5,000,000 \text{ Gwei} = 0.005


ETH

Gas optimization is essential in Solidity programming to minimize costs. Techniques include


using fixed-size arrays, reducing storage operations, and using external instead of public
functions where appropriate.

Section 4: Hyperledger Fabric Smart Contracts (Permissioned Model)

Hyperledger Fabric is a permissioned blockchain framework designed for enterprise


applications. Unlike Ethereum, which is a public blockchain, Hyperledger Fabric restricts
access to authorized participants. It uses Chaincode as its smart contract programming
model. Chaincode is typically written in Go, Node.js, or Java.

The lifecycle of chaincode includes four main stages:

1. Packaging: The chaincode is packaged into a deployable format.


2. Installation: It is installed on the peers participating in the network.
3. Approval: Peers approve the chaincode definition.
4. Commitment: The chaincode is committed to the channel, making it available for
execution.

A simple chaincode in Go might look like this:

package main

import (
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)

type SmartContract struct {


contractapi.Contract
}

func (s *SmartContract) InitLedger(ctx


contractapi.TransactionContextInterface) error {
return ctx.GetStub().PutState("Asset1", []byte("Hyperledger
Asset"))
}

This chaincode stores an asset on the blockchain, allowing participants to interact with it
securely. Hyperledger Fabric is widely used in industries such as finance, healthcare, and
supply chain management.

UNIT 4: Advanced Blockchain Concepts


No. of Hours: 9

Section 1: Decentralized Identity Management

Decentralized Identity (DID) is an innovative concept where individuals control their


digital identity without relying on centralized authorities. Traditional identity systems store
personal information in centralized databases, making them vulnerable to data breaches. In
contrast, DID uses blockchain technology to create verifiable, tamper-proof identities.

A DID system consists of three components:

1. Decentralized Identifiers (DIDs): Unique, verifiable identifiers created and


controlled by users.
2. Verifiable Credentials (VCs): Digital certificates that verify identity-related claims.
3. Decentralized Identifiers Registry: Blockchain records that link DIDs to public
keys.

In practice, DID works by allowing users to create a self-sovereign identity (SSI), which
they control independently. When a service provider requests identity verification, the user
can present their VC without revealing unnecessary personal data.

SSI is increasingly being used for:

 KYC (Know Your Customer) processes.


 Healthcare identity management.
 Digital wallets for verified credentials.

Section 2: Blockchain Interoperability


Blockchain interoperability is the ability of different blockchain networks to communicate
and share data. Since most blockchains operate in silos, interoperability enables cross-chain
functionality, enhancing liquidity and scalability.

Cross-chain communication protocols allow seamless asset and data transfers between
blockchains. Two common techniques are:

1. Atomic Swaps:
o A peer-to-peer exchange mechanism allowing two parties to swap different
cryptocurrencies without a third party.
o It uses Hash Time-Locked Contracts (HTLC) to ensure that the swap either
occurs completely or not at all.
2. Sidechains:
o Independent blockchains that run parallel to the main chain, enabling faster
and lower-cost transactions.
o Assets can move between the main chain and the sidechain.

Interoperability solutions like Polkadot and Cosmos have emerged to connect multiple
blockchains:

 Polkadot:
o Uses parachains (parallel blockchains) that communicate with the main relay
chain.
o Enables cross-chain messaging and data exchange.
 Cosmos:
o Employs the Inter-Blockchain Communication (IBC) protocol.
o Allows seamless token transfers across different blockchains.

These solutions are revolutionizing the blockchain landscape by breaking down silos and
enabling seamless interaction between multiple networks.

Key Takeaways

 Unit 3:
o Smart contracts automate trustless execution on the Ethereum blockchain
using Solidity.
o Gas fees are essential for executing contracts.
o Hyperledger Fabric offers a permissioned model for enterprise applications
with Chaincode as its contract language.
 Unit 4:
o Decentralized identity empowers individuals to control their personal data
using DIDs and verifiable credentials.
o Blockchain interoperability connects different networks, enhancing
scalability and efficiency through solutions like Polkadot and Cosmos.

You might also like