You are on page 1of 12

NAMEMAYANK YADAV

REG. NO  20BCE2114

DIGITAL ASSIGNMENT

BKT3001 DESIGN AND DEVELOPMENT OF BLOCKCHAIN


APPLICATIONS

SLOT:L39+L40

SUBMITTED TO-- SUBMITTED BY--


SWARNALATHA P MAYANK YADAV
(20BCE2114)
NAMEMAYANK YADAV
REG. NO  20BCE2114

QUESTION 1 Create a smart contract named MyContract


having a state variable as owner. Create a constructor to
fetch the address of the owner from msg and hold it into the
state variable owner. Also, create a function getBalance() to
show the current balance of the owner. After creating a
contract, compile, run and deploy in the Ganache
environment.

CODE:
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.13 and less than
0.9.0
pragma solidity ^0.6.8;

contract MyContract
{
    // Private state variable
    address private owner;

    // Defining a constructor
    constructor() public{
        owner=msg.sender;
    }
    function getOwner(
    ) public view returns (address) {  
        return owner;
    }

    function getBalance(
    ) public view returns(uint256){
        return owner.balance;
    }
}
NAMEMAYANK YADAV
REG. NO  20BCE2114

DEPLOYEMENT SCREENSHOT:

GANACHE SCREENSHOT:
NAMEMAYANK YADAV
REG. NO  20BCE2114

OUTPUT SCREENSHOT:
NAMEMAYANK YADAV
REG. NO  20BCE2114

QUESTION 2 Write a smart contract to create an Ether


Wallet in such a way that anyone can send ETH whereas only
an owner can withdraw and get balance.
CODE:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;
 
contract EtherWallet{
    address payable public owner;
 
    constructor(){
        owner = payable(msg.sender);    
    }
 
    receive() external payable {}
 
    function withdraw(uint _amount) external {
        require(msg.sender == owner,"Only the owner can call this methord.");
        payable(msg.sender).transfer(_amount);
    }
 
    function getBalance() external view returns (uint){
        return address(this).balance;
    }
}

DEPLOYEMENT SCREENSHOT:
NAMEMAYANK YADAV
REG. NO  20BCE2114

GANACHE SCREENSHOT:

OUTPUT SCREENSHOT:
1) Error while calling the function by not its owner.
NAMEMAYANK YADAV
REG. NO  20BCE2114

2) Successful withdraw transaction by owner:

2.1 ) Successful call to withdraw by owner function.


NAMEMAYANK YADAV
REG. NO  20BCE2114

Balance:
NAMEMAYANK YADAV
REG. NO  20BCE2114

QUESTION 3 Write a smart contract to create a sub currency which


define the following key functions:
 Send(address from, address to, uint amount) - Which is used to
send amount from one user to another.
 constructor() - which initiates the constructor.
 function mint(address receiver, unit amount) - Mints the crypto
currency
CODE:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;
 
contract Coin {
    address public minter;
    mapping (address => uint) public balances;
   
    event Sent(address from, address to, uint amount);
   
    constructor() {
        minter = msg.sender;
    }
 
    function mint(address receiver, uint amount) public {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }
 
    function send(address receiver, uint amount) public {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}
NAMEMAYANK YADAV
REG. NO  20BCE2114

DEPLOYMENT OUTPUT:

GANACHE OUTPUT:
NAMEMAYANK YADAV
REG. NO  20BCE2114

1) MINTING SCREENSHOT:

2) SEND FUNCTION CALL SCREENSHOT:

3) CONTRACT BALANCE SCREENSHOT:


NAMEMAYANK YADAV
REG. NO  20BCE2114

4) MINTED CONTRACT SCREENSHOT:

You might also like