<blockquote>
  <p>How am I suppose to get the txid of this transaction?</p>
</blockquote>

<p>The same way you get the txid of any other transaction, by hashing it (unless it is segwit). Note that the transaction you linked to is not a segwit transaction, so you can just take its hash.</p>

<p>If the transaction is a segwit transaction (as indicated by the marker and flag bytes of <code>0x0001</code> following the version bytes), then you need to only hash the parts that are non-segwit. Specifically, you drop all of the segwit parts (so the marker and flag and any witnesses which can be found between the last output and the locktime), and hash what is left. This is described in <a href="https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki" rel="nofollow noreferrer">BIP 144</a>.</p>

<blockquote>
  <p>And how is it different from a regular (without multisig) one?</p>
</blockquote>

<p>There isn't.</p>

CC BY-SA 4.0
2018-10-24T18:07:56.720Z
Thank you, I will double-check my code. I tested it on a full block (about 2k txs) and the only times the txid didn't match (20 times) was when a "OP_0" appeared in one of the inputs scripts.
Kevin P
CC BY-SA 4.0
2018-10-24T18:11:38.997Z
Also, I don't simply hash the transaction as it is. I parse it, store all its elements in a data structure, and then append them back and hash them (I use the tx id as an error check).
Kevin P
CC BY-SA 4.0
2018-10-24T19:30:50.093Z
OP_0 is used in segwit transactions too, so that may be your problem.
Ava Chow
CC BY-SA 4.0
2018-10-25T06:29:05.760Z
Problem solved: I had a problem with my "varint" function... Thank you!
Kevin P
CC BY-SA 4.0
2022-11-25T13:49:17.557Z
FWIW, got the same symptom in 2022 but from a different underlying problem. OP_PUSHDATA1 failed to encode its opcode, 0x4c, in the transaction. Obviously, the same problem occured with OP_PUSHDATA2 and OP_PUSHDATA4.
RooSoft
CC BY-SA 4.0
2018-10-24T17:33:05.390Z
2018-10-24T17:33:05.390Z
Ava Chow
<p>I am able to get the tx id (or transaction hash) of almost any transaction but the one where the script starts with an "OP_O" (which is, I think, the null dummy introduced here <a href="https://github.com/bitcoin/bitcoin/pull/3843" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/pull/3843</a>)</p>

<p>For example:</p>

<p><a href="https://www.blockchain.com/btc/tx/97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee" rel="nofollow noreferrer">https://www.blockchain.com/btc/tx/97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee</a></p>

<p>How am I suppose to get the txid of this transaction? And how is it different from a regular (without multisig) one?</p>

<hash><multi-signature><transaction-id>
Getting transaction id from raw transaction of a multisig address
Kevin P
# Getting transaction id from raw transaction of a multisig address

(Asked by: username_0 on 2018-10-24)

I am able to get the tx id (or transaction hash) of almost any transaction but the one where the script starts with an "OP\_O" (which is, I think, the null dummy introduced here <https://github.com/bitcoin/bitcoin/pull/3843>)

For example:

<https://www.blockchain.com/btc/tx/97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee>

How am I suppose to get the txid of this transaction? And how is it different from a regular (without multisig) one?

**Tags:** hash, multi-signature, transaction-id


---

## 1 answers

### Answer by username_1 on 2018-10-24. Score: 1 | Accepted answer

> How am I suppose to get the txid of this transaction?

The same way you get the txid of any other transaction, by hashing it (unless it is segwit). Note that the transaction you linked to is not a segwit transaction, so you can just take its hash.

If the transaction is a segwit transaction (as indicated by the marker and flag bytes of `0x0001` following the version bytes), then you need to only hash the parts that are non-segwit. Specifically, you drop all of the segwit parts (so the marker and flag and any witnesses which can be found between the last output and the locktime), and hash what is left. This is described in [BIP 144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki).

> And how is it different from a regular (without multisig) one?

There isn't.

> **Comments:**
> **username_0**: Thank you, I will double-check my code. I tested it on a full block (about 2k txs) and the only times the txid didn't match (20 times) was when a "OP_0" appeared in one of the inputs scripts.  
> **username_0**: Also, I don't simply hash the transaction as it is. I parse it, store all its elements in a data structure, and then append them back and hash them (I use the tx id as an error check).  
> **username_1**: OP_0 is used in segwit transactions too, so that may be your problem.  
> **username_0**: Problem solved: I had a problem with my "varint" function... Thank you!  
> **username_2**: FWIW, got the same symptom in 2022 but from a different underlying problem. OP_PUSHDATA1 failed to encode its opcode, 0x4c, in the transaction. Obviously, the same problem occured with OP_PUSHDATA2 and OP_PUSHDATA4.  

---

