web3 js sendet Ether, der nicht im Hauptnetz sendet

Ich verwende das folgende Codebeispiel, um Ether zwischen 2 meiner eigenen Konten zu senden, beide haben genug Geld:

"use strict";
var Web3 = require('web3');
var Tx = require('ethereumjs-tx');
// Show Web3 where it needs to look for a connection to Ethereum.
//web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
var web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/N6IIa2HvDYOovtgmPbhD'));
var gasPrice = "20";//or get with web3.eth.gasPrice
var gasLimit = '42000';
var addr = "...";
var toAddress = "....";
var amountToSend = web3.utils.toWei('0.0005', 'ether'); //$1
var nonce = web3.eth.getTransactionCount(addr); //211;
var rawTransaction = {
"from": addr,
"nonce": web3.utils.toHex(nonce),
"gasPrice": web3.utils.toHex(web3.utils.toWei('9', 'gwei')),
"gasLimit": web3.utils.toHex(gasLimit),
"to": toAddress,
"value": web3.utils.toHex(amountToSend) ,
"chainId": 1 //remember to change this
};
var privateKey = "...";
var privKey = new Buffer(privateKey, 'hex');
//console.log("privKey  : ", privKey);
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
console.log('serializedTx : '+serializedTx);
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
{
console.log('Txn Sent and hash is '+hash);
let userBalance = (web3.eth.getTransactionReceipt(hash));
console.log(userBalance);
userBalance.then(function(result) {
   console.log(result);
})

}
else
{
console.error(err);
}
});

Was ich jedoch aus dem Konsolenprotokoll bekomme, ist:

Txn Sent and hash is 0xab9a2265792203d787d0e08c7a808865b1d776d9a289d92ded2596c352b6e56c
Promise { <pending> }
null

Dies wird nicht auf Etherscan oder irgendwo im Hauptnetz aktualisiert. Ich bin ziemlich verwirrt, da mir nirgendwo gesagt wird, wo ich falsch liege. Weiß jemand, wie man es repariert?

Antworten (1)

Entfernen Sie einfach die "Von"-Adresse aus Ihrer rawTransaction und versuchen Sie es erneut. Lesen Sie den angegebenen Link. https://web3js.readthedocs.io/en/1.0/web3-eth.html#sensignedtransaction