<p>I want to avoid physically importing addresses into a wallet. I want to write a UTXO indexing system on a per-address basis.</p>
<p>I often wonder how a wallet can keep track of all of its addresses' UTXOs, seeing as transaction outputs can become spent and are therefore no longer spendable.</p>
<p>My concept, as it stands, is to record every <code>vout</code>, of an incoming transaction, against its corresponding address.</p>
<p>So now we have a database of addresses, each with a relation to some <code>txId</code> and <code>vout</code> index that holds the address.</p>
<p>From there, <a href="https://chainquery.com/bitcoin-cli/gettxout" rel="nofollow noreferrer">gettxout</a> can be used on each of an address's transactions corresponding to its <code>vout</code> index.</p>
<p>If <code>gettxout</code> responds empty the address's <code>vout</code> has been spent, so is not deemed spendable and does not contribute to calculating the address's balance.</p>
<p>If <code>gettxout</code> responds with a result, the address's <code>vout</code> remains unspent, so is spendable and contributes to the address's balance.</p>
<p>This would obviously only work for addresses where this indexing approach has been implemented. Is this a good idea?</p>
<p>TLDR; how would one go about building a custom index, on top of a Bitcoin node, to track UTXOs, belonging to addresses, given that any <code>vout</code> can become spent?</p>

CC BY-SA 4.0
2020-11-13T16:25:00.980Z
I might do a longer answer tomorrow when I have time, but you should look into how electrumx structures its data to allow for fast querying across the entire utxo set
Raghav Sood
CC BY-SA 4.0
2020-11-13T17:28:21.803Z
Looking forward to it.
Luka
<wallet><full-node><utxo><balance><wallet-development>
How to approach building a custom UTXO index on top of a full-node
Anonona
# How to approach building a custom UTXO index on top of a full-node

(Asked by: username_0 on 2020-11-13)

I want to avoid physically importing addresses into a wallet. I want to write a UTXO indexing system on a per-address basis.

I often wonder how a wallet can keep track of all of its addresses' UTXOs, seeing as transaction outputs can become spent and are therefore no longer spendable.

My concept, as it stands, is to record every `vout`, of an incoming transaction, against its corresponding address.

So now we have a database of addresses, each with a relation to some `txId` and `vout` index that holds the address.

From there, [gettxout](https://chainquery.com/bitcoin-cli/gettxout) can be used on each of an address's transactions corresponding to its `vout` index.

If `gettxout` responds empty the address's `vout` has been spent, so is not deemed spendable and does not contribute to calculating the address's balance.

If `gettxout` responds with a result, the address's `vout` remains unspent, so is spendable and contributes to the address's balance.

This would obviously only work for addresses where this indexing approach has been implemented. Is this a good idea?

TLDR; how would one go about building a custom index, on top of a Bitcoin node, to track UTXOs, belonging to addresses, given that any `vout` can become spent?

**Tags:** wallet, full-node, utxo, balance, wallet-development

> **Comments:**
> **username_1**: I might do a longer answer tomorrow when I have time, but you should look into how electrumx structures its data to allow for fast querying across the entire utxo set  
> **username_2**: Looking forward to it.  

---

## 0 answers

