Advertisement
amu2002

SimpleBank

Nov 20th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity 0.8.22;
  3.  
  4. contract Bank{
  5.  
  6.     address public accountholder;
  7.     uint256 balance = 0;
  8.     constructor()
  9.     {
  10.       accountholder = msg.sender;//one who will deploy the contract
  11.     }
  12.    
  13.     function deposit() public payable  {
  14.         require(msg.sender==accountholder,"you are not an account holder");
  15.         require(msg.value>0,"deposit amount should be greater than 0.");
  16.        
  17.         balance += msg.value;
  18.     }
  19.     function withdraw() payable public
  20.     {
  21.         require(msg.sender==accountholder,"you are not an account holder");
  22.         require(balance > 0,"You dont have enough balance.");
  23.        
  24.         payable(msg.sender).transfer(balance);
  25.         balance=0;
  26.     }
  27.     function showBalance() public view returns(uint)
  28.     {
  29.         require(msg.sender==accountholder,"you are not an account holder");
  30.         return balance;
  31.  
  32.     }
  33.  
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement