Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: crypt0mancien on March 31, 2024, 12:55:37 PM



Title: Import address from Sparrow to Bitcoin Core
Post by: crypt0mancien on March 31, 2024, 12:55:37 PM
Hello,

I have many problems with Bitcoin Core.

I want to create a blank wallet in Core then import a set of address/descriptors from Sparrow.

I'm able to import descriptors with private key.

```RPC
{
  "jsonrpc": "1.0",
  "id": "curltest", 
  "method": "importdescriptors",
  "params": [
    [
      {
        "internal": true,
        "timestamp": 'now',
        "desc": "tr(tprv...rest...of...key)#checksum"
      }
    ]
  ]
}
```
Response is success: true.

For now I can track my taproot address with Core.


The problem is I can't send fund.

I try the command send, sendtoaddress, sendmany, the error is:
Transaction needs a change address, but we can't generate it. Error: No bech32 addresses available.


So I try to generate a change address like this:
```RPC
"method": "getrawchangeaddress",
  "params":
  ["bech32"]
```
Result: Error: This wallet has no available keys

So I try to import keys with importmulti, sethdseed, importprivkey.
Result: Only legacy wallets are supported by this command

Bitcoin Core version: latest 26.

Need help.
Thanks a lot


Title: Re: Import address from Sparrow to Bitcoin Core
Post by: Forsyth Jones on April 01, 2024, 02:58:55 AM
It seems to me that you imported the descriptor without activating the descriptor that you intend to use only for receiving,

Basically you didn't include the "active":true argument in the descriptor for receiving and you also didn't include the argument: "internal":true in the descriptor you want for change addresses.

I assume you already know how to import the descriptor, so I'll skip the part on how to assemble a descriptor and get the checksum.

In the receive descriptor, you must include the argument: "active":true, in the change descriptor you must include both: "active":true,"internal":true. I'll leave the examples below and bold them to indicate what was missing in your descriptor. My example is in the console gui.

Descriptor you would use to receive: importdescriptors '[{"desc":"tr(your_xpriv/86h/0h/0h/0/*)"#checksum","timestamp":"now","active":true}]'

Code:
importdescriptors '[{"desc":"tr(your_xpriv/86h/0h/0h/0/*)"#checksum","timestamp":"now","active":true}]'

change descriptor: importdescriptors '[{"desc":"tr(your_xpriv/86h/0h/0h/1/*)"#checksum","timestamp":"now","active":true,"internal":true}]'

Code:
importdescriptors '[{"desc":"tr(your_xpriv/86h/0h/0h/1/*)"#checksum","timestamp":"now","active":true,"internal":true}]'

As for the "importmulti, sethdseed, importprivkey" commands, they only work on legacy wallets, as the error statement says.


Title: Re: Import address from Sparrow to Bitcoin Core
Post by: nc50lc on April 01, 2024, 06:02:29 AM
       "internal": true,
        "timestamp": 'now',
        "desc": "tr(tprv...rest...of...key)#checksum"

Response is success: true.
That worked but you basically imported a single change address (internal) derived directly from the private key part of the provided "extended private key" (tprv).
And it looks like that originated in your setup in Sparrow since you've mentioned that you can track it with that "weird" descriptor.

Take note that the instructions above must be done in order for the the commands that require change address to work.
But it will only work on "ranged descriptors" as you can see in his examples; with "derivation path", and "range" arg (defaults to 0,999 if not set).

With that, you should create a proper ranged descriptor in Sparrow and import it to Bitcoin Core.

If you want to keep using the setup, you can still use send command by providing the named argument: "change_address" when sending bitcoins.
Example:
Code:
./bitcoin-cli --named send outputs='{"<recipient address>": 0.001}' change_address=<your address>
Only with send command specifically and not the other three "send" wallet commands.


Title: Re: Import address from Sparrow to Bitcoin Core
Post by: crypt0mancien on April 01, 2024, 02:53:21 PM
Thanks 1000 times  :)