0

I have a bitcoin cash xpub

  • I can derive Internal and external addresses
  • I have a full node so I can check each individual addresses

My Question

01 - how do I calculate the balance ?

02 - do I need to combine the external and internal unspent amount ?

Please advice

f4r4
  • 181
  • 10

2 Answers2

0

Regular nodes, by default, only maintain a balance tally for addresses in its own wallet. Your options are to either add every address to the wallet as a watch-only address, or to build your own index on top of the node by scanning each block and extracting the data from it.

There are patched versions of nodes available, such as the ones backing insight explorers, that also maintain an address index to speed explorer operations up. However, these versions are rarely up to date.

Raghav Sood
  • 16,869
  • 3
  • 21
  • 42
0

01 - how do I calculate the balance ?

You will need to scan the entire blockchain and look for outputs that send coins to your addresses and inputs that spend outputs that sent coins to your addresses. For each output, you add its value. For each input, you subtract the value of the output it spends.

With a Bitcoin Core based software such as Bitcoin ABC, you would have to import every single address that you derived into the wallet so that it can scan the blockchain and perform this task for you. Otherwise you will need to use some other software that works on top of your node which can perform this task. Bitcoin Core based software cannot do this automatically for you without adding the addresses to a wallet. Furthermore, you cannot import the xpub itself into Bitcoin Core based software, you will need to import each address individually.

02 - do I need to combine the external and internal unspent amount ?

Of course.

Andrew Chow
  • 67,209
  • 5
  • 76
  • 149