<p>If all you have is an address that you want to watch, you can use an <code>addr(ADDR)</code> descriptor (with <code>ADDR</code> replaced with your actual address). Importing that will make a descriptor wallet treat the address as its own, list its transactions, and use it in balance calculations.</p>
<p>If you want to also participate in signing, you'll need to provide more detail about its construction.</p>
<p>In your case, we're talking about a P2PKH-in-P2SH script, for which the descriptor would be <code>sh(pkh(KEY))</code> (<code>sh</code> is for P2SH, <code>pkh</code> is for P2PKH), where <code>KEY</code> can either be a hex pubkey, a WIF privkey, an xpub with derivation path, or an xprv with derivation path.</p>
<p>See the descriptors documentation for how to write ones for other types of scripts, but in very short, the single-key constructions I can come up with:</p>
<ul>
<li><code>pk(KEY)</code> for P2PK</li>
<li><code>pkh(KEY)</code> for P2PKH</li>
<li><code>wpkh(KEY)</code> for P2WPKH</li>
<li><code>tr(KEY)</code> for P2TR (with KEY as internal key)</li>
<li><code>sh(pk(KEY))</code> for P2SH-P2PK</li>
<li><code>sh(pkh(KEY))</code> for P2SH-P2PKH</li>
<li><code>sh(wpkh(KEY))</code> for P2SH-P2WPKH</li>
<li><code>wsh(pk(KEY))</code> for P2WSH-P2PK</li>
<li><code>wsh(pkh(KEY))</code> for P2WSH-P2PKH</li>
<li><code>sh(wsh(pk(KEY)))</code> for P2SH-P2WSH-P2PK</li>
<li><code>sh(wsh(pkh(KEY)))</code> for P2SH-P2WSH-P2PKH</li>
</ul>
<p>It's hopefully obvious that I don't recommend any but the first few in this list, but it can be fun to play around with the ability to compose.</p>
<p>Note that the <code>importdescriptors</code> call requires descriptors that include a checksum. The checksum can be calculated using the <code>getdescriptorinfo</code> RPC.</p>

