Eloise1988 / CRYPTOBALANCE

A library for importing ones balances, networth, staking, rewards, lending & farming rates, dex volume & fees, uniswap new pairs into Google spreadsheets
MIT License
149 stars 23 forks source link

ypub or xpub support for bitcoin addresses #22

Open SeanBannister opened 9 months ago

SeanBannister commented 9 months ago

When you perform a transaction with a bitcoin wallet using a Ledger device it changes your bitcoin address. The way to track your wallet balance is using your xpub or ypub address, is there any chance cryptobalance could add support for xpub or ypub to make it easier to track our balance?

Eloise1988 commented 9 months ago

xpub addresses work with cryptobalance. I'm not sure about ypub, I'd need an example to test it out.

SeanBannister commented 9 months ago

After testing a number of xpub addresses there seems to be a bug where some addresses return 0 and some don't? try this one for example: xpub661MyMwAqRbcG8Zah6TcX3QpP5yJApaXcyLK8CJcZkuYjczivsHxVL5qm9cw8BYLYehgFeddK5WrxhntpcvqJKTVg96dUVL9P7hZ7Kcvqvd

It has a balance of 0.00048356 BTC but when I run CRYPTOBALANCE it returns 0.

Eloise1988 commented 9 months ago

I'm uncertain why it returns a balance of 0.

I've checked several different explorers, and the only one I've found that provides a non-zero balance is https://www.blockchain.com/explorer.

I haven't come across any API that accurately provides the correct balance. Due to the limited number of examples available to me, it's challenging to comprehend fully. One possibility that occurred to me is that there might be numerous underlying addresses, and the API only loads a restricted list of addresses, possibly missing the one with the balance.

As a last resort, you could directly request the balance from https://www.blockchain.com/explorer/addresses/btc/bc1qn0q5m8v6h3weeruy5ewy0t7szj24elzs5eyyrd. This may not be a viable solution if you have frequent transactions, but it could work if your transactions are infrequent.

SeanBannister commented 8 months ago

I'm not familiar exactly with how bitcoin transactions work but when using a hardware Ledger wallet it seems to create a new address that your existing coins get transferred to every time you make a transaction. So I think you're correct in presuming this is due to multiple addresses belonging to the xpub and these APIs possibly not finding them.

SeanBannister commented 2 weeks ago

Started looking at this issue again, are you using Blockchain.info on the backend per chance? I found this info that they don't support new segwit xpub addresses: https://gist.github.com/matthewdowney/998e6cfc750d286b3e2cca1aac7ca0ed but there's a way around it.

Eloise1988 commented 5 days ago

This should be fixed now. Thank you.