<ol>
<li>Addresses that start with 2 on testnet or more precisely scripts that are like <code>OP_HASH160 &lt;hash&gt; OP_EQUAL</code> are P2SH scripts and the hash is created by computing HASH160 of a redeem script. Your redeem script seems to be a P2WPKH one which makes your address a P2SH-P2WPKH address. Your redeem script that has to be hashed is <code>OP_0 &lt;160-bit hash of public key&gt;</code></li>
<li>It is a indicator that this transaction contains witnesses. See <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer">BIP-141</a>.</li>
<li><code>02</code> is indicating there are 2 witness items and <code>47</code> is the size of the first witness item using compact integer format.</li>
</ol>

CC BY-SA 4.0
2021-12-29T03:51:23.593Z
Hey, thanks for the answer.
So, you mean do the RIPEMD160 hash of "0x00 + publicKey", which is the redeem script,
then do the "RIPEMD160" of that, add the network prefix, double hash that, grab the first 4 bytes as checksum, then do base58checkencode? 

I'm still kinda lost on the exact steps. Here is the output from the testnet wallet for that address/label (see question above, I edited it)
btcnewb
CC BY-SA 4.0
2021-12-29T04:52:37.333Z
@btcnewb Hash160 = SHA-256 followed by ripemd-160. The script hash is the hash160 of the redeem script. You prepend the version byte to that, compute the checksum as the double sha-256 hash of "version+script hash", append the first four bytes of that hash, then Base58 encode. The steps are similar to [this procedure](https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses) and [this answer](https://bitcoin.stackexchange.com/a/111484/51948).
meshcollider
CC BY-SA 4.0
2021-12-24T08:18:01.530Z
2021-12-24T08:18:01.530Z
Coding Enthusiast
<p>I'm trying to learn more about bitcoin and I'm trying to decode a transaction I made to myself on testnet and I can't seem to figure out a couple of things</p>
<p>Here is the output of getrawtransaction:
<code>getrawtransaction 'f013fd7f27a8c78fd52ad95253e7330dd7e5c6490f480cecd95359cfb1abcbdd' true</code></p>
<pre><code>{
  &quot;txid&quot;: &quot;f013fd7f27a8c78fd52ad95253e7330dd7e5c6490f480cecd95359cfb1abcbdd&quot;,
  &quot;hash&quot;: &quot;f6f699d7587a455e516be97b81b79d318d40ca9a8cc4f3382e4ba355808f7c83&quot;,
  &quot;version&quot;: 2,
  &quot;size&quot;: 223,
  &quot;vsize&quot;: 142,
  &quot;weight&quot;: 565,
  &quot;locktime&quot;: 2133079,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;246f7eb126789462a13b56658fc8095118ea9499b0c41ca5402fa38f97681d2b&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;txinwitness&quot;: [
        &quot;304402200eb3153139da95c29755baaddb1f8038ad1bd850f46b56d467875d91eb49599502204a19b6798bbdbd019f0bcf63a3412d4f99f923b19a33377c714d06a6f77a71fa01&quot;,
        &quot;036abeb6881115996db7d8fc9845adf6dabc66e03ca04ff9ff6d15d64fed1cf4b1&quot;
      ],
      &quot;sequence&quot;: 4294967293
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 0.00009858,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;OP_HASH160 07a715962bfe8aec6637ea4abe38e412aa8f9f77 OP_EQUAL&quot;,
        &quot;hex&quot;: &quot;a91407a715962bfe8aec6637ea4abe38e412aa8f9f7787&quot;,
        &quot;address&quot;: &quot;2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS&quot;,
        &quot;type&quot;: &quot;scripthash&quot;
      }
    },
    {
      &quot;value&quot;: 0.00010000,
      &quot;n&quot;: 1,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 f864afee2f6d17a22c420ee61ea21aff5d76ebd4&quot;,
        &quot;hex&quot;: &quot;0014f864afee2f6d17a22c420ee61ea21aff5d76ebd4&quot;,
        &quot;address&quot;: &quot;tb1qlpj2lm30d5t6ytzzpmnpags6lawhd675fh8265&quot;,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;
      }
    }
  ],
  &quot;hex&quot;: &quot;020000000001012b1d68978fa32f40a51cc4b09994ea185109c88f65563ba162947826b17e6f240000000000fdffffff02822600000000000017a91407a715962bfe8aec6637ea4abe38e412aa8f9f77871027000000000000160014f864afee2f6d17a22c420ee61ea21aff5d76ebd40247304402200eb3153139da95c29755baaddb1f8038ad1bd850f46b56d467875d91eb49599502204a19b6798bbdbd019f0bcf63a3412d4f99f923b19a33377c714d06a6f77a71fa0121036abeb6881115996db7d8fc9845adf6dabc66e03ca04ff9ff6d15d64fed1cf4b1578c2000&quot;
}
</code></pre>
<p>Questions:</p>
<ol>
<li>The address I sent some test BTC to is <code>2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS</code>. But, I don't know what <code>07a715962bfe8aec6637ea4abe38e412aa8f9f77</code> is and I can't seem to duplicate it. I can't even duplicate <code>2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS</code>.  By duplicate I mean I can't seem to recreate that label given the public key from my wallet.  The public key is <code>02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc</code>, so from that shouldn't I be able to take the RIPEMD160 HASH, prepend add <code>0x6f</code>, take the double hash, take the first 4 bytes, then encode that into base-58 (version + hash + checksum) and get the above address? What am I doing wrong because I'm not getting that.</li>
<li>What are the 2 bytes after the first 4 bytes (Version)?  Bytes 5-6, which is <code>0001</code>?</li>
<li>What about bytes 113-114?  Which is <code>0247</code> (in the raw hex dump)?  What does that represent?</li>
</ol>
<p>Edit: output from testnet wallet:</p>
<pre><code>getaddressinfo &quot;2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS&quot;


