4

I was trying to transfer some ether using ganache desktop application in nodejs. It was properly working but suddenly an error occurred.

var s = 1;

try{
 web3.eth.sendTransaction({
 from: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
 to:'0x821aea9a577a9b44299b9c15c88cf3087f3b5544',
 value: web3.toWei(s.toString(), "ether")

}).then(function(receipt) {
    console.log(receipt);
    res.json({success: true});

}).catch(function(e){
console.log('error occured');
console.log(e);
res.json({success: false });
});

If .then() and .catch() is removed, ether is transferred.

4
  • if you are not using promises. Try using fallback fuctions – Prashant Prabhakar Singh Feb 15 '18 at 5:40
  • 1
    @PrashantPrabhakarSingh I think you mean "callback" functions. – user19510 Feb 15 '18 at 7:22
  • 1
    What version of web3.js are you using? 0.2x.0 doesn't support promises, but 1.0.0-beta.x does. – user19510 Feb 15 '18 at 7:22
  • I'm using 0.18.4 version and it was working perfectly..suddenly today this error showed up... – angelmaria Feb 15 '18 at 9:42
3

You need to use a callback. Kindly read the documentation.

var handleReceipt = (error, receipt) => {
  if (error) console.error(error);
  else {
    console.log(receipt);
    res.json(receipt);
  }
}

web3.eth.sendTransaction({
 from: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
 to:'0x821aea9a577a9b44299b9c15c88cf3087f3b5544',
 value: web3.toWei(s.toString(), "ether")
}, handleReceipt);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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