1

I use the following to call a solidity contract function in nodejs(v10.14.2) + web3(v0.20.7) + ganache(v1.2.3):

contract.getItemCount(function(err1,result1){
 console.log(result1);
}

result1(datatype BigNumber/uint256) do have the value returned from the contract function.

But sometimes i get out of gas error(ganache gas limit is 90000), I then used the following syntax:

contract.getItemCount.sendTransaction({gas: 200000},function(err1,result1){
 console.log(result1);
}

It executed(consumed 176424 gas) the function successfully. But result1 now has transaction hash as mentioned here. How should i get the result i.e., value returned by the contract function?

1 Answer 1

2

If you are calling the callback function of sendTransaction will obviously return the hash. You can also see that in the document you share in question.

You can simply call like this:

contract.getItemCount({gas: 200000}).then(result){
 console.log(result);
}

or

contract.getItemCount({gas: 200000},function(err,res){
   if(!err){
     console.log(res);
   }
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.