{
  &quot;address&quot;: &quot;2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS&quot;,
  &quot;scriptPubKey&quot;: &quot;a91407a715962bfe8aec6637ea4abe38e412aa8f9f7787&quot;,
  &quot;isscript&quot;: true,
  &quot;iswitness&quot;: false,
  &quot;script&quot;: &quot;witness_v0_keyhash&quot;,
  &quot;hex&quot;: &quot;00145ec830fe309c79964f739c66bdc0619d754a4e33&quot;,
  &quot;pubkey&quot;: &quot;02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc&quot;,
  &quot;embedded&quot;: {
    &quot;isscript&quot;: false,
    &quot;iswitness&quot;: true,
    &quot;witness_version&quot;: 0,
    &quot;witness_program&quot;: &quot;5ec830fe309c79964f739c66bdc0619d754a4e33&quot;,
    &quot;pubkey&quot;: &quot;02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc&quot;,
    &quot;address&quot;: &quot;tb1qtmyrpl3sn3uevnmnn3ntmsrpn4655n3npp07k4&quot;,
    &quot;scriptPubKey&quot;: &quot;00145ec830fe309c79964f739c66bdc0619d754a4e33&quot;
  },
</code></pre>

<address><raw-transaction><testnet>
Help decoding transaction on bitcoin testnet
btcnewb
# Help decoding transaction on bitcoin testnet

(Asked by: username_0 on 2021-12-24)

I'm trying to learn more about bitcoin and I'm trying to decode a transaction I made to myself on testnet and I can't seem to figure out a couple of things

Here is the output of getrawtransaction:
`getrawtransaction 'f013fd7f27a8c78fd52ad95253e7330dd7e5c6490f480cecd95359cfb1abcbdd' true`

```
{
  "txid": "f013fd7f27a8c78fd52ad95253e7330dd7e5c6490f480cecd95359cfb1abcbdd",
  "hash": "f6f699d7587a455e516be97b81b79d318d40ca9a8cc4f3382e4ba355808f7c83",
  "version": 2,
  "size": 223,
  "vsize": 142,
  "weight": 565,
  "locktime": 2133079,
  "vin": [
    {
      "txid": "246f7eb126789462a13b56658fc8095118ea9499b0c41ca5402fa38f97681d2b",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402200eb3153139da95c29755baaddb1f8038ad1bd850f46b56d467875d91eb49599502204a19b6798bbdbd019f0bcf63a3412d4f99f923b19a33377c714d06a6f77a71fa01",
        "036abeb6881115996db7d8fc9845adf6dabc66e03ca04ff9ff6d15d64fed1cf4b1"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 0.00009858,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 07a715962bfe8aec6637ea4abe38e412aa8f9f77 OP_EQUAL",
        "hex": "a91407a715962bfe8aec6637ea4abe38e412aa8f9f7787",
        "address": "2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS",
        "type": "scripthash"
      }
    },
    {
      "value": 0.00010000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 f864afee2f6d17a22c420ee61ea21aff5d76ebd4",
        "hex": "0014f864afee2f6d17a22c420ee61ea21aff5d76ebd4",
        "address": "tb1qlpj2lm30d5t6ytzzpmnpags6lawhd675fh8265",
        "type": "witness_v0_keyhash"
      }
    }
  ],
  "hex": "020000000001012b1d68978fa32f40a51cc4b09994ea185109c88f65563ba162947826b17e6f240000000000fdffffff02822600000000000017a91407a715962bfe8aec6637ea4abe38e412aa8f9f77871027000000000000160014f864afee2f6d17a22c420ee61ea21aff5d76ebd40247304402200eb3153139da95c29755baaddb1f8038ad1bd850f46b56d467875d91eb49599502204a19b6798bbdbd019f0bcf63a3412d4f99f923b19a33377c714d06a6f77a71fa0121036abeb6881115996db7d8fc9845adf6dabc66e03ca04ff9ff6d15d64fed1cf4b1578c2000"
}

```

Questions:

1. The address I sent some test BTC to is `2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS`. But, I don't know what `07a715962bfe8aec6637ea4abe38e412aa8f9f77` is and I can't seem to duplicate it. I can't even duplicate `2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS`. By duplicate I mean I can't seem to recreate that label given the public key from my wallet. The public key is `02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc`, so from that shouldn't I be able to take the RIPEMD160 HASH, prepend add `0x6f`, take the double hash, take the first 4 bytes, then encode that into base-58 (version + hash + checksum) and get the above address? What am I doing wrong because I'm not getting that.
2. What are the 2 bytes after the first 4 bytes (Version)? Bytes 5-6, which is `0001`?
3. What about bytes 113-114? Which is `0247` (in the raw hex dump)? What does that represent?

Edit: output from testnet wallet:

```
getaddressinfo "2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS"

{
  "address": "2MswgsrCPRvvB6umFyCYJB6L5FFjnoce2AS",
  "scriptPubKey": "a91407a715962bfe8aec6637ea4abe38e412aa8f9f7787",
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_keyhash",
  "hex": "00145ec830fe309c79964f739c66bdc0619d754a4e33",
  "pubkey": "02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc",
  "embedded": {
    "isscript": false,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "5ec830fe309c79964f739c66bdc0619d754a4e33",
    "pubkey": "02381296c094c7284621bf3b25fb086a531d5035b7982604d15f9223cda758c7bc",
    "address": "tb1qtmyrpl3sn3uevnmnn3ntmsrpn4655n3npp07k4",
    "scriptPubKey": "00145ec830fe309c79964f739c66bdc0619d754a4e33"
  },

```

**Tags:** address, raw-transaction, testnet


---

## 1 answers

### Answer by username_1 on 2021-12-24. Score: 2

1. Addresses that start with 2 on testnet or more precisely scripts that are like `OP_HASH160 <hash> OP_EQUAL` are P2SH scripts and the hash is created by computing HASH160 of a redeem script. Your redeem script seems to be a P2WPKH one which makes your address a P2SH-P2WPKH address. Your redeem script that has to be hashed is `OP_0 <160-bit hash of public key>`
2. It is a indicator that this transaction contains witnesses. See [BIP-141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki).
3. `02` is indicating there are 2 witness items and `47` is the size of the first witness item using compact integer format.

> **Comments:**
> **username_0**: Hey, thanks for the answer. So, you mean do the RIPEMD160 hash of "0x00 + publicKey", which is the redeem script, then do the "RIPEMD160" of that, add the network prefix, double hash that, grab the first 4 bytes as checksum, then do base58checkencode?   I'm still kinda lost on the exact steps. Here is the output from the testnet wallet for that address/label (see question above, I edited it)  
> **username_2**: @username_0 Hash160 = SHA-256 followed by ripemd-160. The script hash is the hash160 of the redeem script. You prepend the version byte to that, compute the checksum as the double sha-256 hash of "version+script hash", append the first four bytes of that hash, then Base58 encode. The steps are similar to [this procedure](https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses) and [this answer](https://bitcoin.stackexchange.com/a/111484/51948).  

---

