<p>For hierarchical deterministic wallets this is usually solved with a &quot;gap limit&quot;. It means that when restoring from a recovery seed (or similar backup) the wallet will start checking for addresses until it finds a long enough run (e.g. 100) of unused addresses, and then it assumes that's all there is. Conversely, the wallet should not allow you to generate more than this number of addresses ahead of use, or at least display a warning that it might later prevent the wallet from discovering your funds.</p>
<p>Checking if an address is unused cannot be done with the UTXO set alone, because knowing that the address doesn't have a UTXO associated with it doesn't mean it never had. You need to store the entire blockchain, preferably in a way to allow efficient lookup of transactions associated with a specific address. Most hierarchical deterministic wallets delegate this task to an external service.</p>

CC BY-SA 4.0
2021-12-29T16:13:46.333Z
2021-12-29T16:13:46.333Z
Vojtěch Strnad
<p>I think I understand how the UTXO model works, the inputs, and outputs, etc. However, one thing I am still having a hard time still, is understanding how balance is calculated from a seed or xkeys.</p>
<p>If you were to create a new receiving address for each transaction, then wouldn't that mean that in order to check your entire balance you have to go through every single address that could be generated from the derivation path of your keys? If so, how would that be efficient at all?</p>
<p>Also, as far as I know, every node keeps a dataset of all the UTXOs. But in order to check for your balance, wouldn't you still need to check the whole dataset for every possible address you could generate?</p>
<p>Thanks in advance!</p>

<full-node><utxo><balance><seed>
Bitcoin UTXO Balance Checking
Sontiac
# Bitcoin UTXO Balance Checking

(Asked by: username_0 on 2021-12-29)

I think I understand how the UTXO model works, the inputs, and outputs, etc. However, one thing I am still having a hard time still, is understanding how balance is calculated from a seed or xkeys.

If you were to create a new receiving address for each transaction, then wouldn't that mean that in order to check your entire balance you have to go through every single address that could be generated from the derivation path of your keys? If so, how would that be efficient at all?

Also, as far as I know, every node keeps a dataset of all the UTXOs. But in order to check for your balance, wouldn't you still need to check the whole dataset for every possible address you could generate?

Thanks in advance!

**Tags:** full-node, utxo, balance, seed


---

## 1 answers

### Answer by username_1 on 2021-12-29. Score: 2

For hierarchical deterministic wallets this is usually solved with a "gap limit". It means that when restoring from a recovery seed (or similar backup) the wallet will start checking for addresses until it finds a long enough run (e.g. 100) of unused addresses, and then it assumes that's all there is. Conversely, the wallet should not allow you to generate more than this number of addresses ahead of use, or at least display a warning that it might later prevent the wallet from discovering your funds.

Checking if an address is unused cannot be done with the UTXO set alone, because knowing that the address doesn't have a UTXO associated with it doesn't mean it never had. You need to store the entire blockchain, preferably in a way to allow efficient lookup of transactions associated with a specific address. Most hierarchical deterministic wallets delegate this task to an external service.


---

