Get address balance in Java

1

I'm a merchant that is currently developing program that I will use for receiving transactions for my business.

I would like my program to be able to check how much Bitcoin the address sending to me has. I have the entire blockchain downloaded to the computer.

Ideally I'd like something that works like this:

String address = "1PSxTeWTVgomscit2BoViZYKSc4QoyrmAk";
Double balance = blockChain.getBalance(address);

Is this possible? I am having a difficult time finding a way to do this using the blockchain stored on my computer. It seems like it would be fairly easy to do this just using blockchain.info's API, but I would like to keep the process contained on my computer.

Thanks in advance.

user2980492

Posted 2013-12-02T21:52:46.727

Reputation: 49

Addresses do not have balances, so expecting bitcoin core to give you this information is unreasonable.Guest 2014-08-23T02:02:26.433

@Guest While that's technically true, it's a very misleading thing to say.Nick ODell 2014-10-22T02:50:27.917

Answers

1

If the address is not in your wallet that is not possible with the current bitcoind RPC API. You have to either go through the blockchain calculating the balance of the address yourself (i.e. find the last transaction from that address or sum the payouts to the address) or use an online tool like blockchain.info as you mentioned.

Jori

Posted 2013-12-02T21:52:46.727

Reputation: 1 522

...or BlockTrail API or Chain API. Blockchain.info have been proving to be somewhat unreliable lately, so always good to be aware of the alternatives out there.

OACDesigns 2014-10-22T17:12:54.700

1

If you want to get balance by using address, then you should try :

BitcoinJSONRPCClient tr = new BitcoinJSONRPCClient();

tr.gettransaction("txnId");

It will give you the Balance and everything related to that particular address.

I hope this will help.

Pawan Tiwari

Posted 2013-12-02T21:52:46.727

Reputation: 121