<p>thx for linking one of my older pics from 2016 :-) meanwhile things had changed, especially the multisig was not clear enough. I attach an updated version here. I didn't have the time to put newest SegWit related things into the pic though...
Still happy to see other opinions ...</p>

<p><a href="https://i.sstatic.net/ELgkj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ELgkj.png" alt="output script"></a></p>

CC BY-SA 4.0
2018-09-10T17:14:24.510Z
Thanks man! I ended up figuring out most of the information I needed once I reviewed your picture. One other question I figured I'd ask. I know with the adoption of segregated witness there has been some degree of backwards compatibility with P2SH. Though, I have also heard people mention P2SH-P2WSH, P2WSH, P2WPKH, and P2SH-P2WPKH. Would you happen to know what differences there are in these versions, if any? Or perhaps a thread that might share the details? Regardless, thanks for this! PS: I'd love to upvote this too, but I don't have enough reputation yet :(
Mason Ticehurst
CC BY-SA 4.0
2018-09-10T18:07:30.603Z
I haven't seen any "prepared" stuff for easy usage, so my reference is currently here: https://en.bitcoinwiki.org/wiki/Segregated_Witness - with the links at the bottom to BIPs and the Wallet Development Guide.
pebwindkraft
CC BY-SA 4.0
2018-09-10T12:41:20.370Z
2018-09-10T12:41:20.370Z
pebwindkraft
<p>Bitcoin core just rolled out descriptor wallet implementation (PR <a href="https://github.com/bitcoin/bitcoin/pull/17261" rel="nofollow noreferrer">here</a>). Descriptors are modeled as functions. They take input a public key, and return the corresponding scriptPubKey,describing its spending conditions in engineer-readable format. For example, <code>sh(wpkh(03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556))</code> describes a P2SH-P2WPKH output with the specified public key.</p>
<p>You can refer to this <a href="https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md" rel="nofollow noreferrer">doc</a> for more details.
achow101 also gave a great <a href="https://www.youtube.com/watch?v=xC25NzIjzog" rel="nofollow noreferrer">talk</a> (15 min) to explain this idea in details.</p>

CC BY-SA 4.0
2020-08-19T05:27:24.230Z
2020-08-19T05:27:24.230Z
glowang
<p>I am working on a little script to breakdown the data inside coinbase transactions. This is largely to improve my understanding of legacy and SegWit transactions (Given coinbase transactions have less data than for example a multisig TX, it is easier for me to work through).</p>

<p>One thing I've noticed about these transactions is differences in the output scripts. The <a href="http://chainquery.com/bitcoin-api/decodescript" rel="nofollow noreferrer">Bitcoin RPC API</a> works pretty well in decoding them, though I would like to know how to do it without an external tool. 
I am aware that there are different types such as P2PKH, P2SH, and P2PK. However, what I do not know is how to differentiate them only given the raw hexadecimal representation.</p>

<p>For example <a href="https://www.blockchain.com/btc/tx/b3a02ec25b14b7fa845148beafa9b0248dcb05ca048e9262a31d7ce2405898ba" rel="nofollow noreferrer">this transaction</a> has two output scripts:</p>

<pre><code>76A91494155788E7233D7BEA9AA29FEB2ED37BC878C40B88AC
</code></pre>

<p>and</p>

<pre><code>6A24AA21A9ED7387872912D999B657F4146043675D84B9BBCF66AD5DEC8BCC14117E4FB6999E
</code></pre>

<p>The RPC API tells me the first one has the type <code>pubkeyhash</code> with a P2SH value of <code>3EstC3Hhe8zvNGP73oX9oDvo36sNCygjJi</code></p>

