1

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

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

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?

1 Answer 1

2

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:

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:

# 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:

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?

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.