<p>The output script (typically referred to as the scriptPubKey, but for some reason blockchain.com is calling it pkscript) tells you where to find the public key(s). It depends on the output script used. The public key(s) could be found in any of the three places.</p>
<p>In your example, the output script is a Pay to Script Hash (P2SH) script. This tells us that the script that is actually being executed is found in the input script (typically referred to as the scriptSIg, but for some reason blockchain.com is calling it sigscript). P2SH stipulates that the first item in the scriptSig is another script. In this example, there is only one item in the scriptSig, and that item is a script. This script is a Pay to Witness Pubkey Hash script (P2WPKH). This tells us that in the witness for this input, we should find a signature, followed by the public key. If you look at the witness section, you will see two items, the first is the signature, the second is the public key.</p>
<p>So in your example, the public key is found in the witness. However this is not always the case. It all depends on the various script types. If the output script were a Pay to Pubkey (P2PK) script, then the public key would be found in the output script. If it were a Pay to Public Key Hash (P2PKH) script, it would be found scriptSig. The address could also refer to a more complicated script that has multiple public keys, or no public keys at all. It all depends on the scripts.</p>

CC BY-SA 4.0
2020-12-29T19:55:24.333Z
Thank you. How can you tell which script type are the output and the input scripts? And where in the witness can the public key be found?
DUO Labs
CC BY-SA 4.0
2020-12-29T20:21:13.030Z
There are a set of standard script templates so you can just match the scripts against the templates to determine the script type. Most of these templates also match to an address type. For example, addresses beginning with a 3 correspond to P2SH output scripts. In your example, the public key is `03ac7d8d505d09082033ec04ce1e6dd5ff3e1bf4c2788f6588da38f39460772210`. It's the second thing listed in the witness section.
Ava Chow
CC BY-SA 4.0
2020-12-29T18:53:01.500Z
2020-12-29T18:53:01.500Z
Ava Chow
<p>Let's use <a href="https://www.blockchain.com/btc/tx/aea93ecfbe266143a659c63da58dc019df57a28bc38adc4f4906070448aa3bb9" rel="nofollow noreferrer">this transaction</a> as an example. In the transcation, address 3GGoy8NoCF62TCAPGidWMU3u1ZrgwmasFt has a pkscript, a sigscript and a witness. It is possible to use any one of these, or some combination of them to retrieve that address' public key?</p>

<public-key>
Retrieving an addresses' public key from Pkscript/sigscript/witness
DUO Labs
# Retrieving an addresses' public key from Pkscript/sigscript/witness

(Asked by: username_0 on 2020-12-29)

Let's use [this transaction](https://www.blockchain.com/btc/tx/aea93ecfbe266143a659c63da58dc019df57a28bc38adc4f4906070448aa3bb9) as an example. In the transcation, address 3GGoy8NoCF62TCAPGidWMU3u1ZrgwmasFt has a pkscript, a sigscript and a witness. It is possible to use any one of these, or some combination of them to retrieve that address' public key?

**Tags:** public-key


---

## 1 answers

### Answer by username_1 on 2020-12-29. Score: 0 | Accepted answer

The output script (typically referred to as the scriptPubKey, but for some reason blockchain.com is calling it pkscript) tells you where to find the public key(s). It depends on the output script used. The public key(s) could be found in any of the three places.

In your example, the output script is a Pay to Script Hash (P2SH) script. This tells us that the script that is actually being executed is found in the input script (typically referred to as the scriptSIg, but for some reason blockchain.com is calling it sigscript). P2SH stipulates that the first item in the scriptSig is another script. In this example, there is only one item in the scriptSig, and that item is a script. This script is a Pay to Witness Pubkey Hash script (P2WPKH). This tells us that in the witness for this input, we should find a signature, followed by the public key. If you look at the witness section, you will see two items, the first is the signature, the second is the public key.

So in your example, the public key is found in the witness. However this is not always the case. It all depends on the various script types. If the output script were a Pay to Pubkey (P2PK) script, then the public key would be found in the output script. If it were a Pay to Public Key Hash (P2PKH) script, it would be found scriptSig. The address could also refer to a more complicated script that has multiple public keys, or no public keys at all. It all depends on the scripts.

> **Comments:**
> **username_0**: Thank you. How can you tell which script type are the output and the input scripts? And where in the witness can the public key be found?  
> **username_1**: There are a set of standard script templates so you can just match the scripts against the templates to determine the script type. Most of these templates also match to an address type. For example, addresses beginning with a 3 correspond to P2SH output scripts. In your example, the public key is `03ac7d8d505d09082033ec04ce1e6dd5ff3e1bf4c2788f6588da38f39460772210`. It's the second thing listed in the witness section.  

---

