Skip to content

Instantly share code, notes, and snippets.

@hydai
Created September 19, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hydai/be2e42877efc29b6d9536ef28a87ee8a to your computer and use it in GitHub Desktop.
Save hydai/be2e42877efc29b6d9536ef28a87ee8a to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
contract PiggyBank {
uint public goal;
constructor(uint _goal) {
goal = _goal;
}
receive() external payable {}
function getMyBalance() public view returns (uint) {
return address(this).balance;
}
function withdraw() public {
if (getMyBalance() > goal) {
selfdestruct(msg.sender);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment