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!

1 Answer 1


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

  • Thanks for the feedback. I tried that and am still receiving the same message on the front end as well as Remix. Given that minting requires gas, should the smart contract has eth available? If so, how would I add eth to the smart contract? Aug 27, 2021 at 20:26
  • It doesnt, when you call the smart contract you pay for gas, which is forwarded to the token contract when your contract calls the token contract. Can you send the whole flattened code? or even better deploy it on testnet and send the address.
    – Foxxxey
    Aug 27, 2021 at 21:59
  • My bad on the delay, was traveling. Here's the contract addresses on Rinkeby: mintToken.sol - link Sep 2, 2021 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.