3

I am looking for an open source script or application which would take a private wallet key from the user (from terminal input or file, as mnemonic or xpriv string) and then connect to a bitcoind and output all UTXOs which are owned (spendable) by that key. Does something like that exist?

3 Answers 3

3

You can import a descriptor composed of the xpriv(s) (or xpub(s) if you just want to watch the coins) to the bitcoind wallet, and then rescan the block chain for transactions involving derived key up to a configured gap limit.

For importing the descriptor, use the importmulti RPC call in versions <0.21 and the importdescriptors RPC as of 0.21 (upcoming).

Both calls allow you to pass a creation timestamp in order to rescan the block chain from this point. You can otherwise manually call rescanblockchain.
Note that, depending on the number of blocks you are scanning, it will take some time. You can monitor the progress in your debug.log.

1
  • Thanks, I will look into that. Initially, I wanted to avoid using bitcoind wallet and was looking for a lightweight solution which would construct a set of HD wallet PKHs and scan the full UTXO database for matches (even though that's not part of bitcoin core api, it can be done locally)
    – DeLorean88
    Jan 12, 2021 at 21:18
2

This python library comes close (disclaimer: I wrote it). It supports HD wallets via mnemonic or xprv and you can query outputs of addresses however it queries a block explorer for the outputs instead of bitcoind (you can probably tweak the code to replace the API call with an rpc call)

1
  • Looks interesting, but I didn't see the described functionality in the examples. I also specifically wanted to do everything locally and avoid queries to a 3rd party
    – DeLorean88
    Jan 13, 2021 at 4:19
1

You can avoid risking exposing your private keys and just check the addresses with scanutxooutset in the console or via JSON-RPC. Although it takes a few minutes, you don't have to wait for a full rescan and it's easy to get all UTXOs for any address or even xpub and it doesn't have to already be in your wallet like when importing keys.

Example in the console:

scantxoutset start '[{"desc":"addr(1SomeAddress)"},{"desc":"addr(1AnotherAddressToCheck)"}]'

or checking xpubs would look something like this:

scantxoutset start '[{"desc":"pkh(xpubMyXpubToCheck)"}]'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.