Skip to content

Instantly share code, notes, and snippets.

@jchudzynski
Created February 14, 2022 04:35
Show Gist options
  • Save jchudzynski/766e8b4d5cda8fe1a3a56599037dbd46 to your computer and use it in GitHub Desktop.
Save jchudzynski/766e8b4d5cda8fe1a3a56599037dbd46 to your computer and use it in GitHub Desktop.
Faucet
// SPDX-License-Identifier: MIT
// Author: Janusz Chudzynski
pragma solidity >=0.4.22 <0.9.0;
contract Faucet {
mapping(address=>uint) lastTransfers;
uint maxAllowed = 10 ** 18 * 5000;
constructor() {
}
function requestTokens(address payable requestor, uint amount) external {
uint lastTransfer = lastTransfers[requestor];
require(lastTransfer > block.timestamp + 1 hours, "You already requested funds hour ago");
require(address(this).balance > maxAllowed, "Not enough funds in the faucet. Please donate");
require(maxAllowed - amount >= 0, "Requested More than allowed");
requestor.transfer(amount);
lastTransfers[requestor] = amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment