0% found this document useful (0 votes)
2 views

Assignment 03

Uploaded by

Abdul Wase Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 03

Uploaded by

Abdul Wase Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ZIAUDDIN UNIVERSITY

Faculty Of Engineering Science Technology &


Management
(ZUFESTM)
Department of Computer Science and Software Engineering

Course Code/ Title: Block Chain Technology & ASSESSMENT ACTIVITY: Semester:
Application Lab 1&2 CS 2023 (Semester- III)

Dated: 17/01/2024 OBE Target: Weight of Marks:


CLO- 2, PLO- 2, P- 3 02
Student Name: MUHAMMAD HASSAN Score:
Teacher:
ASIM
Sir Wajeeh Abbas
Student ID: 4-38/2023/013
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science Technology &
Management
(ZUFESTM)
Department of Computer Science and Software Engineering

Examiner Signature: Student Score:

Question # 01: Explain in detail about visibility specifiers in solidity along with their examples? (1-mark)
Answer:
There are four main visibility specifiers: public, private, internal, and external.

Public: They are accessible by any contract on the blockchain. They can be called internally within the contract or
externally by other contracts. Public functions automatically create getter functions, enabling external access to the
data without direct modification.
Example:
Imagine a smart contract for an online marketplace where the getProductPrice function is marked as public. This
function allows anyone, both within and outside the contract, to view the price of a product listed on the platform.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science Technology &
Management
(ZUFESTM)
Department of Computer Science and Software Engineering

Private: They can only be accessed within the contract where they are defined.
Example:
Consider a voting smart contract where the voteCount variable is marked as private. This variable stores the total
number of votes cast but is only accessible and modifiable within the contract itself, ensuring the confidentiality
and integrity of the voting process.

Internal: They are accessible within the contract where they are defined and by any derived contracts. They are not
accessible externally, ensuring encapsulation within the contract hierarchy.
Example:
In a DAPP for a loyalty program, the redeemPoints function marked as internal can be used. This function allows
derived contracts representing different loyalty tiers to access and redeem points accumulated by users,
maintaining the exclusivity of the redemption process within the loyalty program.

External: They are part of the contract interface and can only be called by external contracts using transactions.
They cannot be accessed internally within the contract and require an EVM call to execute.
Example:
For an escrow smart contract handling transaction, the releaseFunds function marked as external can be
implemented. This function enables external contracts or users to trigger the release of funds held in escrow,
ensuring secure and transparent transactions between parties.

Question # 02: Explain in detail about different types of functions and visibility modes used in functions
in solidity along with their examples? (1-mark)
Answer:
In Solidity, functions in smart contracts can have different visibility modes that determine how they can be accessed
within the contract.
● State Functions: These functions are used to modify the state of the contract. They can be called by any
contract on the blockchain, but they can also modify the state of the contract.
Example:
In an online voting system smart contract, a function like voteForCandidate that updates the vote count for
a candidate would be a state function.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science Technology &
Management
(ZUFESTM)
Department of Computer Science and Software Engineering
● View Functions: They provide read-only access to the contract's data without modifying the state.
Example:
In a decentralized marketplace contract, a function like getProductPrice that retrieves the price of a product
without changing it would be a view function.
● Pure Functions: They do not read or modify the contract's state and return a value without consuming gas
when called externally.
Example:
In a token contract, a function like add that calculates the sum of two numbers without interacting with the
contract’s state would be a pure function.
● Payable Functions: They can receive Ether along with the call and modify the contract's state, commonly
used for handling Ether transfers.
Example:
In a crowdfunding smart contract, a function like contribute that allows users to send Ether to fund a
project would be a payable function.
There are four function visibility modes:
● Public: These functions can be accessed by any contract on the blockchain and are the default visibility
mode.
Example:
In a decentralized token contract, a function like transfer that allows users to transfer tokens publicly would
be a public function.
● Private: These functions can only be called by the contract itself, restricting access from other contracts.
Example:
In a voting smart contract, a function like finalizeResults that calculates final voting results internally would
be a private function.
● Internal: These functions can be called by the contract itself and by any contract that inherits from it.
Example:
In an inheritance structure for smart contracts, a function like updateData that updates shared data within
the contract hierarchy would be an internal function.
● External: These functions can only be called by other contracts, not by the contract itself.
Example:
In a decentralized exchange contract, a function like trade that allows external contracts to execute trades
would be an external function.

Question # 03:
A) Write a half page summary on
https://www.theserverside.com/tip/Introduction-to-Solidity-Build-an-Ethereum-smart-contract.
(0.5-mark)
Answer:
The article provides a comprehensive introduction to Solidity, a programming language used for developing
smart contracts on the Ethereum blockchain. We`ve seen a simple example of a smart contract called
"SimpleStorage" that stores a single number and allows anyone to access or modify it. It taught us that
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science Technology &
Management
(ZUFESTM)
Department of Computer Science and Software Engineering
smart contracts are self-executing contracts with the terms of the agreement directly written into code.
They are stored on the Ethereum blockchain and can be accessed by anyone in the world. Solidity is a
statically typed programming language that is similar to Javascript and C. Each contract contains state
variables, functions, and common data types. Contract-specific features include modifier (guard) clauses,
event notifiers for listeners, and custom global variables.we got to know that how to create a sub currency
example, which is a simple cryptocurrency contract that allows only its creator to create new coins. Anyone
can send coins to each other without registering with a username and password, all they need is an
Ethereum keypair. The contract also includes error handling for insufficient balance. The article also
discusses the different types of functions and visibility modes used in Solidity. Public functions/variables
can be used both externally and internally. For public state variables, Solidity automatically creates a getter
function. Internal functions/variables can only be used internally or by derived contracts. Private
functions/variables can only be used internally and not even by derived contracts. The article provides a
brief overview of the deployment process and testing of smart contracts. It is important to note that smart
contracts can get complex very quickly, and the more code and state the contract is maintaining, the more
expensive it is to deploy and use. Therefore, it is crucial to consider the tradeoff of code, state, and cost as
part of the design.

B) Explain how arrays and loops work in solidity by any example? (0.5 marks)
Answer:
In Solidity, arrays are used to store a collection of elements of the same data type. They can be of fixed size
or dynamic. For example, you can have an array of integers or addresses.
When it comes to loops in Solidity, there are different types like the while loop, do-while loop, and for loop.
These loops allow you to execute a block of code repeatedly based on a condition. For instance, a while
loop will keep running the code block as long as a certain condition is true.
Example:
contract ArrayLoopExample {
uint[] public myArray;
function addElementsToArray() public {
myArray.push(10);
myArray.push(20);
myArray.push(30);
}
function incrementArrayValues() public {
for (uint i = 0; i < myArray.length; i++) {
myArray[i] += 5;
}
}
}

Question# 04: Explain Mainnet, Testnet , Rinkeby Faucet and Metamask ? (1-mark)
Answer:
They are essential components in the Ethereum ecosystem.
Mainnet: The Mainnet refers to the main Ethereum blockchain where real Ether is used for transactions. It
is the live network where actual cryptocurrency transactions take place.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science Technology &
Management
(ZUFESTM)
Department of Computer Science and Software Engineering
Testnet: Testnets are alternative blockchains that developers use to test their decentralized applications
(dApps) without using real money. Testnets like Rinkeby provide a safe environment for testing and
debugging code before deploying it on the Mainnet.
Rinkeby Faucet: The Rinkeby Faucet is a tool that allows users to request test Ether (Rinkeby Ether) for free
on the Rinkeby testnet. This test Ether has no real-world value and is used solely for testing purposes on
the Rinkeby testnet.
Metamask: Metamask is a popular web wallet that enables users to interact with dApps on the Ethereum
blockchain. By default, Metamask is set to the Ethereum Mainnet, but users can add testnets like Rinkeby
to test their dApps without using real Ether. It provides a user-friendly interface for managing Ethereum
assets and interacting with decentralized applications.

Question#05:
A) How does Ethereum handle network congestion? (0.5 Marks)
Answer:
Ethereum handles network congestion through various methods, including layer 2 scaling solutions,
consensus upgrades, sharding, and limiting blockchain bloat. Layer 2 scaling solutions like roll-ups and side
chains move activity off-chain while leveraging Ethereum security. The consensus upgrade to Proof-of-Stake
aims to handle more transactions per second at lower costs. Sharding, a planned upgrade, parallelizes
transaction processing across multiple chains to increase throughput. Restricting certain activities like
minting NFTs or identifying network spam transactions during congestion can help limit blockchain bloat.
Allowing some failed transactions can relieve network capacity pressure during peak congestion. Higher gas
fees can also help reduce network abuse.
B) What are ERC-20 tokens, and why are they important? (0.5 marks)
Answer:
ERC-20 tokens are standards for creating digital tokens on the Ethereum blockchain. They are important
because they allow developers to create new tokens that are compatible with a wide range of products and
services within the Ethereum ecosystem. ERC-20 tokens can represent any transferable non-unique asset,
such as shares in a company or virtual goods in a video game. They are fungible, meaning they can be
exchanged with other tokens of the same type, and are widely used in decentralized finance, stablecoins,
governance tokens, and other applications. ERC-20 tokens are important because they enable seamless
integration and compatibility with various products and services within the Ethereum ecosystem. They have
become the standard for building new tokens within the Ethereum ecosystem, allowing for smooth
interaction between different parts of the Ethereum blockchain. ERC-20 tokens have unleashed a wave of
innovation, democratization, and financial inclusion, shaping the future of decentralized economies.

You might also like