let tx = new Tx(rawTransaction);
tx.sign(privateKey);
let serializedTx = '0x' + tx.serialize().toString('hex');
// I need to get the transaction hash here
let sender = web3.eth.sendSignedTransaction(serializedTx).once('transactionHash', async hash => {
console.log(hash)
})
You might want to try this: https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#signtransaction
You might want to try this: https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#signtransaction
tq for you reply, but I only have privateKey, signtransaction must need password for account.
Managing plaintext private keys is a bad idea, but if you must, then try with https://web3js.readthedocs.io/en/1.0/web3-eth.html#signtransaction.
@dk-lan This will get you the txHash of your transaction before sending it.
const txHash = await web3.utils.sha3(serializedTx);
@dev1644
thanks , the way is correctly
@dev1644, hi I've tried wtih online hashing such as https://emn178.github.io/online-tools/keccak_256.html but the result is different. Maybe web3 has modified few input data or something? Thanks for your help so much bro.
Most helpful comment
@dk-lan This will get you the txHash of your transaction before sending it.
const txHash = await web3.utils.sha3(serializedTx);