Created
February 4, 2022 19:06
-
-
Save zscole/057c72899e9f5b1124bdb51f21f90f78 to your computer and use it in GitHub Desktop.
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
| contract EtherStore { | |
| mapping(address => uint) public balances; | |
| function deposit() public payable { | |
| balances[msg.sender] += msg.value; | |
| } | |
| function withdraw() public { | |
| uint bal = balances[msg.sender]; | |
| require(bal > 0); | |
| (bool sent, ) = msg.sender.call{value: bal}(""); | |
| require(sent, "Failed to send Ether"); | |
| balances[msg.sender] = 0; | |
| } | |
| // Helper function to check the balance of this contract | |
| function getBalance() public 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