How is a Transaction ID generated & when does it change? (with a new sequence ID?)

8

I'm creating a non-mainstream client that processes and validates Bitcoin transactions and need to track transactions in my database.

  • How is the TxID generated and when does it change?

Specifically, since sequence is intended to update a transaction, and if the transactions hash were to change I would assume the txid hash would change s well.

When I look at this image of a Tx, it appears that the txid is marked as TxIn (VI)

  • Is it possible or useful for a script to verify the TxID and signature hash?

goodguys_activate

Posted 2012-12-20T22:20:27.780

Reputation: 11 898

Answers

7

TxID is just a SHA256 hash of binary transation data, so it changes upon any modification of transaction. Therefore, one cannot include verification of TxID in the script in same transaction (if I correctly understood what you want to achieve).

aland

Posted 2012-12-20T22:20:27.780

Reputation: 1 338

@PieterWuille does generating txid mean you hash the scriptSif & scriptPubKey as well ?Haddar Macdasi 2015-04-29T16:09:48.000

Yes, any change at all, including any non-sensical or irrelevant change, will change the transaction id.Pieter Wuille 2015-04-30T05:58:58.143

Maybe I'm confused... Where is the TxID?goodguys_activate 2012-12-20T23:08:18.113

3The transaction id is used to refer to a transaction; it is not part of it.Pieter Wuille 2012-12-20T23:20:07.543

@PieterWuille Is the TxID a simple Sha256 hash of the tx data in it's entirety? Does that mean the TxID changes if the sequence # changes? How should I track revisions (new sequences) of the same tx?goodguys_activate 2012-12-21T06:17:47.523

@makerofthings7 Yes, it is just hash of all data. If tx data changes then it is NOT the same tx.aland 2012-12-21T08:13:01.847

1It is a double-SHA256 of the serialized transaction. So indeed, the sequence number is part of. Changing the sequence number means you get a new transaction, but there is some (currently disabled) code in the reference client which can detect one transaction as a 'new version' of another, and replace it.Pieter Wuille 2012-12-21T10:39:35.917