Can't really use the transfer function as it is written. It assumes the owner uses it. So made a new function for the "minting" function for the faucet to use. Not sure why the compiler message is so cryptic.
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
Trying to create a Faucet for my ERC-20 Token, and getting a "Gas Estimation Failed" when running my dripToken
function which looks like this (UPDATED):
function dripToken() public {
require(faucetStatus);
if(!checkStatus(msg.sender)) revert();
tokenInstance.updateSupply(oneToken);
updateStatus(msg.sender, oneMinute);
tokenInstance.transfer(msg.sender, oneToken);
}
I have narrowed it down to the line with the transfer call which causes the error. I now deploy my ERC-20 Token and pass that into the faucet contract on the following way:
constructor(string _fname, address _tokenInstance) public {
tokenInstance = MyToken(_tokenInstance);
faucetName = _fname;
faucetStatus = true;
emit FaucetOn(faucetStatus);
}
My Token transfer function is from https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/StandardToken.sol I just noticed I get a compiler warning on the transfer function which hints at the problem, but I don't understand why (yet). Here is the warning:
Gas requirement of function StandardToken.transfer(address,uint256) high: infinite. If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)
function transfer(address _to, uint256 _value) public returns (bool) {
require(_value <= balances[msg.sender]);
require(_to != address(0));
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
I create my Token in the following way. I now initialize it with a small supply.
contract MyToken is StandardToken {
string public name;
uint8 public decimals;
string public symbol;
constructor() public {
StandardToken.balances[msg.sender] = 1000000000000000000;
StandardToken.totalSupply_ = 1000000000000000000;
name = "My Token";
decimals = 18;
symbol = "MY";
}
}
Posted my code on google drive: https://drive.google.com/open?id=1EvKEVhD8bR2oKS2W1XNRQpTqVbieUcmC
transfer
, but I would guess that it fails if the contract itself doesn't have a high enough balance. You might just wanttotalSupply_ += oneToken; balanceOf[msg.sender] += oneToken; emit Transfer(0, msg.sender, oneToken);
.Transfer
is an event that should be emitted by your token any time a token is transferred. (By convention, an event is emitted showing a transfer from address 0 when new tokens are minted.)