2

I state that I'm still a beginner. I need some clarification. I am using the Testnet. This is the information regarding the address I used to receive funds from a Faucet

 bitcoin-cli validateaddress 2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd
{
  "isvalid": true,
  "address": "2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd",
  "scriptPubKey": "a9149ac58ff47e27214b158b38da04bc8cbf72def14387",
  "isscript": true,
  "iswitness": false
}
bitcoin-cli decodescript a9149ac58ff47e27214b158b38da04bc8cbf72def14387
{
  "asm": "OP_HASH160 9ac58ff47e27214b158b38da04bc8cbf72def143 OP_EQUAL",
  "reqSigs": 1,
  "type": "scripthash",
  "addresses": [
    "2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd"
  ]
}

What do data mean? I interpret that my address will receive UTXO blocked by P2SH type scripts, correct? "iswitness": false means that this address cannot use UTXO segWit?

On this address I received the following output as input:

{
      "value": 0.01944571,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 9ac58ff47e27214b158b38da04bc8cbf72def143 OP_EQUAL",
        "hex": "a9149ac58ff47e27214b158b38da04bc8cbf72def14387",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd"
        ]
      }

The blocked UTXO is as follows:

"txid": "a61389ff9af670770182198a984a4c1785625c60795bd57645ecc78765b23679",
    "vout": 1,
    "address": "2N7MaihNErbNH8XTkuZWtJYPzMQAWMPVKHd",
    "label": "",
    "redeemScript": "0014778daf651b21684b572644b47d551fce0ff71c74",
    "scriptPubKey": "a9149ac58ff47e27214b158b38da04bc8cbf72def14387",
    "amount": 0.01944571,
    "confirmations": 116,
    "spendable": true,
    "solvable": true,
    "desc": "sh(wpkh([7de694b7/0'/0'/7']032c27921f2d15e7eca768c0e8a8b1aeb863328c74d6c194d41dde2888d4b0e75b))#6z7uwusp",

"Sh (wpkh ())" describes a P2SH-P2WPKH output and the public key with which it is associated.

The descriptor is telling us that the hash (sh) script incorporates wpkh (Witness - Public - Key - Hash) output. In simple words the RedeemScript should match the HASH of this public key, correct?

When I unlock and use this UTXO my input will generate a separate txinwitness field.

"scriptSig": {
        "asm": "0014778daf651b21684b572644b47d551fce0ff71c74",
        "hex": "160014778daf651b21684b572644b47d551fce0ff71c74"
      },
      "txinwitness": [
        "3044022034a07f088dd88396cd378912a4ed6a156701b075f0facbbae810677048c390e602205df07e13bf4d56feece791a1b5e4d94bec9c93aae14bb87a1b4c6c54ae9bf2f701",
        "032c27921f2d15e7eca768c0e8a8b1aeb863328c74d6c194d41dde2888d4b0e75b"
      ],
      "sequence": 4294967295

I can't understand the link between my address information ("iswitness": false) and the ways in which I received / spent the UTXO.

1 Answer 1

2

Because the address you are using is a P2SH-P2WPKH address as you mention (sh (wpkh ())), you get the output

"isscript": true,

"iswitness": false

It is talking only about the top level (P2SH), because it is a P2SH address, regardless of what the script "inside" it encodes. It doesn't "see" the underlying P2WPKH when you call validateaddress. The only time isscript and iswitness are both true, is for P2WSH addresses. You can view the code which creates this RPC isscript/iswitness output here.

When you spend it, you reveal the script inside the P2SH. Because it is a P2WPKH script, which is OP_0 <keyhash>, that script is then evaluated as such (using the key/signature data in the witness).

4
  • Is the wallet that decides which type of address to use? the incoming transactions to the addresses that I will generate will always be P2SH?
    – MaXbeMan
    May 1, 2020 at 10:34
  • You can choose which address type your wallet will generate. If you generate P2SH-P2WPKH addresses (as you have), then incoming transactions should follow the correct format yes. Technically though, if someone knows the key itself, they can also make transactions to the P2PKH and Bech32 forms of that key as well, and the wallet will currently accept them. May 1, 2020 at 11:56
  • for my wallet I generated 3 addresses with the getnewaddress command. All received utxo are in the same format. P2SH-P2WPKH is the standard format for getnewaddress?
    – MaXbeMan
    May 1, 2020 at 13:24
  • 1
    It is the default for your version of bitcoin core, but you can change it May 5, 2020 at 4:21

Your Answer

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

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