Created
August 13, 2024 18:37
-
-
Save amarachiugwu/d409275463377fc37a037cfd10393eac to your computer and use it in GitHub Desktop.
wa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity >=0.7.0 < 0.9.0; | |
| contract Wallet { | |
| // recieve ether | |
| // send ether | |
| // store ether | |
| // withdrawl ether | |
| // check balance | |
| // check balance in contract | |
| //events | |
| event Deposit(address _addrs, uint amount); | |
| event Send(address _reciever, uint amount); | |
| event Withdrawl(address withdrawer, uint amount); | |
| //modifier | |
| modifier hasEnough(address _addrs, uint _amount){ | |
| require(balances[_addrs] >= _amount, "Insufficient funds"); | |
| _; | |
| } | |
| //mapping | |
| mapping(address => uint) public balances; | |
| //recieve ether | |
| receive() external payable { | |
| balances[msg.sender] += msg.value; | |
| emit Deposit(msg.sender, msg.value); | |
| } | |
| // sending | |
| function send(address _reciever, uint _amount) external hasEnough(msg.sender, _amount) { | |
| balances[msg.sender] -= _amount; | |
| balances[_reciever] += _amount; | |
| emit Send(_reciever, _amount); | |
| } | |
| // withdrawl | |
| function withdrawl(uint _amount) external hasEnough(msg.sender, _amount){ | |
| balances[msg.sender] -= _amount; | |
| address payable reciever = payable(msg.sender); | |
| (bool sent,) = reciever.call{value : _amount}(""); | |
| require(sent, "withdrawal failed"); | |
| emit Withdrawl(msg.sender, _amount); | |
| } | |
| // getter getBalance | |
| function getBalance(address _addrs) external view returns(uint){ | |
| return balances[_addrs]; | |
| } | |
| function getContractBalance() external view returns(uint) { | |
| return address(this).balance; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment