By default, what is maintained by the 0.8 blockchain engine is:
- All blocks
- A database with all block headers, and the positions on disk for each block
- A database that represents all unspent transaction outputs (UTXOs), indexed by txid, at the current tip of the block chain
- Undo files that allow rewinding the effects of blocks on this set of UTXOs.
Nothing related to addresses or balances exists at this level. That is just a client-side representation of the data. The balance of a wallet is the sum of the values of the UTXOs that are spendable with the set of keys in the wallet. You could define the balance of an address as the sum of the values of the UTXOs assigned to a script matching a given address (and this is what several sites do), but presenting it this way is quite confusing - it makes many people think that Bitcoin transactions transfer value from one address to another. This is not true, they consume specific outputs of a previous transaction, and merge and split those into new outputs.
The -txindex option you mention, adds one more thing that is maintained by the validation engine:
- A database with the positions on disk for each transaction, indexed by txid.
This was added to make the getrawtransaction command work with historical transactions, but again, this has nothing to do with addresses. A database that indexes the UTXO set by address, or even the entire block chain history by address would be possible, but it would be relatively expensive to maintain, and shouldn't be necessary for normal operations (though it is quite useful for debugging...).
Where such things do belong, is in the wallet. The wallet as presented by the reference client does not use "balance of an address" - it rather sees addresses as entry points into the wallet, but manages the coins in the entire wallet together, regardless of what address they were last sent to. This also confuses people who are used to look at blockexplorer-like websites, when they realize that for example change is always sent to a fresh address.
So, to give a real answer: if you really want to track a balance, you need the wallet interface. Right now, this is quite unflexible, but there are plans to improve this situation soon. We'll hopefully soon get support for multiple wallets, and watch-only wallets, where you can just add addresses you'd like to track, without having their keys.
While I don't know the answer to your question, I would like to point out that
txindexis not relevant here, as the client does not need the full index to get the balance for any given address. – Tom van der Woerdt – 2013-04-22T14:24:17.220I thought it might, but indeed it doesn't seem to be so. – Steven Roose – 2013-04-22T15:26:40.357
found any solution ? – coding_idiot – 2014-02-25T06:34:51.187
@coding_idiot It's not possible (intentionally) to query for any information using bitcoind. It only maintains an index for transactions that are relevant for your wallet. – Steven Roose – 2014-02-26T12:05:13.317
You can use api of some bitcoin exploer like https://api.blockcypher.com/v1/btc/main/addrs/38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa. There is also some opensource exploer like https://github.com/blockcypher/explorer
– Kris Roofe – 2018-04-02T02:58:16.270