Reputation: 2263
I get this error when I try to call my solidity function using truffle.
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.
Upvotes: 0
Views: 772
Reputation: 3285
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.
Upvotes: 0