<p>I assembled this picure with the top ten PKscripts I found somewhere on a webpage... don't find the link. I'd also want to extend it by segwit outputs. I can share the "graphml" file if desired.</p>

<p><a href="https://i.sstatic.net/ELgkj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ELgkj.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2016-11-12T18:39:55.827Z
2018-09-24T12:59:12.403Z
2018-09-24T12:59:12.403Z
pebwindkraft
<p>There currently exists no native address format for witness outputs, so the answer for P2WPKH and P2WSH is simply: you can't, and shouldn't. If you convert the 20-byte hash inside a P2WPKH output to a 1xxxxxx, and show the result, people may think that is an address more money can be sent to. However, that would result in a P2PKH output, which a pure segwit wallet may not understand.</p>

<p>However, most segwit outputs initially will use the P2SH wrapper (resulting in P2SH-P2WPKH or P2SH-P2WSH programs), which just look like (and behave like) P2SH addresses.</p>

<p>A new native segwit address format is proposed in <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki</a>. That can only be used when both the receiver and sender software support it however.</p>

CC BY-SA 3.0
2017-06-30T16:06:08.697Z
Still ongoing? I want to know the latest trend. Is P2SH wrapper the defacto standard now? Seems bit142 is still deferred. https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki
zono
CC BY-SA 3.0
2017-06-30T16:12:51.110Z
BIP173 replaces it. It will take a long time to be adopted, however, so initially I expect segwit transfers to use the P2SH wrapper.
Pieter Wuille
CC BY-SA 3.0
2016-11-12T18:11:42.093Z
2017-06-30T16:16:01.333Z
2017-06-30T16:16:01.333Z
Pieter Wuille
<p>I'm running through raw transaction data, and I'd like to be able to gather addresses (where possible).</p>

<p>So far, I've made this diagram to help me understand when it's possible to figure out addresses from the <code>scriptPubKey</code> of each <strong>output</strong>:</p>

<p><a href="https://i.sstatic.net/P7TvJ.png" rel="noreferrer"><img src="https://i.sstatic.net/P7TvJ.png" alt="enter image description here"></a></p>

<p>However, as you can see, I'm not sure how I can work out an address from a <strong>P2WSH</strong>.</p>

<p>Is it possible to get addresses from the <code>scriptPubKey</code> alone, or can I only get them when the witness is revealed when the output has been spent?  (as shown here):</p>

<pre><code>witness:      0 &lt;signature1&gt; &lt;1 &lt;pubkey1&gt; &lt;pubkey2&gt; 2 CHECKMULTISIG&gt;
scriptSig:    (empty)
scriptPubKey: 0 &lt;32-byte-hash&gt;
              (0x0020{32-byte-hash})
</code></pre>

<hr>

<p><strong>EDIT:</strong> Also, please let me know if you notice that any of my pattern matching in this diagram is incorrect (or if I'm missing any patterns that allow me to find out more addresses).</p>

CC BY-SA 3.0
2016-11-12T17:31:23.657Z
Nitpick: there's a checksum for the address in P2PK/P2PKH/P2SH. https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
Nick ODell
CC BY-SA 3.0
2016-11-12T19:22:34.717Z
Yes, thank you. To clarify for anyone reading this, it should be `base58('00' + hash160 + checksum)`
inersha
<address><script><segregated-witness>
How to get addresses from scriptPubKey in segwit transactions?
inersha
# How to get addresses from scriptPubKey in segwit transactions?

(Asked by: username_0 on 2016-11-12)

I'm running through raw transaction data, and I'd like to be able to gather addresses (where possible).
So far, I've made this diagram to help me understand when it's possible to figure out addresses from the scriptPubKey of each output:

However, as you can see, I'm not sure how I can work out an address from a P2WSH.
Is it possible to get addresses from the scriptPubKey alone, or can I only get them when the witness is revealed when the output has been spent?  (as shown here):
witness:      0  <1   2 CHECKMULTISIG>
scriptSig:    (empty)
scriptPubKey: 0 <32-byte-hash>
              (0x0020{32-byte-hash})


EDIT: Also, please let me know if you notice that any of my pattern matching in this diagram is incorrect (or if I'm missing any patterns that allow me to find out more addresses).

**Tags:** address, script, segregated-witness

> **Comments:**
> **username_1**: Nitpick: there's a checksum for the address in P2PK/P2PKH/P2SH. https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses  
> **username_0**: Yes, thank you. To clarify for anyone reading this, it should be `base58('00' + hash160 + checksum)`  

---

## 2 answers

### Answer by username_3 on 2016-11-12. Score: 6 | Accepted answer

There currently exists no native address format for witness outputs, so the answer for P2WPKH and P2WSH is simply: you can't, and shouldn't. If you convert the 20-byte hash inside a P2WPKH output to a 1xxxxxx, and show the result, people may think that is an address more money can be sent to. However, that would result in a P2PKH output, which a pure segwit wallet may not understand.

However, most segwit outputs initially will use the P2SH wrapper (resulting in P2SH-P2WPKH or P2SH-P2WSH programs), which just look like (and behave like) P2SH addresses.

A new native segwit address format is proposed in <https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki>. That can only be used when both the receiver and sender software support it however.

> **Comments:**
> **username_4**: Still ongoing? I want to know the latest trend. Is P2SH wrapper the defacto standard now? Seems bit142 is still deferred. https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki  
> **username_3**: BIP173 replaces it. It will take a long time to be adopted, however, so initially I expect segwit transfers to use the P2SH wrapper.  

---

### Answer by username_2 on 2016-11-12. Score: 2

I assembled this picure with the top ten PKscripts I found somewhere on a webpage... don't find the link. I'd also want to extend it by segwit outputs. I can share the "graphml" file if desired.

[![enter image description here](https://i.sstatic.net/ELgkj.png)](https://i.sstatic.net/ELgkj.png)


---

