Assignment No.
03
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.22 <0.8.0;
contract Banking {
mapping(address => uint) public userAccount;
mapping(address => bool) public userExists;
// 1. Create Account
function createAcc() public payable returns (string memory) {
require(userExists[[Link]] == false, "Account Already Created");
if ([Link] == 0) {
userAccount[[Link]] = 0;
userExists[[Link]] = true;
return "Account created with 0 balance";
}
userAccount[[Link]] = [Link];
userExists[[Link]] = true;
return "Account created with initial balance";
}
// 2. Deposit
function deposit(uint256 amount) public payable returns (string memory){
require(userExists[[Link]] == true, "Account is not created");
require(amount> 0, "Deposit amount must be greater than zero");
userAccount[[Link]] += amount;
return "Deposit successful";
}
// 3. Withdraw
function withdraw(uint256 amount) public payable returns (string memory) {
require(userExists[[Link]] == true, "Account is not created");
require(amount > 0, "Withdrawal amount must be greater than zero");
require(userAccount[[Link]] >= amount, "Insufficient balance");
userAccount[[Link]] -= amount;
return "Withdrawal Successful";
}
// 4. Transfer Amount to another user
function TransferAmount(address payable userAddress, uint amount) public
returns (string memory) {
require(userExists[[Link]] == true, "Sender account is not
created");
require(userExists[userAddress] == true, "Recipient account is not
created");
require(amount > 0, "Transfer amount must be greater than zero");
require(userAccount[[Link]] >= amount, "Insufficient balance");
userAccount[[Link]] -= amount;
userAccount[userAddress] += amount;
return "Transfer successful";
}
// 5. Show Balance
function getBalance() public view returns (uint) {
require(userExists[[Link]] == true, "Account is not created");
return userAccount[[Link]];
}
}