2

I'm having a hard time figuring out how to compute the balance of a given bitcoin address using only the standard RPC API. I would like to extend this logic to bitcoin clones as well so the solution should use standard API calls only (e.g. only calls listed here https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list )

Can you think of a way of doing this?

7

AFAIK, this can't be done in any reasonable way with Bitcoin Core and its derivatives.

The only way I know to do it with Bitcoin Core is to use importaddress or importmulti to add your address(es) to the wallet as watch-only, but this requires a full blockchain rescan in order to compute the balance. This takes several minutes to hours depending on the speed of your hardware.

(Note that the bitcoin.it link you gave is obsolete and only covers the API up to version 0.8, so you won't find these commands listed there.)

You'd need to use some other software that actually indexes all transactions in the blockchain by their receiving addresses. This is what a block explorer does, for instance.

We have had a lot of other questions similar to this, so maybe there are some suggestions there: https://bitcoin.stackexchange.com/search?q=get+address+balance

  • Using importaddress is a good idea! I don't mind doing a rescan because the address will not change often. Will I have problems when trying to spend bitcoins if there is an imported watch-only address in my wallet? – Paul Sep 7 '17 at 13:43
  • 1
    @Paul: Not that I know of. The wallet knows that the coins in the watch-only address don't belong to it, and it will ignore them when trying to spend coins. – Nate Eldredge Sep 7 '17 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.