1

I deployed my smart contract on Kovan Etherium testnet. After that, I am trying to interact with smart contract methods using web3 1.0.0. Below is my node js code:

var Web3 = require('web3');
var api = myapikey;
const testnet = 'https://kovan.infura.io/'+ api;
const web3 = new Web3(new Web3.providers.HttpProvider(testnet))

function a (){
        const abi =[{ abi json}];
        var MyContract = new web3.eth.Contract(abi,'0xf...');
        console.log(MyContract.address);
        console.log(MyContract.jsonInterface);
        MyContract.methods.buyCoordinator(1,'https://cdn.pixabay.com/photo/2016/02/17/19/08/lotus-1205631_960_720.jpg','abc').call({from:'0x7...'},(error, result) => {
                console.log(result);
                console.log(error);
        });
}

a();

It returns null and giving me the following error:

Error: Node error: {"code":-32015,"data":"Reverted 0x","message":"VM execution error."} at Function.validate (/home/administrator/node_modules/web3-providers/dist/web3-providers.cjs.js:114:18) at HttpProvider._callee$ (/home/administrator/node_modules/web3-providers/dist/web3-providers.cjs.js:708:61) at tryCatch (/home/administrator/node_modules/regenerator-runtime/runtime.js:62:40) at Generator.invoke [as _invoke] (/home/administrator/node_modules/regenerator-runtime/runtime.js:288:22) at Generator.prototype.(anonymous function) [as next] (/home/administrator/node_modules/regenerator-runtime/runtime.js:114:21) at asyncGeneratorStep (/home/administrator/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24) at _next (/home/administrator/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9) at at process._tickCallback (internal/process/next_tick.js:188:7)

Can anybody tell me the meaning of this error? Where I am getting wrong? And how to confirm whether the smart contract has interacted or not?

  • I am getting this error on payable methods. – Varsh May 2 at 7:08
0

use send and not call

myContract.methods.myMethod([param1[, param2[, ...]]]).send(options[, callback])

Send -> Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.

Call -> Will call a “constant” method and execute its smart contract method in the EVM without sending any transaction. Note calling can not alter the smart contract state.

and it also could need a "value" in option, if it is a payable function and require ether

  • And how do you know that the method is not constant, when this dude hasn't posted the contract's code? – goodvibration May 2 at 9:32
  • there is no payable constant method (see his comment). and actually the name of the method say that this is a transaction-method and not a query -method – Majd TL May 2 at 10:43
  • And how do you know that the method is payable, when this dude hasn't posted the contract's code? (BTW, he doesn't specify a value field, so there's a pretty good chance that this method is in fact not payable). – goodvibration May 2 at 14:06
  • Oh, I see you even wrote it yourself at the bottom of your answer... so again - how do you know that the method is payable? – goodvibration May 2 at 14:07
  • 1
    this dude worte down in the comment section that he is getting this error on a payable method, "I am getting this error on payable methods. – Varsh yesterday" – Majd TL May 3 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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