CC BY-SA 4.0
2023-12-07T19:21:59.360Z
I'm using P2SH-P2PKH because I created some examples for my study notes, and now I want to adjust them if possible. I also have examples for P2SH-P2PK and P2WPKH.
monkeyUser
CC BY-SA 4.0
2023-12-07T19:40:37.817Z
I updated again the answer with your steps
monkeyUser
CC BY-SA 4.0
2023-12-07T19:42:36.500Z
@monkeyUser The `descriptor` field in the `getdescriptorinfo` output is the *normalized* descriptor (which excludes private key material) for your input (note that it replaced your WIF key with a hex pubkey). If you want to import private key material too, you need to use the original (the `checksum` field reports the checksum for your original descriptor).
Pieter Wuille
CC BY-SA 4.0
2023-12-07T21:05:47.867Z
Thanks for your time and for new edited answer
monkeyUser
CC BY-SA 4.0
2023-12-07T18:59:41.103Z
2023-12-07T20:00:44.733Z
2023-12-07T20:00:44.733Z
Pieter Wuille
<p>I created a script for studying purposes, generating a private key, a public key, and a <code>P2SH</code> address with a redeem script and <code>RIPEMD160</code>. I stored the address string in <code>address_P2SH.txt</code>.</p>
<p>I updated Bitcoin Core to version 26, and since version 0.21, Bitcoin uses Descriptor wallets. Now, I can't use <code>importaddress</code> because, by default, <code>createwallet</code> uses descriptors.</p>
<pre><code>ADDR_P2SH=`cat address_P2SH.txt`
bitcoin-cli importaddress $ADDR_P2SH
</code></pre>
<p>I know I can use <code>descriptor=false</code> during <code>createwallet</code>, but I'd like to know if I can migrate my &quot;external&quot; address to a descriptor and sign my transaction with <code>signrawtransactionwithwallet</code>. If I'm not mistaken, I can't use <code>signrawtransactionwithkey</code> anymore because the descriptor doesn't allow getting the private key, only the master private key, even if I have the private key from my external address.</p>
<p><strong>Update</strong>
The redeem script is a P2PKH <code>SCRIPT=&quot;76a9&quot;$PBLENGTH$PBH&quot;88AC&quot;</code>. I presume that the logic for other kinds of scripts is the same.</p>
<p><strong>second Update</strong></p>
<p>I followed the steps of @Pieter Wuille</p>
<pre><code>bitcoin-cli getdescriptorinfo &quot;sh(pkh($(cat compressed_private_key_WIF_1.txt)))&quot;
</code></pre>
<p>and I got</p>
<pre><code>{
  &quot;descriptor&quot;: &quot;sh(pkh(0233e11f2a33d480d4fa1bcb7a0e118ea56d6511a21735e01c00182e924c5a8efc))#cx4xdav6&quot;,
  &quot;checksum&quot;: &quot;e2yjqzgh&quot;,
  &quot;isrange&quot;: false,
  &quot;issolvable&quot;: true,
  &quot;hasprivatekeys&quot;: true
}
</code></pre>
<p>then</p>
<pre><code> bitcoin-cli importdescriptors '[{ &quot;desc&quot;: &quot;sh(pkh(0233e11f2a33d480d4fa1bcb7a0e118ea56d6511a21735e01c00182e924c5a8efc))#cx4xdav6&quot;, &quot;timestamp&quot;: &quot;now&quot;, &quot;internal&quot;: true }]'
[
  {
    &quot;success&quot;: false,
    &quot;error&quot;: {
      &quot;code&quot;: -4,
      &quot;message&quot;: &quot;Cannot import descriptor without private keys to a wallet with private keys enabled&quot;
    }
  }
]
</code></pre>
<p><strong>Third update</strong>
Thanks to Peter I can import the address</p>
<pre><code>CHECKSUM=$(bitcoin-cli getdescriptorinfo &quot;sh(pkh($(cat compressed_private_key_WIF_1.txt)))&quot; | jq -r .checksum)

bitcoin-cli importdescriptors '[{ &quot;desc&quot;: &quot;sh(pkh('$(cat compressed_private_key_WIF_1.txt)'))#'&quot;$CHECKSUM&quot;'&quot;, &quot;timestamp&quot;: &quot;now&quot;, &quot;internal&quot;: true }]'
</code></pre>

CC BY-SA 4.0
2023-12-07T18:48:56.687Z
What kind of script is the P2SH redeemScript? With just an address all you can do is watch. If you want to participate in signing, you'll need a descriptor that describes how the address is constructed. I can't advise on that without knowing what the script is.
Pieter Wuille
CC BY-SA 4.0
2023-12-07T18:57:46.790Z
you are right, I Updated my question
monkeyUser
<wallet><private-key><output-script-descriptors>
Importaddress and migrate to descriptor
monkeyUser
# Importaddress and migrate to descriptor

(Asked by: username_0 on 2023-12-07)

I created a script for studying purposes, generating a private key, a public key, and a `P2SH` address with a redeem script and `RIPEMD160`. I stored the address string in `address_P2SH.txt`.

I updated Bitcoin Core to version 26, and since version 0.21, Bitcoin uses Descriptor wallets. Now, I can't use `importaddress` because, by default, `createwallet` uses descriptors.

```
ADDR_P2SH=`cat address_P2SH.txt`
bitcoin-cli importaddress $ADDR_P2SH

```

I know I can use `descriptor=false` during `createwallet`, but I'd like to know if I can migrate my "external" address to a descriptor and sign my transaction with `signrawtransactionwithwallet`. If I'm not mistaken, I can't use `signrawtransactionwithkey` anymore because the descriptor doesn't allow getting the private key, only the master private key, even if I have the private key from my external address.

**Update**
The redeem script is a P2PKH `SCRIPT="76a9"$PBLENGTH$PBH"88AC"`. I presume that the logic for other kinds of scripts is the same.

**second Update**

I followed the steps of @username_1

