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 {
require(allowedToWithdraw(msg.sender));
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;
}
}