Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to monitor HD wallet balance using only xpub (watch mode) #673

Closed
sulliwane opened this issue Jan 23, 2019 · 7 comments
Closed

Comments

@sulliwane
Copy link

Hello,

I was wondering what is the easiest way to monitor a wallet whole balance having only the wallet xpub key (implementing a simple watch service) without having to maintain my own bitcoin node.

Any recommendation on this, using bcoin?

Many thanks!

@pinheadmz pinheadmz added the help wanted User has a question, not critical label Jan 23, 2019
@pinheadmz
Copy link
Member

pinheadmz commented Jan 23, 2019

You can run a pruned node or an SPV node. (Soon we will have Neutrino client available as well!)

Pruned node: bcoin --prune Only keeps the last 288 blocks on disk, so some operations are limited like big wallet rescans, but most API calls still work. Still needs to sync the entire blockchain. And because rescans are impaired, if you are importing an xpub with transaction history already on chain, you need to be sure you create your wallet BEFORE the node gets to those transactions. Otherwise you will not be able to discover them, because the blocks will no longer be on disk.

SPV node: bcoin --spv Only stores block headers, not full blocks. It's a compromise for security and privacy because you rely on other full nodes on the network to validate the chain and serve your wallet data, but there is still a good deal of verification. Mainnet SPV sync takes a fraction of the time (like on the scale of an hour, as opposed to multiple days).

Once you have a node running you can create a watch-only wallet and import your xpub.
See http://bcoin.io/api-docs/#create-a-wallet

bwallet-cli mkwallet --id=<wallet name> --account-key=<xpub...> --watch-only=true

Then you can query the wallet any time (lots more at https://bcoin.io/api-docs)

bwallet-cli --id=<wallet name> history
bwallet-cli --id=<wallet name> balance

...etc

Let me know if this helps. If you really want to run a wallet without any network at all, the wallet is a separate module and can be run without a node, but you wouldn't be able to get its balance or tx history, just generate addresses basically.

@sulliwane
Copy link
Author

Ok got it. I will consider --prune and --spv options! Thank you very much for you feedback on this.

@tynes
Copy link
Member

tynes commented Jan 23, 2019

There are socket events that are also useful for this, so that you can get live updates of when you receive a transaction

@sulliwane
Copy link
Author

Thanks for your anwsers. @pinheadmz I'm wondering if when running in --prune mode I will have to rescan when in the case you described above (adding wallet after its transactions).

Also, how slower is prune compared to spv ? Thanks !

@pinheadmz
Copy link
Member

In prune mode you can only rescan as many blocks as you have on disk, which is only two days worth. Actually now it is a dangerous unchecked situation, I have a PR to return an error: #532

Prune takes as long as Full - it must download and verify the entire blockchain. SPV is very fast (less than hour depending on your machine)

If you want to describe more the application you are building here or on slack, I might have more ideas for you

@braydonf braydonf removed the help wanted User has a question, not critical label May 16, 2019
@JoePotentier
Copy link

Hey, I'm creating a watch-only wallet with a full node.

If I'm only given an xpub and the user of this wallet is generating receiving addresses in their private wallet. Will bcoin be able to detect transactions that are outside of the "account depth" of the wallet?

I want to use the sockets API to be alerted when transaction occur in the wallet. But my impression is that we will have to create some mechanism that guarantees that any receiving address the end-user has generated is within the account depth index. Is this correct?

@pinheadmz
Copy link
Member

pinheadmz commented Mar 30, 2021

@JoePotentier For each account, bcoin has a lookahead value of 10:

this.lookahead = 10;

So if the user generates more than 10 addresses without receiving any transactions then yes, potentially the watch only wallet will fall behind. If the user actually receives TXs on the blockchain within that window, your watch-only wallet will be able to keep up.

If you think the user might end up large gaps in the BIP32 account, you may want to pre-derive more addresses on your side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants