1

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?

3

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, privacy policy and cookie policy

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