Skip to content

Instantly share code, notes, and snippets.

@AyDeveloper
Created August 9, 2022 21:59
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 AyDeveloper/e3c30e52d15d4d3b15d309adec0e0a7e to your computer and use it in GitHub Desktop.
Save AyDeveloper/e3c30e52d15d4d3b15d309adec0e0a7e to your computer and use it in GitHub Desktop.
pragma solidity ^0.8.0;
contract Donation {
// input your default donor address
address public donor = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
uint constant DONATION_FEE = 2 ether;
modifier onlyDonor() {
require(msg.sender == donor,"Only buyer can call this.");
_;
}
function setNewDonor(address _donor, address _recipient) public payable onlyDonor {
uint bal = address(this).balance;
uint amount = msg.value;
if (msg.value < DONATION_FEE) revert("Not enough Ether provided.");
// Perform the buy operation.
donor = _donor;
payable(_recipient).transfer(amount);
assert(address(this).balance == bal - amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment