TokenFaucet Contract (ERC20)

ERC20 水龍頭

IERC20.sol

//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IERC20 {

    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);

    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint);
    function transfer(address recipient, uint amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint amount) external returns (bool);
    function approve(address spender, uint amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint);

    // ======================================================
    //                        OPTIONAL                       
    // ======================================================
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);

}

TokenFaucet.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "./IERC20.sol";

contract TokenFaucet {

    IERC20 immutable public Token;

    uint256 public amountAllowed = 100 ether;
    mapping(address => bool) public receivedAddress;

    event SendToken(address indexed receiver, uint256 indexed amount);

    constructor(address _tokenContract) {
        Token = IERC20(_tokenContract);
    }

    function requestTokens() external {
        require(!receivedAddress[msg.sender], "One address can only be withdrawn once");
        require(Token.balanceOf(address(this)) >= amountAllowed, "Faucet Empty!");
        
        Token.transfer(msg.sender, amountAllowed);
        receivedAddress[msg.sender] = true;

        emit SendToken(msg.sender, amountAllowed);
    }

}

BNB Chain Testnet

https://testnet.bscscan.com/address/0xdCdb1976274671AcD75EbB56C0A5c5c4404A8cC2

Last updated