Bitcoin

Wallet – Import addresses and migrate to descriptors

For study purposes I have the private key, public key and P2SH Address with redemption script and RIPEMD160. The address string has been saved. address_P2SH.txt.

We updated Bitcoin Core to version 26, and starting with version 0.21, Bitcoin uses descriptor wallets. Now unavailable importaddress Because basically createwallet Use descriptors.

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

I know I can use descriptor=false while createwalletBut I would like to know if I can migrate my “external” address to a descriptor and then sign the transaction. signrawtransactionwithwallet. You can’t use it unless you make a mistake signrawtransactionwithkey This is because the descriptor no longer allows importing the private key, only the master private key. This is true even if you have the private key from an external address.

update
The redemption script is P2PKH. SCRIPT="76a9"$PBLENGTH$PBH"88AC". I assume the logic for other kinds of scripts is the same.

second update

I followed @Pieter Wuille’s steps.

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 Peter, I can get 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 )'

Related Articles

Back to top button