I am trying to send ethers from one address to another address on the ropsten network but I get the message "undefined".
Here is my code:
web3.eth.getTransactionCount(account1, (error, txCount) => {
//build a transaction object
const txObject = {
nonce: web3.utils.toHex(txCount),
to: account2,
value: web3.utils.toHex(web3.utils.toWei('0.3', 'ether')),
gasLimit: web3.utils.toHex(21000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
}
//console.log(txObject)
//sign transaction with private key of sender
const tx = new Tx(txObject)
tx.sign(privateKey1)
//serialize the transaction
const serializedTransaction = tx.serialize()
const raw ='0x' + serializedTransaction.toString('hex')
//broadcast transaction to the network
web3.eth.sendSignedTransaction(raw, (error, txHash) => {
console.log(txHash)
})
})
Thank you for your help
Take care
Pierre
error
too please.