<p>I have summarized some popular payment types in my book <a href="http://rosenbaum.se/book/grokking-bitcoin-10.html#recap-of-payment-types" rel="nofollow noreferrer">"Grokking Bitcoin"</a>. There are 6 standard payment types:</p>

<p><strong>p2pkh</strong>: Pay-to-public-key-hash. The public key is the second (last) item in scriptSig.</p>

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

<p><br></p>

<p><strong>p2sh</strong>: Pay-to-script-hash. The public key(s) are packed into the redeem script which is the last item in scriptSig. To get them you need to parse the redeem script (which itself is a script) and look for key patterns (push of 33 bytes).</p>

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

<p><br></p>

<p><strong>p2wpkh</strong>: Pay-to-witness-public-key-hash. The public key is found in the witness of the transaction. More specifically in the second item of the witness field with the same index as the input you're investigating (the witness contains one witness field for each input. There's only one witness field in this example, because there's only one input).</p>

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

<p><br></p>

<p><strong>p2wsh</strong>: Pay-to-witness-script-hash. The public key(s) are packed into the witness script which is the last item in the input's corresponding witness field. To get them you need to parse the witness script (which itself is a script) and look for key patterns (push of 33 bytes). </p>

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

<p><br></p>

<p><strong>p2wpkh nested in p2sh</strong>: The pubkey is in the same place as in p2wpkh.</p>

<p><a href="https://i.sstatic.net/WRLy3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WRLy3.png" alt="p2wpkh-nested"></a></p>

<p><br></p>

<p><strong>p2wsh nested in p2sh</strong>: The pubkey is in the same place as in p2wsh.</p>

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

<p>I hope this helps</p>

CC BY-SA 4.0
2020-03-27T23:23:19.670Z
great answer. thank you. helpful for your book would also be linking to example transactions of each case. thanks a lot again
brocard
CC BY-SA 4.0
2020-03-28T05:47:32.717Z
i needed this to build this tool:
https://free-online-app.com/bitcoin-2-ethereum-address-converter/
and this tool:
https://free-online-app.com/bitcoin-ethereum-private-key-converter/

maybe you take a look and find some error or stuff i completely missed out on. thanks
brocard
CC BY-SA 4.0
2020-03-30T08:39:22.487Z
@brocard could you mark my answer as accepted if you think it answers your question. Thanks.
Kalle Rosenbaum
CC BY-SA 4.0
2020-03-30T09:38:40.947Z
i got not enough rep to rate. gonna do it when i have enough!! your answer was very helpful!
brocard
CC BY-SA 4.0
2020-03-27T07:16:03.163Z
2020-03-27T07:23:39.850Z
2020-03-27T07:23:39.850Z
Kalle Rosenbaum
<p>i need to retrieve public key of transaction sender.</p>

<p>now i know there are 03 compressed pubkeys and 04 uncompressed ones.</p>

<p>but how is this working with segwit and multisig addresses?</p>

<p>can you please point me to what possible combinations there could be, so i am ready for any possible trnasaction to always get the right key?</p>

<p>thanks a lot!</p>

<transactions><segregated-witness><public-key><raw-transaction>
getting public key from any raw transaction - what to take care of?
brocard
# getting public key from any raw transaction - what to take care of?

(Asked by: username_0 on 2020-03-27)

i need to retrieve public key of transaction sender.

now i know there are 03 compressed pubkeys and 04 uncompressed ones.

but how is this working with segwit and multisig addresses?

can you please point me to what possible combinations there could be, so i am ready for any possible trnasaction to always get the right key?

thanks a lot!

**Tags:** transactions, segregated-witness, public-key, raw-transaction


---

## 1 answers

### Answer by username_1 on 2020-03-27. Score: 0 | Accepted answer

I have summarized some popular payment types in my book ["Grokking Bitcoin"](http://rosenbaum.se/book/grokking-bitcoin-10.html#recap-of-payment-types). There are 6 standard payment types:

**p2pkh**: Pay-to-public-key-hash. The public key is the second (last) item in scriptSig.

[![p2pkh](https://i.sstatic.net/jqAVh.png)](https://i.sstatic.net/jqAVh.png)

**p2sh**: Pay-to-script-hash. The public key(s) are packed into the redeem script which is the last item in scriptSig. To get them you need to parse the redeem script (which itself is a script) and look for key patterns (push of 33 bytes).

[![p2sh](https://i.sstatic.net/ZDkaS.png)](https://i.sstatic.net/ZDkaS.png)

**p2wpkh**: Pay-to-witness-public-key-hash. The public key is found in the witness of the transaction. More specifically in the second item of the witness field with the same index as the input you're investigating (the witness contains one witness field for each input. There's only one witness field in this example, because there's only one input).

[![p2wpkh](https://i.sstatic.net/RV9Wu.png)](https://i.sstatic.net/RV9Wu.png)

**p2wsh**: Pay-to-witness-script-hash. The public key(s) are packed into the witness script which is the last item in the input's corresponding witness field. To get them you need to parse the witness script (which itself is a script) and look for key patterns (push of 33 bytes).

[![p2wsh](https://i.sstatic.net/OJ6oO.png)](https://i.sstatic.net/OJ6oO.png)

**p2wpkh nested in p2sh**: The pubkey is in the same place as in p2wpkh.

[![p2wpkh-nested](https://i.sstatic.net/WRLy3.png)](https://i.sstatic.net/WRLy3.png)

**p2wsh nested in p2sh**: The pubkey is in the same place as in p2wsh.

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

I hope this helps

> **Comments:**
> **username_0**: great answer. thank you. helpful for your book would also be linking to example transactions of each case. thanks a lot again  
> **username_0**: i needed this to build this tool: https://free-online-app.com/bitcoin-2-ethereum-address-converter/ and this tool: https://free-online-app.com/bitcoin-ethereum-private-key-converter/  maybe you take a look and find some error or stuff i completely missed out on. thanks  
> **username_1**: @username_0 could you mark my answer as accepted if you think it answers your question. Thanks.  
> **username_0**: i got not enough rep to rate. gonna do it when i have enough!! your answer was very helpful!  

---

