private key import – How do I use descriptors to put an ancient priv-key into a newly created wallet.dat file?


    Running bitcoin core 26.0 on debian 12. I want to put an ancient priv-key into a newly created wallet.dat file. First, I’ll do a test run:

    $ bitcoin-cli createwallet test
    $ bitcoin-cli loadwallet /home/user/.bitcoin/wallets/test/

    This wallet.dat exists only for testing purposes and will be deleted shortly. Before it’s deleted though, and strictly for testing only, I want to put the priv-key revealed on

    priv-key= 5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF
    corresponding address= 1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj

    … into this test-only wallet.dat file. This particular priv-key is of course here only as a place-holder; nobody in their right mind would want this priv-key anywhere near a live wallet.dat file.

    $ bitcoin-cli getdescriptorinfo 'combo(5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF)'
      "descriptor": "combo(04588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9f88ff2a00d7e752d44cbe16e1ebcf0890b76ec7c78886109dee76ccfc8445424)#nf3atn7u",
      "checksum": "qlt7uqzu",
      "isrange": false,
      "issolvable": true,
      "hasprivatekeys": true
    $ bitcoin-cli importdescriptors '[{"desc":"combo(5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF)#qlt7uqzu","timestamp":"now"}]'
        "success": true

    … so that priv-key should be in the wallet.dat now, so I do a quick test:

    $ bitcoin-cli getaddressinfo 1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj
      "address": "1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj",
      "scriptPubKey": "76a9147ac00f979ff0df2fdcb65761dc8f9ef8b37142db88ac",
      "ismine": true,
      "solvable": true,
      "desc": "pkh([7ac00f97]04588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9f88ff2a00d7e752d44cbe16e1ebcf0890b76ec7c78886109dee76ccfc8445424)#yyv2g3h5",
      "parent_desc": "combo(04588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9f88ff2a00d7e752d44cbe16e1ebcf0890b76ec7c78886109dee76ccfc8445424)#nf3atn7u",
      "iswatchonly": false,
      "isscript": false,
      "iswitness": false,
      "pubkey": "04588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9f88ff2a00d7e752d44cbe16e1ebcf0890b76ec7c78886109dee76ccfc8445424",
      "iscompressed": false,
      "ischange": false,
      "timestamp": 1231006505,
      "hdkeypath": "m",
      "hdseedid": "0000000000000000000000000000000000000000",
      "hdmasterfingerprint": "7ac00f97",
      "labels": [

    … so that looks good. Next thing is to rescan the blockchain, wait a few hours, and the btc controlled by that priv-key (likely an amount equal to zero in this case, obviously!) should be available to be spent by the bitcoin core client after the rescan is done.

    Did I miss anything out? If I use this method to put a priv-key that controls a non-zero btc value into a live wallet.dat file, will I be able to use that wallet.dat file in bitcoin core 26.0 to spend the btc?


    Source link

    Leave a Reply

    Your email address will not be published. Required fields are marked *