2

Is it possible to get the transaction hash before sending the transaction? Just because it sometimes takes really long until the callback with the txHash comes in.

const transaction = new Tx(txData);
transaction.sign(privateKey);
const serializedTx = transaction.serialize().toString('hex');
web3.eth.sendSignedTransaction('0x' + serializedTx, cb);

I need to save the transaction hash in my DB. The best way would be to store it there ASAP. So, is there a way to calculate the Txhash BEFORE sending the transaction with sendSignedTransaction?

1 Answer 1

4

ethereumjs-tx should do the trick. Something like this:

new EthereumTx(serializedTx).hash()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.