ERC20 – Resolving Mint Function Error: “Transaction Has Been Reverted by the EVM”

erc-20evmgas-estimatemintsendtransaction

I want to allow an external app to mint tokens when a user performs an action. I have a separate contract that calls the "mintTo" function for an ERC20 token. Here's the token contract.

contract myToken is ERC20Mintable {

    constructor() public {
    
       symbol = "MYT";
       name = "My Token";
       decimals = 18;
       _totalSupply = 50*10**18;  //initial supply of 50 tokens
       balances[msg.sender] = _totalSupply;
       emit Transfer(address(0), msg.sender, _totalSupply);
     }

     /* Mint function from ERC20Mintable */
    function mintTo(address _to, uint _amount) public 
    {
       _totalSupply = safeAdd(_totalSupply, _amount);
       balances[_to] = safeAdd(balances[_to], _amount);

       emit Mint(msg.sender, _to, _amount);
  }
}

and here's the "Minter" contract.

contract Minter {
    
 myToken token;

 function mintToken() private {
    address addr = msg.sender;
    
    uint _reward = 100 * (10**18);
    
    token.mintTo(addr, _reward);
  }
}

To ensure its not the web3 app, I tested the "mintToken" function call on Remix and got the following error:

Gas estimation errored with the following message (see below). The
transaction execution will likely fail.

I've tried several different things but keep hitting the same wall. Any guidance would be greatly appreciated!

Best Answer

function mintToken() private private means the function can only be called from within the contract itself, try to change it to public or external and it should work