0

I have this function in the smart contract:

function _mint(address account, uint256 amount) external onlyOwner {
  require(account != address(0), "ERC20: mint to the zero address");
  _totalSupply = _totalSupply.add(amount);
  _balances[account] = _balances[account].add(amount);
  supplyAvailable = supplyAvailable.add(amount);
  emit Transfer(address(0), account, amount);
}

I would like to call it from a web3 platform but I am getting an error:

Fatal error: Uncaught InvalidArgumentException: Please make sure the method exists.

The problem is probably due to the fact that the function "_mint" is not listed in the ABI contract. If I change the function, in the smart contract, from "external" to "public" (with owner privilege of course) it may get listed in the ABI contract but is it safe?

2
  • 1
    External functions are part of ABI and can be called from other contracts or via a transaction. They are part of ABI. But external functions can not be called from within the contract. So there is either something off with your contract or they way you are calling it. Jan 12, 2022 at 5:22
  • You nailed it! I made a mistake when I copied the ABI file from Remix. I forgot to select the proper contract from the dropbox. Thank you so much!
    – Vincent
    Jan 12, 2022 at 6:12

1 Answer 1

0

I guess this would depend on depends why you have made the _mint function external? Perhaps you could consider creating a safe public 'mint' function in the smart contract which calls this and make it internal.

3
  • So, I should create a new safe "public" function that will call an "internal" _mint function? I didn't know it was possible. So safe "public" functions are not so safe then? The reason behind this is that I want to be able to manage all functions from a dashboard. Thank you for your help @drexiya !
    – Vincent
    Jan 12, 2022 at 1:15
  • yes that is what I would suggest, but you would have to change the visibility of the _mint function as you cannot call it internally if it is 'external'. So I would consider making it internal then use your new function to call it. So it depends on why you want the _mint function to be external. Hope that helps.
    – C Mars
    Jan 12, 2022 at 1:19
  • I don't really "need" the _mint funct. to be "external" actually. I just wanted to be able to call it from outside the contract without being public. I'm still learning ... Let me try you guys suggestion. Thank you both for your help!
    – Vincent
    Jan 12, 2022 at 1:30

Your Answer

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

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