<p>Note that you are looking at P2SH-P2WPKH, not just P2WPKH.</p>
<p>You need to hash the bytes as bytes, not as a hex string. The linked website does not allow you to interpret the hex string as bytes - it instead interprets it as a string of characters. This results in the incorrect hash. You will need to use a tool that can interpret the hex string as representing bytes.</p>

CC BY-SA 4.0
2022-02-17T03:29:23.950Z
Think you. I think i kown where is the problem, and could you explain that in more detail. How can i hash the bytes as bytes ? It would be nice if there were some examples
KHJUAF403456ZS3K564WAEF
CC BY-SA 4.0
2022-02-17T04:29:33.863Z
You need a tool that will interpret it as bytes. One such that I have used is https://www.fileformat.info/tool/hash.htm and putting the hex string into the box for "Binary hash".
Ava Chow
CC BY-SA 4.0
2022-02-17T03:15:18.050Z
2022-02-17T03:15:18.050Z
Ava Chow
<p>I got some btc in testnet, here are the outputs.</p>
<p>this is the UTXO that i get my btc</p>
<pre><code>{
  &quot;value&quot;: 17.24756333,
  &quot;n&quot;: 1,
  &quot;scriptPubKey&quot;: {
    &quot;asm&quot;: &quot;OP_HASH160 71c5584f02c8ccc97e0ef9fa13aa67d989b29c98 OP_EQUAL&quot;,
    &quot;hex&quot;: &quot;a91471c5584f02c8ccc97e0ef9fa13aa67d989b29c9887&quot;,
    &quot;address&quot;: &quot;2N3cnkjDZd1HyGEy2D8oh8957Wcc1Cjzxza&quot;,
    &quot;type&quot;: &quot;scripthash&quot;
  }
}
</code></pre>
<p>this is the tx input using above UTXO.</p>
<pre><code>{
  &quot;txid&quot;: &quot;a40d14b993b0ec1b3e9f952b1faa746e7abe837619da25f4d3b88d4a063884ed&quot;,
  &quot;vout&quot;: 1,
  &quot;scriptSig&quot;: {
    &quot;asm&quot;: &quot;001460491e34d09f5621867187d04473aa5013907f79&quot;,
    &quot;hex&quot;: &quot;16001460491e34d09f5621867187d04473aa5013907f79&quot;
  },
  &quot;txinwitness&quot;: [
    &quot;304402202c740976d5a6c419c7deb205c19e8767a40a0505c2904a2f7f6bc20cb99248a6022046d73a42eb84277cdd5e201ccef5a518d619bfbb2b3f0d634ca043bb18c9bd2601&quot;,
    &quot;02085f6490ed441f222a38ddb21277ad5e0f05a7f0e7c76e097e0a9a79ac9c74eb&quot;
  ],
  &quot;sequence&quot;: 4294967294
}
</code></pre>
<p>i think they should follow that format(P2WPKH)</p>
<pre><code>witness:      &lt;signature&gt; &lt;pubkey&gt;
scriptSig:    &lt;0 &lt;20-byte-key-hash&gt;&gt;
              (0x160014{20-byte-key-hash})
scriptPubKey: HASH160 &lt;20-byte-script-hash&gt; EQUAL
              (0xA914{20-byte-script-hash}87)
</code></pre>
<p>but when i do hash160( 0014{20-byte-key-hash} ) in <a href="https://md5calc.com/hash" rel="nofollow noreferrer">here</a>, hash result is not equal to &lt;20-byte-script-hash&gt; in the scriptPubKey. it should be equal ,right ? what is the problem?</p>

<script><hash><raw-transaction><p2wpkh>
Why does my hash not line up with the one in the scriptPubKey?
KHJUAF403456ZS3K564WAEF
# Why does my hash not line up with the one in the scriptPubKey?

(Asked by: username_0 on 2022-02-17)

I got some btc in testnet, here are the outputs.
this is the UTXO that i get my btc
{
  "value": 17.24756333,
  "n": 1,
  "scriptPubKey": {
    "asm": "OP_HASH160 71c5584f02c8ccc97e0ef9fa13aa67d989b29c98 OP_EQUAL",
    "hex": "a91471c5584f02c8ccc97e0ef9fa13aa67d989b29c9887",
    "address": "2N3cnkjDZd1HyGEy2D8oh8957Wcc1Cjzxza",
    "type": "scripthash"
  }
}

this is the tx input using above UTXO.
{
  "txid": "a40d14b993b0ec1b3e9f952b1faa746e7abe837619da25f4d3b88d4a063884ed",
  "vout": 1,
  "scriptSig": {
    "asm": "001460491e34d09f5621867187d04473aa5013907f79",
    "hex": "16001460491e34d09f5621867187d04473aa5013907f79"
  },
  "txinwitness": [
    "304402202c740976d5a6c419c7deb205c19e8767a40a0505c2904a2f7f6bc20cb99248a6022046d73a42eb84277cdd5e201ccef5a518d619bfbb2b3f0d634ca043bb18c9bd2601",
    "02085f6490ed441f222a38ddb21277ad5e0f05a7f0e7c76e097e0a9a79ac9c74eb"
  ],
  "sequence": 4294967294
}

i think they should follow that format(P2WPKH)
witness:       
scriptSig:    <0 <20-byte-key-hash>>
              (0x160014{20-byte-key-hash})
scriptPubKey: HASH160 <20-byte-script-hash> EQUAL
              (0xA914{20-byte-script-hash}87)

but when i do hash160( 0014{20-byte-key-hash} ) in here, hash result is not equal to <20-byte-script-hash> in the scriptPubKey. it should be equal ,right ? what is the problem?

**Tags:** script, hash, raw-transaction, p2wpkh


---

## 1 answers

### Answer by username_1 on 2022-02-17. Score: 2

Note that you are looking at P2SH-P2WPKH, not just P2WPKH.

You need to hash the bytes as bytes, not as a hex string. The linked website does not allow you to interpret the hex string as bytes - it instead interprets it as a string of characters. This results in the incorrect hash. You will need to use a tool that can interpret the hex string as representing bytes.

> **Comments:**
> **username_0**: Think you. I think i kown where is the problem, and could you explain that in more detail. How can i hash the bytes as bytes ? It would be nice if there were some examples  
> **username_1**: You need a tool that will interpret it as bytes. One such that I have used is https://www.fileformat.info/tool/hash.htm and putting the hex string into the box for "Binary hash".  

---

