0

I get this error when I try to call my solidity function using truffle.

enter image description here

My solidity code is as :

pragma solidity ^0.4.14;

contract SimpleDemo {
    function returnNumber () public view returns (uint) {
        return 500;
    }
}

The way I'm calling returnNumber() is by :

this.state.web3.eth.getAccounts((error, accounts) => {
    simpleDemo.deployed().then((instance) => {
        simpleDemoInstance = instance
        // Below line runs with the error ...
        return simpleDemoInstance.returnNumber.call()
    }).then((result) => {
        console.log(result)
    })
})

Also, this solution did not help at all. Hence, I asked separately.

Pramesh Bajracharya
  • 2,153
  • 3
  • 28
  • 54
  • Seems to me that you're receiving an `[Object object]` instead of the `500` primitive. Is there a reason you're using `.call()` instead of just `returnNumber()`? You could add a `.catch(..)` at the bottom of your promise chain to inspect more. – Ian MacDonald Feb 09 '18 at 17:22
  • Actually I have tried this with `returnNumber()` also, but same error persists. I'll try `catch()` right away now and find if something's off!! – Pramesh Bajracharya Feb 09 '18 at 17:27
  • @IanMacDonald I tried checking for some errors using `catch()` but got an object returned. I have no Idea how an object is being returned. The object is `{ "name": "BigNumber Error" }`. Now what am I suppossed to do with this error. :P – Pramesh Bajracharya Feb 10 '18 at 05:38

1 Answers1

0

It should be:

simpleDemoInstance.methods.returnNumber().call({ from: accounts[0] });

if it is a function that takes gas(assuming you want to send from metamask).

If it is not a payable function you use:

simpleDemoInstance.methods.returnNumber().call()

Also use es6. Trying to write this stuff without async await is terrible IMO.

ruby_newbie
  • 3,190
  • 3
  • 18
  • 29