Loading...
In the previous section or the part 1 of my smartbook i will explain the basic function of the banking with solidity programming language. In this section i will explain the other function of banking application such as transfer and check the balance of particular account. So let's get started.
so how to create the function about the transfer the ether from account to
function transferether(address _add,uint256 amount)public payable
{
require(account_existed[msg.sender]==true,'user does not existed');
require(account_existed[_add]==true,'user does not existed');
account_amount[msg.sender]<=amount;
payable(_add).transfer(amount);
}
In the above function we mainly transfer the ether from a particular account to another account we mainly create the require condition that specifice the user is valid or not another require condition is for the another user account is valid or not.Then you have to specify that account amout of the user must be less than the required.after it we will send that amount to the another account with the transfer.
After this we specified the last function of our smartbook that is that the check the user balance
function checkbal()public view returns(uint256)
{
require(account_existed[msg.sender]==true,'user does not existed');
return account_amount[msg.sender];
}
In the above function we mainly specified what we check the balance of the particular user and for we first require that the user is existed and that function mainly return the balance of the user. so all it about the different function of the bank structure within the solidity programming.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract BANK{
mapping (address => uint256) public account_amount;
mapping (address => bool) public account_existed;
function createaccount() public returns(bool)
{
require(account_existed[msg.sender]==false,"user does not existed");
account_existed[msg.sender]=true;
return true;
}
function deposit(uint256 amount) public payable returns(bool)
{
require(account_existed[msg.sender]==true,'user does not existed');
msg.value>0;
msg.value==amount;
account_amount[msg.sender]=account_amount[msg.sender]+amount;
return true;
}
function withdrawether(uint256 amount) public payable
{
require(account_existed[msg.sender]==true,'user does not existed');
account_amount[msg.sender]<=amount;
account_amount[msg.sender]=amount- account_amount[msg.sender];
}
function transferether(address _add,uint256 amount)public payable
{
require(account_existed[msg.sender]==true,'user does not existed');
require(account_existed[_add]==true,'user does not existed');
account_amount[msg.sender]<=amount;
payable(_add).transfer(amount);
}
function checkbal()public view returns(uint256)
{
require(account_existed[msg.sender]==true,'user does not existed');
return account_amount[msg.sender];
}
}
and above is the whole contract within the solidity
Thank you !