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": [
      "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"


  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"

1 Answer 1

  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.
  3. 02 is indicating there are 2 witness items and 47 is the size of the first witness item using compact integer format.
  • 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
    Dec 29, 2021 at 3:51
  • 1
    @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 and this answer. Dec 29, 2021 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.