Need help to create rules in here

Hello everyone, i need a litlle help to finish this smartcontract, the goal, is, to create a faucet but, the smartcontract need first to check the user balance, and, only alow user to receive the tokens from faucet if have a specific amount of tokens of another smartcontract adress in his balance…

To solve:

  • check balance of user
  • if user have X amount of tokens of the smarcontract X then = true
    -else - dont let user spend gas fee
pragma solidity ^0.5.10;

interface ERC20 {
    function transfer(address to, uint256 value) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);

contract Faucet {
    uint256 constant public tokenAmount = 10000000000000000000;
    uint256 constant public waitTime = 240 minutes;

    ERC20 public tokenInstance;
    mapping(address => uint256) lastAccessTime;

    constructor(address _tokenInstance) public {
        require(_tokenInstance != address(0));
        tokenInstance = ERC20(_tokenInstance);

    function requestTokens() public {
        tokenInstance.transfer(msg.sender, tokenAmount);
        lastAccessTime[msg.sender] = block.timestamp + waitTime;

    function allowedToWithdraw(address _address) public view returns (bool) {
        if(lastAccessTime[_address] == 0) {
            return true;
        } else if(block.timestamp >= lastAccessTime[_address]) {
            return true;
        return false;

What is the question? It seems that you are almost there, since you have already instantiated one token, and you just need to instantiate another token and add one more condition in allowedToWithdraw function checking the balance of another token.

1 Like

this code, delivery free tokens to the user, but i need to add a function to only allow users to request tokens, if they have in their wallet balance of another token…

lets say, user have 100 000 TOKENA in their wallet balance, then is allowed to make the request and receive the free tokens from tokeninstance

how can i get the user balance, and how can i specifie the token i need to check in their balance?
can you help?

Added the code inline.

thanks very mutch, now i only need to check if user have the minimum “anothertokeninstance” required, i tested the code above, and everrthing works just fine but allow anyone to withdraw without having balance of “anothertokeninstance” closer and closer :slight_smile:

1 Like