Skip to content

Instantly share code, notes, and snippets.

@zscole
Created February 4, 2022 19:06
Show Gist options
  • Select an option

  • Save zscole/057c72899e9f5b1124bdb51f21f90f78 to your computer and use it in GitHub Desktop.

Select an option

Save zscole/057c72899e9f5b1124bdb51f21f90f78 to your computer and use it in GitHub Desktop.
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