Skip to content

Instantly share code, notes, and snippets.

@luckyyang
Last active January 6, 2023 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckyyang/3a8c210203955b64c07fb8275d7366a9 to your computer and use it in GitHub Desktop.
Save luckyyang/3a8c210203955b64c07fb8275d7366a9 to your computer and use it in GitHub Desktop.
donation example of solidity
pragma solidity ^0.4.25;
contract Donation {
uint fundLimit = 1 ether;
address owner;
event fundMoved(address _to, uint _amount);
modifier onlyowner { if (msg.sender == owner) _; }
address[] _giver;
uint[] _values;
constructor () public {
owner = msg.sender;
}
function donate() public payable {
addGiver(msg.value);
}
function getFundLimit() public view returns (uint) {
return fundLimit;
}
function moveFund(address _to, uint _amount) onlyowner public {
uint balance = address(this).balance;
if (_amount <= balance) {
if (_to.send(balance)) {
emit fundMoved(_to, _amount);
} else {
revert();
}
} else {
revert();
}
}
function addGiver(uint _amount) internal {
_giver.push(msg.sender);
_values.push(_amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment