<p><strong>Feb2018</strong>: an older request, I just answer it so that future research might reveal useful data :-)</p>

<p>To compose the redeem script for a P2WPKH, there is a fairly simple structure, I copied this mostly <a href="https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address" rel="nofollow noreferrer">from here</a>:</p>

<p>Start with OP_0, followed by the keyhash. Keyhash is calculated with  RIPEMD160(SHA256(public key)), similiar to "std" PKH. Do not use uncompressed pubkeys! </p>

<p>The P2SH redeemScript will then always have 22 bytes: </p>

<pre><code>OP_0:    00
Length:  14
keyhash: (20 bytes)
</code></pre>

<p>The scriptPubKey is composed this way: </p>

<pre><code>OP_HASH160 hash160(redeemScript) OP_EQUAL
</code></pre>

<p>and the address is the corresponding P2SH address with prefix 3.</p>

<p><a href="https://bitcoin.stackexchange.com/questions/60961/generate-paper-wallet-segwit-address">Step by step explanation</a> here :-)</p>

CC BY-SA 3.0
2018-02-20T11:25:48.140Z
2018-02-20T11:44:53.463Z
2018-02-20T11:44:53.463Z
pebwindkraft
<p>How does one derive the Redeem Script for the new Pay-to-Witness Pubkey Hash addresses? With existing P2SH it's revealed after providing N number of Public Keys through a <code>createmultisig</code> function in the bitcoin client. Is it the same, just provide a single public key through a <code>createwitness</code> or similar function? </p>

<p>Is it currently available for fiddling with on testnet?</p>

<p2sh><segregated-witness><p2wpkh>
Redeem script for segwit addresses
m1xolyd1an
# Redeem script for segwit addresses

(Asked by: username_0 on 2017-01-07)

How does one derive the Redeem Script for the new Pay-to-Witness Pubkey Hash addresses? With existing P2SH it's revealed after providing N number of Public Keys through a `createmultisig` function in the bitcoin client. Is it the same, just provide a single public key through a `createwitness` or similar function?

Is it currently available for fiddling with on testnet?

**Tags:** p2sh, segregated-witness, p2wpkh


---

## 1 answers

### Answer by username_1 on 2018-02-20. Score: 2 | Accepted answer

**Feb2018**: an older request, I just answer it so that future research might reveal useful data :-)

To compose the redeem script for a P2WPKH, there is a fairly simple structure, I copied this mostly [from here](https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address):

Start with OP\_0, followed by the keyhash. Keyhash is calculated with RIPEMD160(SHA256(public key)), similiar to "std" PKH. Do not use uncompressed pubkeys!

The P2SH redeemScript will then always have 22 bytes:

```
OP_0:    00
Length:  14
keyhash: (20 bytes)

```

The scriptPubKey is composed this way:

```
OP_HASH160 hash160(redeemScript) OP_EQUAL

```

and the address is the corresponding P2SH address with prefix 3.

[Step by step explanation](https://bitcoin.stackexchange.com/questions/60961/generate-paper-wallet-segwit-address) here :-)


---

