0

When I am trying to call a function that is deployed in a smart contract, it shows me

Error: Returned error: VM Exception while processing transaction: revert

Even when I am trying to call a simple HelloWorld function deployed in smart contract, the error still persists. I have successfully linked the accounts of metamask with Node.js script. I am using solidity to write smart contracts and node.js for communicating with the smart contract for this project. I am new to Blockchain development.

The smart contract:

contract SampleContract{
    function sayHello() public pure returns (string memory) {
        return "Hello World";
    }
}

Node.js code:

I am trying to execute the sayHello() function when a GET request at root is done)

app.get('/', (req, res) => {
  
  contract.methods.sayHello().call()
  .then(function(result) 
  {
    console.log(result);
    res.send(result);
  })
  .catch(function(error) 
  {
    console.error(error);
  }) 

  res.send('Current account is: '+ JSON.stringify(account));
})

I am able to the current account address on localhost:8000

Error:

Error: Returned error: VM Exception while processing transaction: revert
    at Object.ErrorResponse (/home/deepu/Desktop/Blockchain Project/sample_node/node_modules/web3-core-helpers/lib/errors.js:28:19)
    at /home/deepu/Desktop/Blockchain Project/sample_node/node_modules/web3-core-requestmanager/lib/index.js:300:36
    at /home/deepu/Desktop/Blockchain Project/sample_node/node_modules/web3-providers-http/lib/index.js:127:13
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  data: '0x'
}

Expected Output: The sayHello() function must be executed and the 'Hello World' should be displayed in the console.

James Z
  • 12,209
  • 10
  • 24
  • 44
Deepu D
  • 1
  • 1

0 Answers0