Ich habe versucht, etwas Ether mit der Ganache-Desktop-Anwendung in nodejs zu übertragen . Es funktionierte einwandfrei, aber plötzlich trat ein Fehler auf.
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 });
});
Wenn .then() und .catch() entfernt werden, wird Ether übertragen.
Sie müssen einen Rückruf verwenden. Bitte lesen Sie die Dokumentation .
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);
Dies ist direkt aus der Dokumentation:
web3.eth.sendTransaction({from: '0x123...', data: '0x432...'})
.once('sending', function(payload){ ... })
.once('sent', function(payload){ ... })
.once('transactionHash', function(hash){ ... })
.once('receipt', function(receipt){ ... })
.on('confirmation', function(confNumber, receipt, latestBlockHash){ ... })
.on('error', function(error){ ... })
.then(function(receipt){
// will be fired once the receipt is mined
}); and it does not recognize .once, .on, or.then
or.catch
Prashant Prabhakar Singh
Benutzer19510
Benutzer19510
angelmaria