When i have a rawTx ,such as this '15e2d20fae45d0c19a01177b48c79f1298a3343b2f4a4286ec27b7bdca0ae8cb070000e7fb71f07fb0a5ac3ec398f6ad47c10730d2145ff309bcdd04f855ac0200cc5febf12dc07f8e71b6f73d485ea733a77c3908d1b4e9bb0582579edb762756080000e7fb71f07fb0a5ac3ec398f6ad47c10730d2145ff309bddd04f855ac02e09143000056a48224cb245a4ede4774d377e94fd01d0a7eefff00000002030b35676fe47e2d12a184e7693640e8ab6ac1d3fa640b5da03ea1b9d1649e55383f6e58a330602fdc1f5dd028b4e0e948e1cbc78565a70027cfcb2d6a955412010d' how to get the txHash?

1 Answer 1

  1. Create a 32 byte generic hash of the raw tx
  2. Base58 encode it with the 'o' prefix

It would look something like this:

var rawHash = libsodium.crypto_generichash(32, rawTx);
var prefix = new Uint8Array([5, 116]); // 'o'
var merged = new Uint8Array(prefix.length + rawHash.length);
merged = merged.set(prefix);
merged = merged.set(rawHash, prefix.length);
var txHash = Bs58check.encode(merged);
  • Thanks, it's solve my problem Jul 22, 2019 at 3:16
  • @ruanqunfeng please accept the answer by clicking the checkmark when you are satisfied with the answer, tx!
    – Ezy
    Jul 26, 2019 at 11:06
  • This answer should include the actual result: Which txid/txHash does this raw hex actually match? Sep 26, 2020 at 8:07
  • Input (Carthagenet): "f711fa7cad51cf5c426b3d12c43e342374be29a2529241f823b8ae313bbcc0af6c000786cf9445307bd5092ebdccc891298c086676c58b0aedef64af5000c0e7fb0a0000ffc412ec694ac31e3a3af70433139129096577d000384978f679098ea5400da89879e1cd0061ba3df5ecdd7d3597d001db9fdb8dae190a943b8b55f48b57eda21b232b58b162962694ac62797e5d35ef8e7385100e" Result: "oo9tuhqPwjUZLPRcCmNrmUHECCMBMpdarbax11Ar5tzs5yiJCAJ"
    – Klassare
    Sep 26, 2020 at 10:01
  • 1
    This is what you're hashing: doc.tzalpha.net/api/p2p.html#operation-shell
    – Klassare
    Sep 26, 2020 at 10:02

Your Answer

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

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