गुरुर्ब्रह्मा गुरुर्विष्णु गुरुर्देवो महेश्वरा गुरुर्साक्षात परब्रह्म तस्मै श्री गुरवे नमः !
Q1. Blockchain is a type of ____.
Database
Table
View
Object
Correct Answer : Database
Q2. Are Decentralized Blockchains immutable
TRUE
FALSE
Correct Answer : TRUE
Q3. The types of Blockchain networks are
public
permissioned
consortium
All of the above
Correct Answer : All of the above
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
Correct 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
Correct 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
Correct Answer : gwei
Q7. A pure function in solidity can access
state variables
local variables
both
none
Correct Answer : local variables
Q8. ________ can be used to restrict access in solidity
modifiers
functions
constructors
all of the above
Correct Answer : modifiers
Q9. 1 gwei is _________ ETH
10^-9
10^-18
10^9
10^18
Correct Answer : 10^-9
Q10. solidity is also known as
curly bracket language
access restriction language
both
none
Correct 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
Correct Answer : shift to function definition
Q12. msg.sender fetches __________
20 bytes accounts address
40 bytes account address
ethers in an account
transaction hash
Correct Answer :20 bytes accounts address
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
Correct Answer : transfer ethers to another account
Q14. The data types in Ethereum are
uint256
fixedMxN
bool
All of the above
Correct 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
Correct Answer : M should be divisible by 8
1. 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
Here is an example of a Solidity smart contract that implements the concept of a piggy bank:
pragma solidity ^0.8.0;
contract PiggyBank {
address owner;
event Deposit(address from, uint256 value);
event Withdrawal(address to, uint256 value);
constructor() public {
owner = msg.sender;
}
function receive() public payable {
require(msg.value > 0);
emit Deposit(msg.sender, msg.value);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function withdraw() public onlyOwner {
require(address(this).balance > 0);
emit Withdrawal(owner, address(this).balance);
owner.transfer(address(this).balance);
selfdestruct(owner);
}
}
Explanation of the contract:
The contract has an address variable "owner" that is set to the deployer of the contract in the constructor.
The receive() function allows anyone to deposit money into the contract. It emits a Deposit event with the address of the depositor and the value of the deposit.
The onlyOwner modifier ensures that only the owner can call the withdraw() function.
The withdraw() function allows the owner to withdraw all the money in the contract and destroy the contract by using the selfdestruct() function. It emits a Withdrawal event with the address of the owner and the value of the withdrawal.
The deposit and withdrawal event are used to track the transaction and can be used to notify the user about the transaction
2. 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.
Here is an example of a Solidity smart contract that implements the concept of an Ownable contract:
pragma solidity ^0.8.0;
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
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));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
Explanation of the contract:
The contract has an address variable "owner" that is set to the deployer of the contract in the constructor.
The onlyOwner modifier ensures that only the owner can call certain functions like transferring the current ownership of the contract.
The getOwner() function returns the current owner of the contract.
The transferOwnership(address newOwner) function allows the owner to transfer the ownership of the contract to a new address. It emits an OwnershipTransferred event with the previous owner and the new owner.
The OwnershipTransferred event is used to notify the user about the ownership change.
3. Explain Solidity and its features. What types of applications can be developed using Solidity?
Solidity is a programming language for writing smart contracts on the Ethereum blockchain. It is designed to be similar to JavaScript, making it easy for developers to learn and use.
Some of the features of Solidity include:
Object-oriented programming: Solidity is an object-oriented language, allowing developers to use concepts such as inheritance and encapsulation.
Strong typing: Solidity has a strong typing system, which helps to prevent errors and makes the code more readable.
Support for multiple types of data: Solidity supports various types of data, such as integers, booleans, and strings, which allows developers to create complex smart contracts.
Built-in support for Ethereum: Solidity has built-in support for Ethereum, including the ability to interact with the Ethereum Virtual Machine (EVM), and access to Ethereum-specific features such as gas and Ether.
Secure by design: Solidity has several security-focused features, such as the ability to prevent reentrancy attacks, and the ability to restrict access to certain functions.
Solidity can be used to develop a wide range of applications on the Ethereum blockchain, such as:
Decentralized finance (DeFi) applications: Solidity can be used to create decentralized exchanges, lending platforms, and other DeFi applications.
Non-fungible tokens (NFTs): Solidity can be used to create unique digital assets, such as digital collectibles and virtual real estate.
Supply chain management: Solidity can be used to create smart contracts that can track and verify the origin and authenticity of goods, reducing the risk of fraud.
Gaming: Solidity can be used to create decentralized gaming platforms, where players can own and trade in-game assets, and participate in decentralized tournaments.
Identity management: Solidity can be used to create decentralized identity management systems, where users can control their personal information and share it with others on their own terms.
In summary, Solidity is a programming language used to write smart contracts on the Ethereum blockchain. It's designed to be similar to JavaScript, making it easy for developers to learn and use. Solidity has several features that make it suitable for the development of various types of blockchain-based applications, including DeFi, NFTs, Supply Chain Management, Gaming, and Identity Management.