importmulti with BIP84 derivation always fails

0

I have been trying to test importmulti with BIP84 derivation like so:

bitcoin-cli -rpcwallet=BIP84Test importmulti '[{ "desc": "wpkh([18734cbe/84'/0'/0']xpub6AC5B4KkrtMkXmzUWAiVVYWvhzwMJDX46ZJhm2tusm7SPc2KjeSqwEjLTaB8vAo7ev3zUFbGdWcX3EMy1ZQ9JxDgpc1pzBGLVpftq84naq5/0/*)#shfp59jm", "timestamp": "now", "range": [0, 99], "watchonly": true, "label": "Fully Noded Cold Storage", "keypool": true, "internal": false, "rescan": false }]'

But I always get an error:

-bash: syntax error near unexpected token `)'

I have tried replacing [18734cbe/84'/0'/0'] with [18734cbe/84h/0h/0h]

and [18734cbe/84\'/0\'/0\']

But it all returns errors. Is there anything obvious I am doing wrong?

I get the descriptor from getdescriptorinfo

EDIT:

Here is the fix which is working:

First get the descriptor using getdescriptorinfo then:

var descriptor = "\"\(result["descriptor"] as! String)\""

                descriptor = descriptor.replacingOccurrences(of: "4'", with: "4'\"'\"'")
                descriptor = descriptor.replacingOccurrences(of: "0'", with: "0'\"'\"'")

bitcoin-cli -rpcwallet=NewTest importmulti '[{ "desc": "wpkh([18734cbe/84'"'"'/0'"'"'/0'"'"']xpub6AC5B4KkrtMkXmzUWAiVVYWvhzwMJDX46ZJhm2tusm7SPc2KjeSqwEjLTaB8vAo7ev3zUFbGdWcX3EMy1ZQ9JxDgpc1pzBGLVpftq84naq5/0/*)#jun2ynxt", "timestamp": "now", "range": [0, 99], "watchonly": true, "label": "Fully Noded Cold Storage", "keypool": true, "internal": false }]' '{"rescan": false}'

result = (
        {
        success = 1;
    }
)

Very hacky but it works :)

Fontaine

Posted 2019-06-21T06:42:51.103

Reputation: 158

Answers

3

The issue is that your hardened paths use the single quote notation which breaks the single quoting that surrounds the entire import command. You will need to escape those properly, and \' is not the way to do that. Instead, for every single quote within your import command, you need to do '"'"' - an explanation for why can be found here.

Alternatively, you can change those single quotes to h, but once you do so, you will need to recompute the descriptor checksum. But iff you give such a descriptor to getdescriptorinfo it will give you back the descriptor with single quotes (there is a pull request open to fix this) so you will need to use an external checksum tool to do this. I have a python script which can do this.

Running your descriptor with h instead of ' through that script, I get:

wpkh([18734cbe/84h/0h/0h]xpub6AC5B4KkrtMkXmzUWAiVVYWvhzwMJDX46ZJhm2tusm7SPc2KjeSqwEjLTaB8vAo7ev3zUFbGdWcX3EMy1ZQ9JxDgpc1pzBGLVpftq84naq5/0/*)#rxk7wl9c

Andrew Chow

Posted 2019-06-21T06:42:51.103

Reputation: 40 910

amazing, thank you yet again. Editing OP to show working code for anyone else who is tryingFontaine 2019-06-22T01:52:46.693