<p>You can use the <code>getaddressinfo</code> RPC command in the latest version of bitcoin core to get the hex encoded script for that address. But note that because you were able to get a private key, I assume this is a P2SH wrapped segwit address, which means the script is just an <code>OP_0</code> opcode followed by the hash160 of the public key corresponding to that private key.</p>

CC BY-SA 3.0
2018-04-08T07:06:04.743Z
I use bitcoin core 0.16.0 the latest version. But when I use `getaddressinfo` I got "Method not found"
LF-DevJourney
CC BY-SA 3.0
2018-04-08T07:18:49.790Z
Oh apologies, I thought it had made it into 0.16, it looks like its still only on the master dev branch. In that case you might have to create the script yourself using the OP_0 + hash160 approach I mentioned, see here for more info: https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address
meshcollider
CC BY-SA 3.0
2018-04-08T07:21:11.150Z
Use `validateaddress` instead (the parts of `validateaddress` that give address information are moved to a new `getaddressinfo` command for the next major version, 0.17).
Ava Chow
CC BY-SA 3.0
2018-04-08T08:18:07.220Z
@AndrewChow does validateaddress output the script? I wasn't sure if it did or if that was new functionality
meshcollider
CC BY-SA 3.0
2018-04-08T12:51:35.847Z
@MeshCollider It does. The RPC was just split up in two in master, but no new functionality was added.
Pieter Wuille
CC BY-SA 3.0
2018-04-08T06:29:49.937Z
2018-04-08T06:29:49.937Z
meshcollider
<p><em>(For additional detail):</em></p>

<p>It is a <code>P2SH-P2WPKH</code> (Pay to witness public key hash wrapped in a pay to script hash). To create this address for mainnet:</p>

<ol>
<li>Create Witness <code>PKH</code>:</li>
</ol>

<p><code>PKH = OP_0 0x14 RIPEMD160(SHA256(compressed public key))</code><br>
<code>0x14</code> is number of bytes</p>

<ol start="2">
<li>Create <code>P2SH</code>:</li>
</ol>

<p><code>BASE58CHECK(0x05 PKH)</code><br>
<code>0x05</code> is the mainnet <code>P2SH</code> prefix</p>

CC BY-SA 4.0
2018-08-13T14:57:50.443Z
2018-08-13T14:57:50.443Z
JBaczuk
<p>I'm trying to generate the address <code>38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa</code> in my bitcoin core wallet with code.</p>

<p>First, I dump the private key from the address, then I calculate the address from the private key. As the address is start form <code>m</code>, which is of P2SH <a href="https://en.bitcoin.it/wiki/Address" rel="nofollow noreferrer">bitcoin address type</a>. And the P2SH address is constructed as</p>

<pre><code>base58-encode: [one-byte version][20-byte hash][4-byte checksum]
</code></pre>

<p>Here I don't know what the script used to calculate the <code>[20-byte hash]</code> in the bitcoin core wallet?</p>

<bitcoin-core><wallet><address><script><p2sh>
What redeem script is used in bitcoin core wallet when generate the address?
LF-DevJourney
# What redeem script is used in bitcoin core wallet when generate the address?

(Asked by: username_0 on 2018-04-08)

I'm trying to generate the address 38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa in my bitcoin core wallet with code.
First, I dump the private key from the address, then I calculate the address from the private key. As the address is start form m, which is of P2SH bitcoin address type. And the P2SH address is constructed as
base58-encode: [one-byte version][20-byte hash][4-byte checksum]

Here I don't know what the script used to calculate the [20-byte hash] in the bitcoin core wallet?

**Tags:** bitcoin-core, wallet, address, script, p2sh


---

## 2 answers

### Answer by username_1 on 2018-04-08. Score: 2 | Accepted answer

You can use the `getaddressinfo` RPC command in the latest version of bitcoin core to get the hex encoded script for that address. But note that because you were able to get a private key, I assume this is a P2SH wrapped segwit address, which means the script is just an `OP_0` opcode followed by the hash160 of the public key corresponding to that private key.

> **Comments:**
> **username_0**: I use bitcoin core 0.16.0 the latest version. But when I use `getaddressinfo` I got "Method not found"  
> **username_1**: Oh apologies, I thought it had made it into 0.16, it looks like its still only on the master dev branch. In that case you might have to create the script yourself using the OP_0 + hash160 approach I mentioned, see here for more info: https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address  
> **username_2**: Use `validateaddress` instead (the parts of `validateaddress` that give address information are moved to a new `getaddressinfo` command for the next major version, 0.17).  
> **username_1**: @AndrewChow does validateaddress output the script? I wasn't sure if it did or if that was new functionality  
> **username_3**: @MeshCollider It does. The RPC was just split up in two in master, but no new functionality was added.  

---

### Answer by username_4 on 2018-08-13. Score: 0

*(For additional detail):*

It is a `P2SH-P2WPKH` (Pay to witness public key hash wrapped in a pay to script hash). To create this address for mainnet:

1. Create Witness `PKH`:

`PKH = OP_0 0x14 RIPEMD160(SHA256(compressed public key))`  
`0x14` is number of bytes

2. Create `P2SH`:

`BASE58CHECK(0x05 PKH)`  
`0x05` is the mainnet `P2SH` prefix


---

