Skip to content

Instantly share code, notes, and snippets.

@emmaodia
Created July 6, 2022 13:49
Show Gist options
  • Save emmaodia/c00599d1295a6e1756bd4fed463bcbfa to your computer and use it in GitHub Desktop.
Save emmaodia/c00599d1295a6e1756bd4fed463bcbfa to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Coin is ERC20 {
address public minter;
uint256 constant public waitTime = 24 hours;
mapping(address => uint) lastMintBlock;
event Sent(address _from, address _to, uint _amount);
constructor(uint256 _initialsupply) ERC20("Bread Token", "BREAD") {
minter = msg.sender;
_mint(minter, _initialsupply);
}
function faucet(uint _amount, address payable _receiver) public {
require(minter != _receiver, "Not recommended");
require(_amount <= 100, "You can only request for 100 Bread Tokens from the Faucet");
require(_receiver == msg.sender, "You can not mint for another EOA");
require(newMint(_receiver), "Wait for 24 hours");
_mint(_receiver, _amount);
lastMintBlock[_receiver] = block.timestamp + waitTime;
emit Sent(minter, _receiver, _amount);
}
function newMint(address _receiver) public view returns(bool) {
if(lastMintBlock[_receiver] == 0){
return true;
}else if(block.timestamp >= lastMintBlock[_receiver]) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment