<blockquote>
  <p>01 - how do I calculate the balance ?</p>
</blockquote>

<p>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.</p>

<p>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.</p>

<blockquote>
  <p>02 - do I need to combine the external and internal unspent amount ?</p>
</blockquote>

<p>Of course.</p>

CC BY-SA 4.0
2018-06-06T05:51:59.923Z
2018-06-06T05:51:59.923Z
Ava Chow
<p>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.</p>

<p>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.</p>

CC BY-SA 4.0
2018-06-06T02:54:25.700Z
2018-06-06T02:54:25.700Z
Raghav Sood
<p>I have a <strong>bitcoin cash</strong> xpub </p>

<ul>
<li>I can derive Internal and external addresses </li>
<li>I have a full node so I
can check each individual addresses</li>
</ul>

<h2>My Question</h2>

<p>01 - how do I calculate the balance ?</p>

<p>02 - do I need to combine the external and internal unspent amount ?</p>

<p>Please advice </p>

<bitcoin-cash><wallet-development>
Calculating the balance of xpub
f4r4
# Calculating the balance of xpub

(Asked by: username_0 on 2018-06-05)

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

**Tags:** bitcoin-cash, wallet-development


---

## 2 answers

### Answer by username_1 on 2018-06-06. Score: 0 | Accepted answer

> 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.


---

### Answer by username_2 on 2018-06-06. Score: 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.


---

