Can anyone help me fix this problem? I get 'txHash: undefined' error in terminal
var Tx = require('ethereumjs-tx').Transaction
const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io/.....')
const account1 = '0x4e8143b70aC257BC26......................'
const account2 = '0x7184a5934B9B36E210......................'
const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_1, 'hex')
const privateKey2 = Buffer.from(process.env.PRIVATE_KEY_2, 'hex')
web3.eth.getTransactionCount(account2, (err, txCount) => {
// Build a transaction
const txObject = {
nonce: web3.utils.toHex(txCount),
to: account1,
value: web3.utils.toHex(web3.utils.toWei('1', 'ether')),
gasLimit: web3.utils.toHex(21000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
}
// sign a transaction
const tx = new Tx(txObject)
tx.sign(privateKey2)
const serializedTransaction = tx.serialize()
const raw = '0x' + serializedTransaction.toString('hex')
// Broadcast the transacation
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
console.log('txHash:' , txHash)
})
})