What's default derive path for `getnewaddress`? #13302

issue dancju opened this issue on May 22, 2018
  1. dancju commented at 7:55 AM on May 22, 2018: none

    <!-- Describe the issue -->

    <!--- What behavior did you expect? -->

    From a same private key I got different derived address from bitcoin-cli and my own code. I am wondering what mistakes I made.

    I created a HD wallet (under BIP49) and generated a derived address from this piece of code,

    const btc = require('bitcoinjs-lib');
    const btc_prv = btc.HDNode.fromSeedBuffer(seed).derivePath("m/49'/0'/0'");
    const btc_pub = btc_prv.neutered();
    const btc_prv0 = btc_prv.derivePath("0/0");
    const btc_pub0 = btc_pub.derivePath("0/0");
    const btc_add0 = btc.address.fromOutputScript(btc.script.scriptHash.output.encode(btc.crypto.hash160(btc.script.witnessPubKeyHash.output.encode(btc.crypto.hash160(btc_pub0.getPublicKeyBuffer())))));
    console.log("private WIF  : "+btc_prv.keyPair.toWIF());
    console.log("public key   : "+btc_pub.getPublicKeyBuffer().toString('hex'));
    console.log("private WIF 0: "+btc_prv0.keyPair.toWIF());
    console.log("public key  0: "+btc_pub0.getPublicKeyBuffer().toString('hex'));
    console.log("address     0: "+btc_add0);
    

    and got this output.

    private WIF  : L4R...
    public key   : 036124c83be4781cf7294a4d200c49d8161535f1fb5b4bdfef07d282d3219d81b4
    private WIF 0: Kxf...
    public key  0: 0259dcde34aa3cc5c4949bfdd8a35d189db40db3706b82f0879ba52b69be28f2f9
    address     0: 36H1KVwD1BuLPFaNGDDnAwLP8vPNTak71R
    

    Importing this private key into bitcoin-cli and generating derived key from

    bitcoin-cli --version
    bitcoin-cli importprivkey L4R... "" false
    bitcoin-cli getnewaddress
    

    , yields

    Bitcoin Core RPC client version v0.16.0.0-g4b4d7eb255
    38jrZ3ojUPvxbhG8pzqVSNae1MgmVVsMHd
    

    . Why did I get different addresses? What is the algorithm behind getnewaddress? Can I generate address from custom derive path?

    <!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

    <!--- How reliably can you reproduce the issue, what are the steps to do so? -->

    <!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

    <!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

    <!-- Any extra information that might be useful in the debugging process. -->

    <!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->

  2. dancju renamed this:
    Whats default derive path for `getnewaddress`?
    What's default derive path for `getnewaddress`?
    on May 22, 2018
  3. MarcoFalke commented at 10:34 AM on May 22, 2018: member

    sethdseed will be in the next release of Bitcoin Core 0.17.0

  4. achow101 commented at 3:55 PM on May 22, 2018: member

    You are using importprivkey entirely incorrectly. importprivkey does not set an HD seed for keys to be derived from. Yet you are trying to import the private key that you use as the HD seed. importprivkey directly imports a private key to be used, no derivation happens with the key and the only transformation is to generate its address. Furthermore, importprivkey does not effect getnewaddress at all. You will not get imported private keys in getnewaddress and importing a private key does not change how new addresses are created.

    To see the address that you want, you have to import its private key, not the private key of its parents. So you should have imported btc_prv0. You can then see that it imported successfully by using getaddressesbyaccount (or getaddressesbylabel if using the master branch).

  5. dancju commented at 3:34 AM on May 23, 2018: none

    @achow101 @ldenman thank you so much for replying! Is BIP32, BIP44, or BIP49 supported by bitcoin-cli?

  6. achow101 commented at 5:47 AM on May 23, 2018: member

    Bitcoin Core supports BIP 32. Keys are derived with the derivation path m/0'/0'/i'

  7. dancju closed this on May 23, 2018

  8. dancju commented at 4:45 PM on May 23, 2018: none

    @achow101 do you mean getnewaddress derives sub-keys with path m/0'/0'/i' and generates segwit addresses with BIP142? Where can I find corresponding official document?

  9. achow101 commented at 5:49 PM on May 23, 2018: member

    do you mean getnewaddress derives sub-keys with path m/0'/0'/i'

    Yes.

    generates segwit addresses with BIP142?

    No. Segwit addresses use BIP 173. BIP 142 is superceded by BIP 173.

    Where can I find corresponding official document?

    There is none.

  10. dancju commented at 6:50 PM on May 23, 2018: none

    @achow101 BIP173 addresses start with bc1, while getnewaddress generates addresses start with 3.

  11. sipa commented at 6:54 PM on May 23, 2018: member

    Please take this discussion to https://bitcoin.stackexchange.com or some other forum. This is not an issue with Bitcoin Core's code.

  12. dancju commented at 2:11 AM on May 24, 2018: none

    @sipa I had no idea about that! Where is the source code of bitcoin-cli?

  13. sipa commented at 2:13 AM on May 24, 2018: member

    @nerdDan You're on the repository with that source code. Now, please, take this question elsewhere.

  14. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me