Post
Topic
Board Bitcoin Technical Support
Merits 70 from 10 users
Re: Gross btc in bitcoin core from multiple wallet files
by
nc50lc
on 20/05/2022, 05:48:42 UTC
⭐ Merited by LoyceV (42) ,ETFbitcoin (5) ,BlackHatCoiner (4) ,o_e_l_e_o (4) ,hugeblack (4) ,hosseinimr93 (4) ,NotATether (3) ,Husna QA (2) ,ajaxtempest (1) ,DdmrDdmr (1)
Each wallet.dat file shows the btc amount but is there any way the bitcoin core shows gross btc of all the wallets that have been connected?
Just to be clear, since you're using BWT plugin in, are the "connected wallets" from Electrum?

If so, then it's doable using this workaround: Create a "blank descriptor wallet" that will hold all of the wallet's master public keys.
Importing each xpub key via "descriptor" can be time consuming but after setting it up, that specific wallet.dat will be able see all of the imported master keys' transactions and total their balances.

These are the steps:
  • In Electrum, get the "Master Public Key" of the wallet that you want to import in "Wallet->Information".
  • For Native SegWit and P2SH-SegWit wallets, you'll have to convert the zpub or ypub into xpub to be compatible with Bitcoin core
    using the console command ("View->Show Console" to enable console tab):
    convert_xkey(xkey="zpub6YBr.....XXZ3DysZgsPX",xtype="standard")
  • With the xpub, create a parent descriptor by following this format:
    For P2WPKH (receiving):        "wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./0/*)"
    For P2WPKH (change):           "wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./1/*)"

    For P2PKH (receiving):         "pkh([00000000/0]xpub....YOUR_XPUB_KEY......./0/*)"
    For P2PKH (change):            "pkh([00000000/0]xpub....YOUR_XPUB_KEY......./1/*)"

    For P2SH-P2WPKH (receiving):   "sh(wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./0/*))"
    For P2SH-P2WPKH (change):      "sh(wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./1/*))"
    If your Electrum wallet is Native SegWit (P2WPKH), create P2WPKH receiving and change address descriptors.

  • Get its checksum by using Bitcoin Core's console, use the command getdescriptorinfo

    For example: getdescriptorinfo "wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./0/*)"

    Take note of the "checksum" among the results.

  • Now, it's ready to be imported to Bitcoin Core.
    Create a new blank wallet in Bitcoin Core by ticking the boxes: "Disable Private Keys", "Make Blank Wallet" and "Descriptor Wallet".

  • After creating the wallet, go to Bitcoin Core's Console (Window->Console), select the newly created wallet from the drop-down menu above.

  • Then import the descriptor by using this command:
    For receiving addresses:
    importdescriptors "[{\"desc\": \"wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./0/*)#2r29ev5v\",\"timestamp\": \"now\",\"watching-only\": true,\"internal\": false,\"range\": [0,999]}]"

    For change addresses:
    importdescriptors "[{\"desc\": \"wpkh([00000000/0]xpub....YOUR_XPUB_KEY......./1/*)#mh0yyey5\",\"timestamp\": \"now\",\"watching-only\": true,\"internal\": true,\"range\": [0,999]}]"
    The example checksum are "2r29ev5v"  and "mh0yyey5" that are next to the descriptors; the only difference is "internal" flag, it's set to 'true' for change address; and lastly you might need to increase the end range depending on the wallet's usage.

  • Just repeat that to each of the connected Electrum's master public key.