I've successfully deployed on Ganache test network a contract with this test method in it:
function test() public pure returns (uint) {
return 7;
}
In my JS script I try to call this method in this way:
var abi = JSON.parse('...'); //
var contract = new web3.eth.Contract(abi, '0xf1447c6d7Bff526411fFfC68502017Ce9a0AE54a'); // contract mined at this address
contract.methods.test().call().then(function(e,r) {
console.log(e,r);
});
The console.log gives me this result (instead of 7):
false, undefined
I don't think it's an address problem (i've tried to change it and tthe script raises an error before call the method).
Any idea?
false
instead of7
, but your callback will only receive one parameter: the result of the call. If you want to catch errors, add a.catch(function (error) { ... })
. – user19510 Mar 6 '18 at 18:06