<p>A transaction is a segwit tx if at least one of the inputs contain a witness. Or if you are inspecting the raw tx then you check the 5th byte (the input count) and if it is <code>0x00</code> then it is a segwit tx. </p>

<p>Example:
<a href="https://blockchain.info/rawtx/574277fa92b5478bf00de8af305d2218fd1ff827ec8f5046f780d822131426ec?format=hex" rel="noreferrer">tx1</a></p>

<blockquote>
  <p>02000000<strong>05</strong>5f4e5315ffe854e75db92f8dda952a8db2f63b37838fca4c32bd4bb692fe7ea2000000006a47304402200ab62a9d1858dceeaa2101cda3f31b7bae60471c0355c54a6eae48f723555806022010d2aad6362a8c56ed66b0670ff84175f534f4f0995f8724a9b2a5fc89a2a4b4012102c424c2670a7aade9cf867576064013d02cc7669c418968993e73e6b25fc122bcfeffffff80cb1bfcde0f309490c717eca07f1353f121fb13e105...</p>
</blockquote>

<p>is not a segwit tx because the input count is <code>0x05</code> = 5</p>

<p><a href="https://blockchain.info/rawtx/5841ff53611ce55facbc57d18c0563576af9e5453f2dd1406f4324a0cee02a18?format=hex" rel="noreferrer">tx2</a></p>

<blockquote>
  <p>01000000<strong>00</strong>010106325bac2f2e7ca67fa46c8304fb3b747e5578df1eef0394349ce2cdd744f7f10100000000ffffffff02db355202000000001976a91489ea1263056ac068adba4844efb376a3a19635ad88ac43b72f07000000002...</p>
</blockquote>

<p>is a segwit tx because the input count is <code>0x00</code> = 0</p>

<p>Also:</p>

<ul>
<li>Transactions spending P2PKH inputs (address starting with 1) cannot
be segwit.</li>
<li>Transactions spending P2SH inputs will be segwit if they are nested
P2SH, otherwise not.</li>
<li>Transactions spending P2WPKH or P2WSH (starting with bc1) will be
segwit.</li>
</ul>

<p>In your example:</p>

<blockquote>
  <p>legacy -> P2SH</p>
</blockquote>

<p>This cannot be a segwit tx because it spends inputs from a legacy address</p>

<blockquote>
  <p>P2SH -> legacy</p>
</blockquote>

<p>This can be a segwit tx if the address is P2SH-P2WPKH or P2SH-P2WSH (nested segwit into P2SH). You wouldn't know if it is nested if it's not your's unless someone has already spent from it (in which case you inspect the spending tx).</p>

<blockquote>
  <p>bech32 -> legacy</p>
</blockquote>

<p>This is always a segwit tx</p>

CC BY-SA 4.0
2018-07-17T08:53:55.853Z
2018-07-17T08:53:55.853Z
Mike D
<p>Segwit Usage chart example : <a href="https://p2sh.info/dashboard/db/segwit-usage?orgId=1" rel="nofollow noreferrer">https://p2sh.info/dashboard/db/segwit-usage?orgId=1</a></p>

<p>I Would like to verify by checking tx if it's Segwit Transaction or not.</p>

<p>Is there any simple method to do this?</p>

<ul>
<li>legacy -> P2SH tx (Is this Segwit Transaction?)</li>
<li>P2SH -> legacy tx (Is this Segwit Transaction?)</li>
<li>bech32 -> legacy tx (Is this Segwit Transaction?)</li>
</ul>

<p>What about when many types of addresses are set as inputs and outputs?</p>

<transactions><segregated-witness><transaction-verification>
How to verify if it's Segwit Transaction or not?
bitcoinlearner
# How to verify if it's Segwit Transaction or not?

(Asked by: username_0 on 2018-07-17)

Segwit Usage chart example : <https://p2sh.info/dashboard/db/segwit-usage?orgId=1>

I Would like to verify by checking tx if it's Segwit Transaction or not.

Is there any simple method to do this?

* legacy -> P2SH tx (Is this Segwit Transaction?)
* P2SH -> legacy tx (Is this Segwit Transaction?)
* bech32 -> legacy tx (Is this Segwit Transaction?)

What about when many types of addresses are set as inputs and outputs?

**Tags:** transactions, segregated-witness, transaction-verification


---

## 1 answers

### Answer by username_1 on 2018-07-17. Score: 12 | Accepted answer

A transaction is a segwit tx if at least one of the inputs contain a witness. Or if you are inspecting the raw tx then you check the 5th byte (the input count) and if it is `0x00` then it is a segwit tx.

Example:
[tx1](https://blockchain.info/rawtx/574277fa92b5478bf00de8af305d2218fd1ff827ec8f5046f780d822131426ec?format=hex)

> 02000000**05**5f4e5315ffe854e75db92f8dda952a8db2f63b37838fca4c32bd4bb692fe7ea2000000006a47304402200ab62a9d1858dceeaa2101cda3f31b7bae60471c0355c54a6eae48f723555806022010d2aad6362a8c56ed66b0670ff84175f534f4f0995f8724a9b2a5fc89a2a4b4012102c424c2670a7aade9cf867576064013d02cc7669c418968993e73e6b25fc122bcfeffffff80cb1bfcde0f309490c717eca07f1353f121fb13e105...

is not a segwit tx because the input count is `0x05` = 5

[tx2](https://blockchain.info/rawtx/5841ff53611ce55facbc57d18c0563576af9e5453f2dd1406f4324a0cee02a18?format=hex)

> 01000000**00**010106325bac2f2e7ca67fa46c8304fb3b747e5578df1eef0394349ce2cdd744f7f10100000000ffffffff02db355202000000001976a91489ea1263056ac068adba4844efb376a3a19635ad88ac43b72f07000000002...

is a segwit tx because the input count is `0x00` = 0

Also:

* Transactions spending P2PKH inputs (address starting with 1) cannot
  be segwit.
* Transactions spending P2SH inputs will be segwit if they are nested
  P2SH, otherwise not.
* Transactions spending P2WPKH or P2WSH (starting with bc1) will be
  segwit.

In your example:

> legacy -> P2SH

This cannot be a segwit tx because it spends inputs from a legacy address

> P2SH -> legacy

This can be a segwit tx if the address is P2SH-P2WPKH or P2SH-P2WSH (nested segwit into P2SH). You wouldn't know if it is nested if it's not your's unless someone has already spent from it (in which case you inspect the spending tx).

> bech32 -> legacy

This is always a segwit tx


---