<p>The second output script appears to be random data which cannot be decoded. (I've also seen many coinbase transactions have one readable output and one or more output that cannot be decoded).</p>

<p>Another example, The genesis block <a href="https://blockchain.info/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b?format=json" rel="nofollow noreferrer">coinbase transaction</a> decoded by the RPC API has the type <code>pubkey</code> with this script:</p>

<pre><code>4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac
</code></pre>

<p>Question: How can I take this output script and determine the type of transaction and the assembly (OP script code) of it without external APIs?</p>

<p>Thank you!</p>

CC BY-SA 4.0
2018-09-09T23:34:37.223Z
As I was writing this I stumbled upon [this image](https://i.sstatic.net/ZekyJ.png) which implies that the scriptPubKeys follow a standardized format, can someone confirm it is accurate? Thanks again!
Mason Ticehurst
<bitcoin-core><script><raw-transaction><coinbase-transaction>
Differentiating Output Script (scriptPubKey) Types
Mason Ticehurst
# Differentiating Output Script (scriptPubKey) Types

(Asked by: username_0 on 2018-09-09)

I am working on a little script to breakdown the data inside coinbase transactions. This is largely to improve my understanding of legacy and SegWit transactions (Given coinbase transactions have less data than for example a multisig TX, it is easier for me to work through).

One thing I've noticed about these transactions is differences in the output scripts. The [Bitcoin RPC API](http://chainquery.com/bitcoin-api/decodescript) works pretty well in decoding them, though I would like to know how to do it without an external tool.
I am aware that there are different types such as P2PKH, P2SH, and P2PK. However, what I do not know is how to differentiate them only given the raw hexadecimal representation.

For example [this transaction](https://www.blockchain.com/btc/tx/b3a02ec25b14b7fa845148beafa9b0248dcb05ca048e9262a31d7ce2405898ba) has two output scripts:

```
76A91494155788E7233D7BEA9AA29FEB2ED37BC878C40B88AC

```

and

```
6A24AA21A9ED7387872912D999B657F4146043675D84B9BBCF66AD5DEC8BCC14117E4FB6999E

```

The RPC API tells me the first one has the type `pubkeyhash` with a P2SH value of `3EstC3Hhe8zvNGP73oX9oDvo36sNCygjJi`

The second output script appears to be random data which cannot be decoded. (I've also seen many coinbase transactions have one readable output and one or more output that cannot be decoded).

Another example, The genesis block [coinbase transaction](https://blockchain.info/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b?format=json) decoded by the RPC API has the type `pubkey` with this script:

```
4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

```

Question: How can I take this output script and determine the type of transaction and the assembly (OP script code) of it without external APIs?

Thank you!

**Tags:** bitcoin-core, script, raw-transaction, coinbase-transaction

> **Comments:**
> **username_0**: As I was writing this I stumbled upon [this image](https://i.sstatic.net/ZekyJ.png) which implies that the scriptPubKeys follow a standardized format, can someone confirm it is accurate? Thanks again!  

---

## 2 answers

### Answer by username_1 on 2018-09-10. Score: 2 | Accepted answer

thx for linking one of my older pics from 2016 :-) meanwhile things had changed, especially the multisig was not clear enough. I attach an updated version here. I didn't have the time to put newest SegWit related things into the pic though...
Still happy to see other opinions ...

[![output script](https://i.sstatic.net/ELgkj.png)](https://i.sstatic.net/ELgkj.png)

> **Comments:**
> **username_0**: Thanks man! I ended up figuring out most of the information I needed once I reviewed your picture. One other question I figured I'd ask. I know with the adoption of segregated witness there has been some degree of backwards compatibility with P2SH. Though, I have also heard people mention P2SH-P2WSH, P2WSH, P2WPKH, and P2SH-P2WPKH. Would you happen to know what differences there are in these versions, if any? Or perhaps a thread that might share the details? Regardless, thanks for this! PS: I'd love to upvote this too, but I don't have enough reputation yet :(  
> **username_1**: I haven't seen any "prepared" stuff for easy usage, so my reference is currently here: https://en.bitcoinwiki.org/wiki/Segregated_Witness - with the links at the bottom to BIPs and the Wallet Development Guide.  

---

### Answer by username_2 on 2020-08-19. Score: 2

Bitcoin core just rolled out descriptor wallet implementation (PR [here](https://github.com/bitcoin/bitcoin/pull/17261)). Descriptors are modeled as functions. They take input a public key, and return the corresponding scriptPubKey,describing its spending conditions in engineer-readable format. For example, `sh(wpkh(03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556))` describes a P2SH-P2WPKH output with the specified public key.

You can refer to this [doc](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md) for more details.
achow101 also gave a great [talk](https://www.youtube.com/watch?v=xC25NzIjzog) (15 min) to explain this idea in details.


---

