Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: shark255 on September 09, 2014, 08:57:14 PM



Title: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: shark255 on September 09, 2014, 08:57:14 PM
Question:

There is getreceivedbyaddress, but there is no command to get current balance of address.

Is there any workarounds ?




Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: AltcoinInvestor on September 09, 2014, 10:39:22 PM
did you named btc address?
if you request "getbalance name" it returns.

also this returns satoshi: https://blockchain.info/q/addressbalance/13qVUetqX6ZWLyEaYAwd8its5m64Bm1SaP


Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: shark255 on September 09, 2014, 10:41:37 PM
I mean using local server bitcoind, sure blockchain.info has more possibilities.


Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: shorena on September 10, 2014, 07:42:25 AM
I mean using local server bitcoind, sure blockchain.info has more possibilities.


you could use listunspend and filter by address.


Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: deepceleron on September 10, 2014, 10:41:19 AM
The problem with such a command is it wouldn't work the way you would expect:

1. someone sends my 1DCeLERon address 5 BTC
2. i send 1 BTC to my friend
3. the balance of my 1DCeLERon address is 0 BTC

This is because if the 5 BTC is the only money in my wallet, the remainder 4 BTC is sent back to a different address in my wallet as change. If I get paid another 5 BTC to the same address again, I have 5 BTC in that address and 4 BTC in the other.

This is why Bitcoin gives you a wallet balance, not an address balance. It is also why looking up an address on a blockchain explorer site will confuse noobs. These sites can't tell if the 4 BTC or the 1 BTC is change back to you, or even if they are both payments to other parties.

I mean using local server bitcoind, sure blockchain.info has more possibilities.


you could use listunspend and filter by address.
The RPC command is "listunspent". I have 24 addresses with a balance in my current wallet just used for personal testing, and that is even after sending some money back to myself to consolidate it. What one entry from this command looks like, btw:



Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: shark255 on September 10, 2014, 11:32:54 AM
Thanks!
Got it and tested it. One thing, that I must walk through all elements of listunspent result to get balance for particular address.



Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: shark255 on September 10, 2014, 07:07:15 PM
And I think it would be better if listunspent could return in associative array a time of transaction.
Because again, I need to loop through another array and call gettransaction for each txid.


Title: Re: How to get current balance of address with bitcoind or maybe not bitcoind?
Post by: Miitch on September 11, 2014, 08:07:05 PM
I found these problems too when working with bitcoind - it's really a bit of a pain to work with. I appreciate that Bitcoin works the way that bitcoin works. But it makes developing Bitcoin applications much slower than it could be for people new to working with it.