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:

enter image description here

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 <signature1> <1 <pubkey1> <pubkey2> 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).

2
  • Nitpick: there's a checksum for the address in P2PK/P2PKH/P2SH. en.bitcoin.it/wiki/…
    – Nick ODell
    Commented Nov 12, 2016 at 17:31
  • Yes, thank you. To clarify for anyone reading this, it should be base58('00' + hash160 + checksum)
    – inersha
    Commented Nov 12, 2016 at 19:22

2 Answers 2

6

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.

2
  • Still ongoing? I want to know the latest trend. Is P2SH wrapper the defacto standard now? Seems bit142 is still deferred. github.com/bitcoin/bips/blob/master/bip-0142.mediawiki
    – zono
    Commented Jun 30, 2017 at 16:06
  • BIP173 replaces it. It will take a long time to be adopted, however, so initially I expect segwit transfers to use the P2SH wrapper. Commented Jun 30, 2017 at 16:12
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.