Created
September 12, 2019 15:10
-
-
Save patitonar/3202ebd4c823899f2fd08344ed642b07 to your computer and use it in GitHub Desktop.
Deposit example in solidity. Get contract balance, anyone can deposit, anyone can withdraw all the balance
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
pragma solidity 0.5.11; | |
contract Deposits { | |
event Deposited(address indexed payee, uint256 weiAmount); | |
event Withdrawn(address indexed payee, uint256 weiAmount); | |
function deposit() public payable { | |
emit Deposited(msg.sender, msg.value); | |
} | |
function withdraw() public { | |
uint256 balance = address(this).balance; | |
msg.sender.transfer(balance); | |
emit Withdrawn(msg.sender, balance); | |
} | |
function getBalance() public view returns (uint256) { | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment