Skip to content

Instantly share code, notes, and snippets.

@jchudzynski
Created February 15, 2022 04:14
Show Gist options
  • Save jchudzynski/ddbda93251010c7c6d1e622560c6c274 to your computer and use it in GitHub Desktop.
Save jchudzynski/ddbda93251010c7c6d1e622560c6c274 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
// Author: Janusz Chudzynski
pragma solidity >=0.4.22 <0.9.0;
contract Faucet {
mapping(address=>uint) lastTransfers;
uint amountToWithdraw = 10 ** 18 * 0.01;
function requestTokens(address payable requestor) external {
uint lastTransfer = lastTransfers[requestor];
require(lastTransfer + 1 hours <= block.timestamp, "Patience is a virtue. You already requested funds hour ago");
require(address(this).balance >= amountToWithdraw, "Not enough funds in the faucet. Please donate");
requestor.transfer(amountToWithdraw);
lastTransfers[requestor] = block.timestamp;
}
function getBalance() public view returns (uint) {
return address(this).balance;
}
receive() external payable {}
fallback() external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment