Blockchain Quiz and Assignment 2
These are Blockchain Essentials And Development Assignment 2
Quiz
Q1. Blockchain is a type of ____.
Database
Table
View
Object
Answer: Database
Q2. Are Decentralized Blockchains immutable
TRUE
FALSE
Answer: TRUE
Q3. The types of Blockchain networks are
public
permissioned
consortium
All of the above
Answer: All of the above
These are Blockchain Essentials And Development Assignment 2
Q4. As Solidity does not support the Switch statement, what else can you do to replace the same behavior?
if-else
if else if else
for loop
while loop
Answer: if else if else
Q5. What happens if the execution of a Smart Contract consumes more than the specified gas?
The contract still gets executed
The contract does not get executed
The user gets a refund
None of the above
Answer: The contract does not get executed
Q6. In the Etherscan website, the transaction fee of each transaction is quoted in which of the following?
BTC
gwei
USD
INR
Answer: gwei
These are Blockchain Essentials And Development Assignment 2
Q7. A pure function in solidity can access
state variables
local variables
both
none
Answer: local variables
Q8. ________ can be used to restrict access in solidity
modifiers
functions
constructors
all of the above
Answer: modifiers
Q9. 1 gwei is _________ ETH
10^-9
10^-18
10^9
10^18
Answer: 10^-9
These are Blockchain Essentials And Development Assignment 2
Q10. solidity is also known as
curly bracket language
access restriction language
both
none
Answer: curly bracket language
Q11. The symbol _; in modifiers is used to
shift to function definition
shift to another modifier
terminate the process
All of the above
Answer: shift to function definition
Q12. msg.sender fetches __________
20 bytes accounts address
40 bytes account address
ethers in an account
transaction hash
Answer: 20 bytes accounts address
These are Blockchain Essentials And Development Assignment 2
Q13. the data type address payable can
hold 20 bytes address
transfer ethers to another account
cannot transfer ethers to another account
only receive ethers
Answer: transfer ethers to another account
Q14. The data types in Ethereum are
uint256
fixedMxN
bool
All of the above
Answer: All of the above
Q15. in fixedMxN
M should be divisible by 8
M should be divisible by 16
M should be divisible by 32
M should be divisible by 64
Answer: M should be divisible by 8
These are Blockchain Essentials And Development Assignment 2
Assignment
Q1) PiggyBank is a concept we all know from childhood where we collect money till a particular
time period in a container called PiggyBank and will break it at some time to withdraw all the
money we collected. Create a Smart Contract that implements the concept of piggybank.
a) Set the owner to the deployer of the contract using the constructor.
b) Deposit money to the contract (piggyBank) through receive() function.
c) Emit an event for the Deposit function.
d) Write the modifier onlyOwner() so that only the owner can call the withdraw function.
e) Write the withdraw() function to kill the contract and transfer all the contract balance
to the owner’s account.
f) Emit an event for withdrawal function.
Solution:
pragma solidity ^0.8.0;
contract PiggyBank {
address payable owner;
event Deposit(address depositor, uint amount);
event Withdrawal(address withdrawer, uint amount);
constructor() public {
owner = msg.sender;
}
function receive() public payable {
emit Deposit(msg.sender, msg.value);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function withdraw() public onlyOwner {
emit Withdrawal(msg.sender, address(this).balance);
owner.transfer(address(this).balance);
selfdestruct(owner);
}
}
These are Blockchain Essentials And Development Assignment 2
Q2) The Ownable smart contract keeps the track of ownership. At the moment who has the
ownership of the contract or maybe tokens like NFTs. Ownership is transferrable so we can
transfer it from one user to the other and get the respective benefits. Create a smart contract that implement the following functionalities:
a) Set the owner to the deployer of the contract using the constructor.
b) Write the modifier onlyOwner() so that only the owner can call certain functions like
transferring the current ownership of the contract.
c) Write the function for getting the current owner of the contract
d) Write the function for transferring the ownership of the contract from the current owner
to the owner.
Solution:
pragma solidity ^0.8.0;
contract Ownable {
address public owner;
constructor() public
{
owner = msg.sender;
}
modifier onlyOwner()
{
require(msg.sender == owner);
_;
}
function getOwner() public view returns (address)
{
return owner;
}
function transferOwnership(address newOwner) public onlyOwner
{
require(newOwner != address(0));
owner = newOwner;
}
}
Here, the constructor() function is used to set the initial owner of the contract to the deployer. The onlyOwner() modifier is used to restrict access to certain functions to only the current owner of the contract. The getOwner() function returns the current owner of the contract, and the transferOwnership() function allows the current owner to transfer ownership of the contract to a new address. The require(newOwner != address(0)) check is added to make sure that new owner address is not a zero address.
These are Blockchain Essentials And Development Assignment 2
Q3) Explain Solidity and its features. What types of applications can be developed using
Solidity.
Solution:
Solidity is a programming language for writing smart contracts on the Ethereum blockchain. It is similar to JavaScript and is designed to be used for creating decentralized applications (dApps) on the Ethereum platform.
Some features of Solidity include:
•Support for inheritance and complex user-defined types
•Support for libraries
•Support for complex user-defined types
•Support for events and logging
•Support for unit testing
Using Solidity, developers can create a wide range of decentralized applications such as:
•Decentralized exchanges (DEXs)
•Non-fungible tokens (NFTs)
•Gaming platforms
•Supply chain management systems
•Voting systems
•Crowdfunding platforms and many more
Solidity is specific to the Ethereum blockchain and cannot be used for other blockchain platforms.
These are Blockchain Essentials And Development Assignment 2
Blockchain all weeks assignments: Click Here
These are Blockchain Essentials And Development Assignment 2