<blockquote>
  <ol start="2">
  <li>Create P2SH redeemScript as <code>OP_PUSH publicKeyHash</code>:</li>
  </ol>
  
  <p>redeemScript: <code>0014d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d</code></p>
</blockquote>

<p>It's actually `OP_0  but you have resulted in the right thing anyways.</p>

<blockquote>
  <ol start="3">
  <li>Generate scriptPubKey as <code>OP_HASH160 hash160(redeemScript) OP_EQUAL</code></li>
  </ol>
  
  <p>scriptPubKey: <code>a914a19949e546c2f4d410cbb061c986b9ff3099ae7087</code></p>
  
  <ol start="4">
  <li>Generate RIPEMD160 hash of scriptPubKey:</li>
  </ol>
  
  <p>hash: <code>dc62e525af22d1f0f17cc2a091cf2c9fb36bf553</code></p>
</blockquote>

<p>These steps are incorrect. The thing that is hashed for a P2SH address is the redeemScript, not the scriptPubKey. Instead of doing step 3, you would skip directly to step 4 and hash the redeemScript instead of the scriptPubKey.</p>

CC BY-SA 3.0
2017-12-17T07:34:01.050Z
Hi Andrew, I was hoping you could help. I think I'm not generating the checksum correctly. Before the base58 encoding, this is the string I have: 05188ba16284702258959d8bb63bb9a5d979b5787555c30444. After base58 that's 33voQqbNAYyig272KjcX8GkucWn2uJk5WT. Last 6 characters are incorrect. Which part am I getting wrong?
user2298995
CC BY-SA 3.0
2017-12-17T16:39:41.000Z
@user2298995 Your checksum is wrong. The hex should be 05188BA16284702258959D8BB63BB9A5D979B57875BFE2FCFD
Ava Chow
CC BY-SA 3.0
2017-12-18T17:46:40.957Z
Thank you very much for your comment!  How is the checksum generated then? I took the 4 bytes of sha256(sha256(redeemScript)). Is it not the proper way?
user2298995
CC BY-SA 3.0
2017-12-18T17:59:02.847Z
No, it is the first 4 bytes of the sha256(sha256(payload)) where the payload is the data you are encoding with the base58 check encoding. In this case, the payload is 05188BA16284702258959D8BB63BB9A5D979B57875
Ava Chow
CC BY-SA 3.0
2017-12-18T19:12:24.703Z
Oh thank you very much. Very appreciated!
user2298995
CC BY-SA 3.0
2017-10-20T00:06:12.847Z
2017-10-20T00:06:12.847Z
Ava Chow
<p>I am trying to generate SegWit paper wallet address from WIF:</p>

<p>My WIF is <code>L5mHKZsCLS27nSoGM3RdAwuxjvg7XhJdP25LgqdXe6zF11wpWdbT</code>.</p>

<p>I am converting WIF to compressed public key:</p>

<p>Compressed public key: <code>03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb</code></p>

<p>I am creating P2SH-P2WPKH address using instructions at <a href="https://bitcoincore.org/en/segwit_wallet_dev/" rel="noreferrer">Creation of P2SH-P2WPKH Address</a></p>

<p>using following algorithm:</p>

<ol>
<li>Calculate the RIPEMD160 of the SHA256 of a public key:</li>
</ol>

<p>SHA256 of public key: <code>cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9</code></p>

<p>RIPEMD160 of SHA256 hash: <code>d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d</code></p>

<ol start="2">
<li>Create P2SH redeemScript as <code>OP_PUSH publicKeyHash</code>:</li>
</ol>

<p>redeemScript: <code>0014d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d</code></p>

<ol start="3">
<li>Generate scriptPubKey as <code>OP_HASH160 hash160(redeemScript) OP_EQUAL</code></li>
</ol>

<p>scriptPubKey: <code>a914a19949e546c2f4d410cbb061c986b9ff3099ae7087</code></p>

<ol start="4">
<li>Generate RIPEMD160 hash of scriptPubKey:</li>
</ol>

<p>hash: <code>dc62e525af22d1f0f17cc2a091cf2c9fb36bf553</code></p>

<ol start="5">
<li>Generate address with <code>0x05</code> prefix and double SHA256 hash checksum:</li>
</ol>

<p>result: <code>3MnK46gvixm8hk7mJTQTAqenniSodjXPrJ</code></p>

<p>Expected result according to <a href="https://segwitaddress.org" rel="noreferrer">segwitaddress</a> is:</p>

<p><code>33voQqbNAYyig272KjcX8GkucWn2x25WEg</code></p>

<p>What am I doing wrong?</p>

<p><strong>Update</strong></p>

<p>Thanks to the accepted answer, here are correct steps to do this:</p>

<pre><code>Public key - compressed: 
03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb

SHA256(public key) =
cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9

