<p>Found an answer to my main question after trial and error:</p>
<p>One needs to first create a <strong>watch-only</strong> wallet and <strong>import descriptors into it</strong>, like so:</p>
<pre class="lang-bash prettyprint-override"><code>bitcoin-cli -regtest createwallet &quot;multisig_watch&quot; true true &quot;&quot; false true 
                                                                   
bitcoin-cli -regtest -rpcwallet=multisig_watch importdescriptors &quot;[
  {\&quot;desc\&quot;:\&quot;$DESCRIPTOR_PREVOUT0\&quot;, \&quot;timestamp\&quot;:\&quot;now\&quot;},    
  {\&quot;desc\&quot;:\&quot;$DESCRIPTOR_PREVOUT1\&quot;, \&quot;timestamp\&quot;:\&quot;now\&quot;}    
]&quot;
</code></pre>
<p>Then update PSBT with that watch-only wallet:</p>
<pre class="lang-bash prettyprint-override"><code># Update PSBT with watch-only wallet                                             
PSBT=$(bitcoin-cli -regtest -rpcwallet=multisig_watch walletprocesspsbt &quot;$PSBT&quot;)
</code></pre>
<p>After that the raw PSBT created with <code>createpsbt</code> will gain the required redeemScript and witnessScript data.<br />
Then, sign as usual with all wallets that contain corresponding private keys for redemption:</p>
<pre class="lang-bash prettyprint-override"><code>for wallet in &quot;${signing_wallets[@]}&quot;; do 
  PSBT=$( bitcoin-cli -regtest -rpcwallet=$wallet walletprocesspsbt $(jq -r .psbt &lt;&lt;&lt; $PSBT))
done
</code></pre>
<p>I think these multisig operations should be better documented in Bitcoin Core.</p>
<p>What remains unclear is if I have <code>sh(multi(1,KEY1_FROM_WALLET1,KEY2_FROM_WALLET2,KEY3_FROM_WALLET2,...))</code>
if/how I can <strong>explicitly choose</strong> between <code>KEY2_FROM_WALLET2</code> and <code>KEY3_FROM_WALLET2</code>?</p>

CC BY-SA 4.0
2024-07-18T17:01:04.613Z
2024-07-18T17:15:10.667Z
2024-07-18T17:15:10.667Z
Alec Matusis
<p>I am looking for the correct way to spend multisig outputs with descriptor wallet bitcoin-cli.</p>
<p>In regtest, I successfully created a funding transaction <code>tx1</code> with the following outputs:</p>
<p><code>out:0 sh(multi(1,KEY1,KEY2))</code></p>
<p><code>out:1 wsh(multi(1,KEY3,KEY4,KEY5))</code></p>
<p>I used <code>bitcoin-cli -regtest deriveaddresses</code> to get <code>P2SH_ADDRESS</code> and <code>P2WSH_ADDRESS</code> from these descriptors and then</p>
<pre class="lang-bash prettyprint-override"><code>bitcoin-cli -regtest -rpcwallet=&quot;$WALLET&quot; createrawtransaction '''
  [
    {
      &quot;txid&quot;: &quot;'$prev_tx'&quot;,
      &quot;vout&quot;: 0
    }
  ]
''' '''
  {
    &quot;'$P2SH_ADDRESS'&quot;: 3,
    &quot;'$P2WSH_ADDRESS'&quot;: 2,
    &quot;'$CHANGE_ADDRESS'&quot;: 18
  }
'''
</code></pre>
<p>Then I broadcast and mined this transaction.</p>
<p>Now I want to create a spending transaction, that spends both of these inputs, using</p>
<pre class="lang-bash prettyprint-override"><code>PSBT=$( bitcoin-cli -regtest -named createpsbt inputs='''[
  {
    &quot;txid&quot;: &quot;tx1&quot;,
    &quot;vout&quot;: 0
  },
  {
    &quot;txid&quot;: &quot;tx1&quot;,
    &quot;vout&quot;: 1
  },
]''' outputs='''[
  {
    &quot;'$ADDRESS1'&quot;: 1
  },
  {
    &quot;'$ADDRESS2'&quot;: 1
  },
  {
    &quot;$CHANGE_ADDRESS&quot;: 4
  }
]''')
</code></pre>
<p>My main question:</p>
<ul>
<li>how do I add input information to this <code>PSBT</code> (i.e. redeemScript for <code>inp:0</code> and witnessScript for <code>inp:1</code>)? What is the modern correct way to get a redeemScript and a witnessScript given output descriptors?</li>
</ul>
<p>My second question:</p>
<ul>
<li>say <code>KEY1,KEY3</code> belong to <code>wallet1</code>, and <code>KEY2,KEY4,KEY5</code> belong to <code>wallet2</code>. I want to spend <code>out:0</code> using <code>KEY1</code> and <code>out:1</code> using <code>KEY4</code>.
I tried to simply sign with both wallets: <code>bitcoin-cli -regtest -rpcwallet=walletN walletprocesspsbt $PSBT</code> but is it possible to select the specific key (i.e. wallet in this case) between <code>KEY1</code> and <code>KEY2</code> to spend the <code>sh(multi(1,KEY1,KEY2)) vout:0</code>, these keys are from the different wallets? And is it even correct to use <code>walletprocesspsbt</code> in this case?</li>
</ul>

