Skip to content

Instantly share code, notes, and snippets.

@patitonar
Created September 12, 2019 15:10
Show Gist options
  • Save patitonar/3202ebd4c823899f2fd08344ed642b07 to your computer and use it in GitHub Desktop.
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
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