1

I must fetch utxos for a native segwit address from the local Bitcoin node. First I wanted to import the segwit address. However, it fails.

How can I import a native segwit address? I'm using latest bitcoind version 240001

# bitcoin-cli -testnet importmulti '[{"scriptPubKey": {"address": "bc1qerwt7v72j0w70ezw09keaqzcsss......."}, "timestamp": "now"}]'
error code: -4
error message:
Only legacy wallets are supported by this command

Thank you!

2 Answers 2

2

For modern "descriptor" wallets, you need to convert whatever you want to import to the output descriptor language, and import that using the importdescriptors RPC.

For an individual address, the descriptor is just addr(ADDR), where ADDR is the address you want to import. The importdescriptors RPC requires descriptors to have a checksum, of the form #CHECK, where CHECK is the checksum. You can compute the necessary checksum using the getdescriptorinfo RPC.

8
  • bitcoin-cli -testnet importDescriptors '[{"desc": "addr(tb1qxhx5gq5gwaju2lh0pxnp7....)", "timestamp": "now"}]' still fails. Error message is Method not found. Bitcoin Core RPC client version v24.0.1
    – att
    Apr 21, 2023 at 22:11
  • 1
    Do not capitalize the D in importdescriptors. Apr 21, 2023 at 22:33
  • 1
    I told you you need to compute and add the checksum, for example using getdescriptorinfo. Apr 21, 2023 at 22:49
  • 1
    You'll need to create a wallet for watching, without private keys, using the createwallet RPC, and import into that. Apr 21, 2023 at 23:06
  • 1
    Thank you! I'm able to import it into wallet test4. Then I deposited some testnet bitcoin into it. Should I supposed to see it with the bitcoin-cli -testnet -rpcwallet=test4 listunspent
    – att
    Apr 21, 2023 at 23:17
1

Thank you @Pieter I'm able to import and segwit address into a wallet.

  • Created a wallet without private keys.
~$ bitcoin-cli -testnet createwallet test4 true
{
  "name": "test4",
  "warning": ""
}
  • Get descriptor info to obtain hash
~$ bitcoin-cli -testnet getdescriptorinfo "addr(tb1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvsfuejza)"
{
 "descriptor": "addr(tb1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvsfuejza)#h8rwjq0n",
 "checksum": "h8rwjq0n",
 "isrange": false,
 "issolvable": false,
 "hasprivatekeys": false
}
  • Imported the address
~$ bitcoin-cli -testnet -rpcwallet=test4 importdescriptors '[{"desc": "addr(tb1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvsfuejza)#h8rwjq0n", "timestamp": "now"}]'
[
  {
    "success": true
  }
]

After a couple of minutes, the testnet bitcoins I've sent to the address appeared in the wallet.

bitcoin-cli -testnet -rpcwallet=test4 listunspent 
[
  {
    "txid": "c50321fa5a86a281882283b507f33529682158998d32bb335c125ed2e2b6e614",
    "vout": 0,
    "address": "tb1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvsfuejza",
    "label": "",
    "scriptPubKey": "001435cd4402887765c57eef09a61f0033ae8f4c3990",
    "amount": 0.00001000,
    "confirmations": 1,
    "spendable": true,
    "solvable": false,
    "parent_descs": [
      "addr(tb1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvsfuejza)#h8rwjq0n"
    ],
    "safe": true
  }
]

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.