<multi-signature><bitcoin-cli><bip174-psbt><output-script-descriptors>
How to spend a multisig descriptor wallet transaction with bitcoin-cli?
Alec Matusis
# How to spend a multisig descriptor wallet transaction with bitcoin-cli?

(Asked by: username_0 on 2024-07-16)

I am looking for the correct way to spend multisig outputs with descriptor wallet bitcoin-cli.

In regtest, I successfully created a funding transaction `tx1` with the following outputs:

`out:0 sh(multi(1,KEY1,KEY2))`

`out:1 wsh(multi(1,KEY3,KEY4,KEY5))`

I used `bitcoin-cli -regtest deriveaddresses` to get `P2SH_ADDRESS` and `P2WSH_ADDRESS` from these descriptors and then

```bash
bitcoin-cli -regtest -rpcwallet="$WALLET" createrawtransaction '''
  [
    {
      "txid": "'$prev_tx'",
      "vout": 0
    }
  ]
''' '''
  {
    "'$P2SH_ADDRESS'": 3,
    "'$P2WSH_ADDRESS'": 2,
    "'$CHANGE_ADDRESS'": 18
  }
'''

```

Then I broadcast and mined this transaction.

Now I want to create a spending transaction, that spends both of these inputs, using

```bash
PSBT=$( bitcoin-cli -regtest -named createpsbt inputs='''[
  {
    "txid": "tx1",
    "vout": 0
  },
  {
    "txid": "tx1",
    "vout": 1
  },
]''' outputs='''[
  {
    "'$ADDRESS1'": 1
  },
  {
    "'$ADDRESS2'": 1
  },
  {
    "$CHANGE_ADDRESS": 4
  }
]''')

```

My main question:

* how do I add input information to this `PSBT` (i.e. redeemScript for `inp:0` and witnessScript for `inp:1`)? What is the modern correct way to get a redeemScript and a witnessScript given output descriptors?

My second question:

* say `KEY1,KEY3` belong to `wallet1`, and `KEY2,KEY4,KEY5` belong to `wallet2`. I want to spend `out:0` using `KEY1` and `out:1` using `KEY4`.
  I tried to simply sign with both wallets: `bitcoin-cli -regtest -rpcwallet=walletN walletprocesspsbt $PSBT` but is it possible to select the specific key (i.e. wallet in this case) between `KEY1` and `KEY2` to spend the `sh(multi(1,KEY1,KEY2)) vout:0`, these keys are from the different wallets? And is it even correct to use `walletprocesspsbt` in this case?

**Tags:** multi-signature, bitcoin-cli, bip174-psbt, output-script-descriptors


---

## 1 answers

### Answer by username_0 on 2024-07-18. Score: 2 | Accepted answer

Found an answer to my main question after trial and error:

One needs to first create a **watch-only** wallet and **import descriptors into it**, like so:

```bash
bitcoin-cli -regtest createwallet "multisig_watch" true true "" false true 
                                                                   
bitcoin-cli -regtest -rpcwallet=multisig_watch importdescriptors "[
  {\"desc\":\"$DESCRIPTOR_PREVOUT0\", \"timestamp\":\"now\"},    
  {\"desc\":\"$DESCRIPTOR_PREVOUT1\", \"timestamp\":\"now\"}    
]"

```

Then update PSBT with that watch-only wallet:

```bash
# Update PSBT with watch-only wallet                                             
PSBT=$(bitcoin-cli -regtest -rpcwallet=multisig_watch walletprocesspsbt "$PSBT")

```

After that the raw PSBT created with `createpsbt` will gain the required redeemScript and witnessScript data.  
Then, sign as usual with all wallets that contain corresponding private keys for redemption:

```bash
for wallet in "${signing_wallets[@]}"; do 
  PSBT=$( bitcoin-cli -regtest -rpcwallet=$wallet walletprocesspsbt $(jq -r .psbt <<< $PSBT))
done

```

I think these multisig operations should be better documented in Bitcoin Core.

What remains unclear is if I have `sh(multi(1,KEY1_FROM_WALLET1,KEY2_FROM_WALLET2,KEY3_FROM_WALLET2,...))`
if/how I can **explicitly choose** between `KEY2_FROM_WALLET2` and `KEY3_FROM_WALLET2`?


---

