6

I searched around for an answer to this question, however couldn't find one. So let's assume we've a raw ethereum transaction and before broadcasting we'd like to know the transaction hash. Is it possible to find out the hash before it's being broadcasted (i.e. via eth_sendRawTransaction RPC method).

For instance for raw transaction hex:

0xf86c258502540be40083035b609482e041e84074fc5f5947d4d27e3c44f824b7a1a187b1a2bc2ec500008078a04a7db627266fa9a4116e3f6b33f5d245db40983234eb356261f36808909d2848a0166fa098a2ce3bda87af6000ed0083e3bf7cc31c6686b670bd85cbc6da2d6e85

I get this transaction: https://kovan.etherscan.io/tx/0x58e5a0fc7fbc849eddc100d44e86276168a8c7baaa5604e44ba6f5eb8ba1b7eb

Is it possible to decode raw transaction so that this hash is known before hand? Note that I am storing private keys outside of applications such as geth/parity.

  • 1
    Please correct me if I am wrong: after mining transaction you receive the same transaction hash as after getting keccak256 hash from raw tx? My tests show that keccak256 hash of raw signed tx is NOT equal to transactionHash generated by ethereum while mining. I would appreciate if somebody could tell me how exactly transactionHashes are generated as there is no iformation available even in yellow paper of ethereum. – user3184743 Jan 7 '18 at 17:36
11

Ok, so asked it a couple of minutes too soon. As the name implies it's a hash, hash of what? Hash of your raw hex in example:

0xf86c258502540be40083035b609482e041e84074fc5f5947d4d27e3c44f824b7a1a187b1a2bc2ec500008078a04a7db627266fa9a4116e3f6b33f5d245db40983234eb356261f36808909d2848a0166fa098a2ce3bda87af6000ed0083e3bf7cc31c6686b670bd85cbc6da2d6e85

Hashed using keccak256 (for instance can be found here: https://wiki.parity.io/JSONRPC-web3-module#web3_sha3): and the result as expected is:

0x58e5a0fc7fbc849eddc100d44e86276168a8c7baaa5604e44ba6f5eb8ba1b7eb

So ended up being a short rhetorical question. However if someone has similar question... hope this helps!

  • It is not a stupid question. In Bitcoin, a hash of the transaction is presented in the opposite endianness so even though you may think that there is only one way to represent a hash as a string, that is not the case. – Thorkil Værge Oct 14 '18 at 18:22
  • Is this a hash of the signed transaction or the unsigned transaction? For the purposes of validating transaction data, can I derive a transaction hash just from the transaction data itself without knowledge of the private key? – Albert Renshaw Oct 27 at 20:26
  • This is hash from the signed raw hex. I don't imagine you could derive it from unsigned data, since unsigned transaction has different "raw" representation and as such the hash of this would be also different than the hash of signed hex. – Kristaps Oct 28 at 21:59

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.