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

+1 vote

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, 2019 in Blockchain by XHQ
2,553 views
Does anyone knows the reason?
Hi. Are you using Testrpc for Blockchain?
I have the same problem, could you please tell me how did you solve it?

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,370 points
3,098 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,740 points
865 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,740 points
2,014 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 8, 2018 in Blockchain by Shashank
• 10,400 points
687 views
+1 vote
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
1,928 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,456 views
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
• 69,220 points
1,468 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP