Created
February 25, 2022 14:45
-
-
Save anoochit/6c87c222415acd002d4820428001b404 to your computer and use it in GitHub Desktop.
Faucet
This file contains 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
// SPDX-License-Identifier: MIT | |
// Author: Jacob Suchorabski | |
pragma solidity >= 0.7.0 <= 0.7.4; | |
contract Faucet{ | |
address owner; | |
mapping (address => uint) timeouts; | |
event Withdrawal(address indexed to); | |
event Deposit(address indexed from, uint amount); | |
constructor() { | |
//Will be called on creation of the smart contract. | |
owner = msg.sender; | |
} | |
// Sends 0.1 ETH to the sender when the faucet has enough funds | |
// Only allows one withdrawal every 30 mintues | |
function withdraw() external{ | |
require(address(this).balance >= 1 ether, "This faucet is empty. Please check back later."); | |
require(timeouts[msg.sender] <= block.timestamp - 30 minutes, "You can only withdraw once every 30 minutes. Please check back later."); | |
msg.sender.transfer(1 ether); | |
timeouts[msg.sender] = block.timestamp; | |
emit Withdrawal(msg.sender); | |
} | |
// Sending Tokens to this faucet fills it up | |
receive() external payable { | |
emit Deposit(msg.sender, msg.value); | |
} | |
// Destroys this smart contract and sends all remaining funds to the owner | |
function destroy() public{ | |
require(msg.sender == owner, "Only the owner of this faucet can destroy it."); | |
selfdestruct(msg.sender); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment