-
Notifications
You must be signed in to change notification settings - Fork 2
/
BankContract.sol
36 lines (24 loc) · 1.07 KB
/
BankContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
//i created a smart contract that allows a user to deposit, withdraw and save ETH!!
contract SmartSHop{
//we mapped the address of the caller balance in the contract
mapping(address => uint) public balances;
// whatever the user deposit is added to msg.value of the sender address we mapped above
function deposit() public payable{
balances[msg.sender] += msg.value;
}
//we create the fucntion of witdraw
function withdraw(uint _amount) public{
//we create a require arg to make sure the balance of the sender is >= _amount if not ERR
require(balances[msg.sender]>= _amount, "Not enough ether");
//if the amount is availabe we subtract it from the sender
balances[msg.sender] -= _amount;
//True bool is called to confirm the amount
(bool sent,) = msg.sender.call{value: _amount}("Sent");
require(sent, "failed to send ETH");
}
function getBal() public view returns(uint){
return address(this).balance;
}
}