Skip to content

Instantly share code, notes, and snippets.

@yemoli
Created December 27, 2021 11:15
Show Gist options
  • Save yemoli/03a4616e00c60f70fa8d75f9632b1d27 to your computer and use it in GitHub Desktop.
Save yemoli/03a4616e00c60f70fa8d75f9632b1d27 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.16+commit.9c3226ce.js&optimize=false&runs=200&gist=
pragma solidity 0.5.16;
contract owned{
address payable owner;
constructor() public{
owner = msg.sender;
}
modifier onlyOwner{
require(msg.sender == owner,"only the contract owner can call this function");
_;
}
}
contract mortal is owned {
// Contract destructor
function destroy() public onlyOwner {
selfdestruct(owner);
}
}
contract Faucet is mortal {
event Withdrawal(address indexed to, uint amount);
event Deposit(address indexed from, uint amount);
// Give out ether to anyone who asks
function withdraw(uint withdraw_amount) public {
// Limit withdrawal amount
require(withdraw_amount <= 0.1 ether);
require(address(this).balance >= withdraw_amount,"Insufficient balance in faucet for withdrawal request");
// Send the amount to the address that requested it
msg.sender.transfer(withdraw_amount);
emit Withdrawal(msg.sender, withdraw_amount);
}
// Accept any incoming amount
function () external payable {
emit Deposit(msg.sender, msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment