0% found this document useful (0 votes)
12 views2 pages

Solidity Banking Smart Contract

The document outlines a Solidity smart contract for a banking system that allows users to create accounts, deposit, withdraw, transfer funds, and check their balance. It includes functions to manage user accounts and ensures that various conditions are met before executing transactions. The contract utilizes mappings to track user accounts and their balances.

Uploaded by

phenomenal7659
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Solidity Banking Smart Contract

The document outlines a Solidity smart contract for a banking system that allows users to create accounts, deposit, withdraw, transfer funds, and check their balance. It includes functions to manage user accounts and ensures that various conditions are met before executing transactions. The contract utilizes mappings to track user accounts and their balances.

Uploaded by

phenomenal7659
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]];
}
}

You might also like