I’m running Hardhat and testing with MetaMask and found something strange in the Hardhat console output. This happens when I go to MetaMask and select my contract’s token, then click “send”, then enter the destination address, at this point MetaMask calls my Hardhat node’s eth_estimateGas function:
eth_estimateGas Contract call: mycontract#transfer From: 0x0000..... To: 0x0000..... Value: 0 ETH Error: VM Exception while processing transaction: reverted with reason string 'Invalid amount' at mycontract.someFunction (contracts/mycontract.sol:584) at mycontract.transfer (contracts/mycontract.sol:603)
As you can see it calls my transfer function, which checks the amount and reverts with “Invalid amount” if it’s zero, which it is because I haven’t entered the amount to transfer yet in MetaMask.
What I don’t understand is why it’s calling mycontract.someFunction also. This is an external function that is never called anywhere in mycontract.
If I change the function name of someFunction then a different function is called instead. Maybe it’s just calling the first function in the bytecode or something. I don’t understand this behaviour, can someone enlighten me?