RIPEMD160(SHA256(public key)) =
7646c030f7e75b80f0a31cdcab731e6f424f22b2

redeemScript (OP_0 pubkeyHash160):
00147646c030f7e75b80f0a31cdcab731e6f424f22b2

SHA256(redeemScript) =
a10e523968ba784d24ccd54e613d8f747d6649e42b1df4fdcec6658262620651

RIPEMD160(SHA256(redeemScript)) =
188ba16284702258959d8bb63bb9a5d979b57875

P2SH address base58(0x05 | hash | 4-byte sha256 checksum) =
33voQqbNAYyig272KjcX8GkucWn2x25WEg
</code></pre>

<segregated-witness><address-generation>
Generate paper wallet SegWit address
Jakub Fedyczak
# Generate paper wallet SegWit address

(Asked by: username_0 on 2017-10-19)

I am trying to generate SegWit paper wallet address from WIF:
My WIF is L5mHKZsCLS27nSoGM3RdAwuxjvg7XhJdP25LgqdXe6zF11wpWdbT.
I am converting WIF to compressed public key:
Compressed public key: 03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb
I am creating P2SH-P2WPKH address using instructions at Creation of P2SH-P2WPKH Address
using following algorithm:

Calculate the RIPEMD160 of the SHA256 of a public key:

SHA256 of public key: cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9
RIPEMD160 of SHA256 hash: d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d

Create P2SH redeemScript as OP_PUSH publicKeyHash:

redeemScript: 0014d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d

Generate scriptPubKey as OP_HASH160 hash160(redeemScript) OP_EQUAL

scriptPubKey: a914a19949e546c2f4d410cbb061c986b9ff3099ae7087

Generate RIPEMD160 hash of scriptPubKey:

hash: dc62e525af22d1f0f17cc2a091cf2c9fb36bf553

Generate address with 0x05 prefix and double SHA256 hash checksum:

result: 3MnK46gvixm8hk7mJTQTAqenniSodjXPrJ
Expected result according to segwitaddress is:
33voQqbNAYyig272KjcX8GkucWn2x25WEg
What am I doing wrong?
Update
Thanks to the accepted answer, here are correct steps to do this:
Public key - compressed: 
03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb

SHA256(public key) =
cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9

RIPEMD160(SHA256(public key)) =
7646c030f7e75b80f0a31cdcab731e6f424f22b2

redeemScript (OP_0 pubkeyHash160):
00147646c030f7e75b80f0a31cdcab731e6f424f22b2

SHA256(redeemScript) =
a10e523968ba784d24ccd54e613d8f747d6649e42b1df4fdcec6658262620651

RIPEMD160(SHA256(redeemScript)) =
188ba16284702258959d8bb63bb9a5d979b57875

P2SH address base58(0x05 | hash | 4-byte sha256 checksum) =
33voQqbNAYyig272KjcX8GkucWn2x25WEg

**Tags:** segregated-witness, address-generation


---

## 1 answers

### Answer by username_1 on 2017-10-20. Score: 2 | Accepted answer

> 2. Create P2SH redeemScript as `OP_PUSH publicKeyHash`:
>
> redeemScript: `0014d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d`

It's actually `OP\_0 but you have resulted in the right thing anyways.

> 3. Generate scriptPubKey as `OP_HASH160 hash160(redeemScript) OP_EQUAL`
>
> scriptPubKey: `a914a19949e546c2f4d410cbb061c986b9ff3099ae7087`
>
> 4. Generate RIPEMD160 hash of scriptPubKey:
>
> hash: `dc62e525af22d1f0f17cc2a091cf2c9fb36bf553`

These steps are incorrect. The thing that is hashed for a P2SH address is the redeemScript, not the scriptPubKey. Instead of doing step 3, you would skip directly to step 4 and hash the redeemScript instead of the scriptPubKey.

> **Comments:**
> **username_2**: Hi Andrew, I was hoping you could help. I think I'm not generating the checksum correctly. Before the base58 encoding, this is the string I have: 05188ba16284702258959d8bb63bb9a5d979b5787555c30444. After base58 that's 33voQqbNAYyig272KjcX8GkucWn2uJk5WT. Last 6 characters are incorrect. Which part am I getting wrong?  
> **username_1**: @username_2 Your checksum is wrong. The hex should be 05188BA16284702258959D8BB63BB9A5D979B57875BFE2FCFD  
> **username_2**: Thank you very much for your comment!  How is the checksum generated then? I took the 4 bytes of sha256(sha256(redeemScript)). Is it not the proper way?  
> **username_1**: No, it is the first 4 bytes of the sha256(sha256(payload)) where the payload is the data you are encoding with the base58 check encoding. In this case, the payload is 05188BA16284702258959D8BB63BB9A5D979B57875  
> **username_2**: Oh thank you very much. Very appreciated!  

---

