0

My transaction fails, so it doesn't give me a hash that I would be able to use to debug it when I call ethers.wallet.sendTransaction(tx). The tx object has 4 fields: from, to, data, value. If I do

    const txSigned = await wallet.signTransaction({
      ...tx,
      gasPrice,
      gasLimit: BigNumber.from("2000000"),
    });
    console.log("Tx hash wrong:", ethers.utils.keccak256(txSigned));

Then this value that emerges does not in fact match the correct transaction hash. Does anyone know how I can use ethers to get such a transaction hash, to debug the failed transaction? I could manually go to the local chain itself and view the failed tx hash, but that can't be manipulated inside my code itself.

2 Answers 2

1

You calculate the hash correctly - it is the keccak256 of a signed transaction. Something wrong is somewhere else.

Try to send that signed tx via provider.sendTransaction, as signer.sendTransaction could recalculate gas or smth. else, then the hash will be different.

Or, when manually signing the transaction you miss the chainId field and signing via the Wallet it adds the chainId.

1
  • I think there's a very specific set of fields needed that are signed, and I don't have all of those, and the sign transaction function doesn't give me those Commented Nov 2, 2022 at 20:04
0

There is no way to get transaction hash before the transaction completion. Because to generate transaction hash some fields are required which not available because before transaction completion

1
  • Like what? I don't think this is the case. Commented Nov 2, 2022 at 20:03

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.