[Ethereum] Error: Node error: {“code”:-32015,”data”:”Reverted 0x”,”message”:”VM execution error.”}

myetherwalletnodejssolidityweb3js

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?

Best Answer

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