Can't call contract function in Remix in Web3 provider mode, but it works in Javascript VM

0 votes

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?

Jun 15 in Blockchain by XHQ
44 views
Does anyone knows the reason?
Hi. Are you using Testrpc for Blockchain?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Blockchain

0 votes
1 answer

Can't call contract function in truffle console

Inspect the object adoption within the console. You will ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,050 points
587 views
0 votes
1 answer

How to call function in one contract from another contract in private blockchain?

Please check whether you have byzantiumBlock: 0 in your ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 26,550 points
47 views
0 votes
1 answer

Truffle migrate fails due to missing function, but it exists in node_modules

deployer.deploy(password1, password2, deadline, {value: 100, from: accounts[0]}); ...READ MORE

answered Oct 3, 2018 in Blockchain by digger
• 26,550 points
136 views
0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,350 points
27 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
141 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,520 points
77 views