A simple contract for addition, an error is reported when calling the function add in Web3 provider mode:
"Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
VM Exception while processing transaction: invalid opcode."
But it works fine in JavaScript mode. The contract is as following:
pragma solidity >=0.4.0;
contract Calc
{
function add(uint a,uint b) public payable returns(uint){
return a+b;
}
}
I found out that if I use the pure modifier and compile it using the version 0.4.24, it would work.:
pragma solidity >=0.4.0;
contract Calc
{
function add(uint a,uint b) public view returns(uint){
return a+b;
}
}
choose the compiler 0.4.24, then I can call the function add successfully. Why is that?