```
bitcoin-cli getdescriptorinfo "sh(pkh($(cat compressed_private_key_WIF_1.txt)))"

```

and I got

```
{
  "descriptor": "sh(pkh(0233e11f2a33d480d4fa1bcb7a0e118ea56d6511a21735e01c00182e924c5a8efc))#cx4xdav6",
  "checksum": "e2yjqzgh",
  "isrange": false,
  "issolvable": true,
  "hasprivatekeys": true
}

```

then

```
 bitcoin-cli importdescriptors '[{ "desc": "sh(pkh(0233e11f2a33d480d4fa1bcb7a0e118ea56d6511a21735e01c00182e924c5a8efc))#cx4xdav6", "timestamp": "now", "internal": true }]'
[
  {
    "success": false,
    "error": {
      "code": -4,
      "message": "Cannot import descriptor without private keys to a wallet with private keys enabled"
    }
  }
]

```

**Third update**
Thanks to Peter I can import the address

```
CHECKSUM=$(bitcoin-cli getdescriptorinfo "sh(pkh($(cat compressed_private_key_WIF_1.txt)))" | jq -r .checksum)

bitcoin-cli importdescriptors '[{ "desc": "sh(pkh('$(cat compressed_private_key_WIF_1.txt)'))#'"$CHECKSUM"'", "timestamp": "now", "internal": true }]'

```

**Tags:** wallet, private-key, output-script-descriptors

> **Comments:**
> **username_1**: What kind of script is the P2SH redeemScript? With just an address all you can do is watch. If you want to participate in signing, you'll need a descriptor that describes how the address is constructed. I can't advise on that without knowing what the script is.  
> **username_0**: you are right, I Updated my question  

---

## 1 answers

### Answer by username_1 on 2023-12-07. Score: 1 | Accepted answer

If all you have is an address that you want to watch, you can use an `addr(ADDR)` descriptor (with `ADDR` replaced with your actual address). Importing that will make a descriptor wallet treat the address as its own, list its transactions, and use it in balance calculations.

If you want to also participate in signing, you'll need to provide more detail about its construction.

In your case, we're talking about a P2PKH-in-P2SH script, for which the descriptor would be `sh(pkh(KEY))` (`sh` is for P2SH, `pkh` is for P2PKH), where `KEY` can either be a hex pubkey, a WIF privkey, an xpub with derivation path, or an xprv with derivation path.

See the descriptors documentation for how to write ones for other types of scripts, but in very short, the single-key constructions I can come up with:

* `pk(KEY)` for P2PK
* `pkh(KEY)` for P2PKH
* `wpkh(KEY)` for P2WPKH
* `tr(KEY)` for P2TR (with KEY as internal key)
* `sh(pk(KEY))` for P2SH-P2PK
* `sh(pkh(KEY))` for P2SH-P2PKH
* `sh(wpkh(KEY))` for P2SH-P2WPKH
* `wsh(pk(KEY))` for P2WSH-P2PK
* `wsh(pkh(KEY))` for P2WSH-P2PKH
* `sh(wsh(pk(KEY)))` for P2SH-P2WSH-P2PK
* `sh(wsh(pkh(KEY)))` for P2SH-P2WSH-P2PKH

It's hopefully obvious that I don't recommend any but the first few in this list, but it can be fun to play around with the ability to compose.

Note that the `importdescriptors` call requires descriptors that include a checksum. The checksum can be calculated using the `getdescriptorinfo` RPC.

> **Comments:**
> **username_0**: I'm using P2SH-P2PKH because I created some examples for my study notes, and now I want to adjust them if possible. I also have examples for P2SH-P2PK and P2WPKH.  
> **username_0**: I updated again the answer with your steps  
> **username_1**: @username_0 The `descriptor` field in the `getdescriptorinfo` output is the *normalized* descriptor (which excludes private key material) for your input (note that it replaced your WIF key with a hex pubkey). If you want to import private key material too, you need to use the original (the `checksum` field reports the checksum for your original descriptor).  
> **username_0**: Thanks for your time and for new edited answer  

---

