0

Been writing a bitcoin library from scratch, which eventually involves calculating transaction IDs.

Version 1 transactions work fine when their hex data is being SHA256'd twice and then reversed.

Version 2 transactions ids don't seem to work that way, according to data I found on block explorers. The IDs I generate never match.

Why?

Vojtěch Strnad
  • 5,623
  • 1
  • 8
  • 31
RooSoft
  • 127
  • 6
  • 2
    The algorithm for computing txids is the same for version 1 and version 2. But is it possible that the v2 transactions you're looking at are segwit transactions? Because those do have a different hashing algorithm, see BIP141 and BIP144. – Pieter Wuille Nov 13 '22 at 00:01
  • Take any V1 transaction in mempool.space, click `Transaction hex`, and then double-sha256 what you get, then reverse it... matches the ID in the URL. The same doesn't seem to apply for any v2 transaction... no idea why. – RooSoft Nov 13 '22 at 00:49
  • 2
    Recent transactions are likely segwit transactions. For those you need to drop the witness before hashing to obtain the txid. It has nothing to do with v1 or v2 however; either can be segwit or not. – Pieter Wuille Nov 13 '22 at 01:08
  • Invaluable information, Pieter... thank you so much! Will take a good look a that. – RooSoft Nov 13 '22 at 02:01
  • Sure does, @RedGrittyBrick ! – RooSoft Nov 13 '22 at 18:45

0 Answers0