<p>I can offer you the workaround for this problem. I used web API for this feature. For example <a href="https://www.blockcypher.com/dev/bitcoin/#address-balance-endpoint" rel="nofollow noreferrer">https://www.blockcypher.com/dev/bitcoin/#address-balance-endpoint</a>.</p>

<p>It will allow you refuse block chain downloading part and make your code more simple.</p>

CC BY-SA 3.0
2017-08-04T07:36:26.803Z
Thanks @Konstantin ,But I need it this way "using bitcoinj" as mentioned
sano143
CC BY-SA 3.0
2017-08-04T07:29:57.743Z
2017-08-04T07:29:57.743Z
Konstantin Shmelev
<p>I can get my bitcoin balance from private key but when i tried retrieving from my address its not possible posted below my code can any one tell me what i'm doing wrong</p>

<pre><code>public static void main( String[] args )

        {
            NetworkParameters params = TestNet3Params.get();
            WalletAppKit kit = new  WalletAppKit(params, new File("."), "sano");
            kit.start();
            kit.isRunning();
            Address address = new Address(params, "mj255GgoGKN6uTjtWdNcF7obu88iLSTZdm");
            boolean add =kit.wallet().isAddressWatched(address);
            Wallet wallet = new Wallet(params);
            DumpedPrivateKey key = new DumpedPrivateKey(params,
                   "cTH6YyRZSqF8VvtjkfqABqjGF682cQkW3mMuageraH4CEzCrweqT");
            wallet.addKey(key.getKey());
            wallet.addWatchedAddress(new Address(params, "mj255GgoGKN6uTjtWdNcF7obu88iLSTZdm"));
            BlockChain chain = new BlockChain(params, wallet,
                   new MemoryBlockStore(params));
         PeerGroup peerGroup = new PeerGroup(params, chain);
         peerGroup.addPeerDiscovery(new DnsDiscovery(params));
         peerGroup.addWallet(wallet);
         peerGroup.start();
         peerGroup.downloadBlockChain();
         BigInteger balance = wallet.getBalance();
         System.out.println("Wallet balance: " + balance);
}
</code></pre>

<p>Edit 1: The below given code retrieves balance from address but each and everytime it is creating a new address.</p>

<pre><code>public static void main(String[] args) {

    NetworkParameters params = TestNet3Params.get();

    String filePrefix = "forwarding-service-testnet";

    WalletAppKit kit = new WalletAppKit(params, new File("."), filePrefix);

    // Download the block chain and wait until it's done.
    kit.startAsync();
    kit.awaitRunning();

    List&lt;Address&gt; list = kit.wallet().getWatchedAddresses();
    if (list.size() &lt; 2) {
        kit.wallet().addWatchedAddress(kit.wallet().freshReceiveAddress());
        System.out.println("New address created");
    }

    System.out.println("You have " + list.size() + " addresses!");
    for (Address a: list) {
        System.out.println(a.toString());
    }

    String balance = kit.wallet().getBalance().toFriendlyString();
    System.out.println(balance);
}
</code></pre>

CC BY-SA 3.0
2017-08-04T08:54:04.663Z
@alcio I did check that one but still I'm not getting my balance
sano143
<address><bitcoinj><balance>
getting balance from my address using bitcoinj
sano143
# getting balance from my address using bitcoinj

(Asked by: username_0 on 2017-08-04)

I can get my bitcoin balance from private key but when i tried retrieving from my address its not possible posted below my code can any one tell me what i'm doing wrong

```
public static void main( String[] args )

        {
            NetworkParameters params = TestNet3Params.get();
            WalletAppKit kit = new  WalletAppKit(params, new File("."), "sano");
            kit.start();
            kit.isRunning();
            Address address = new Address(params, "mj255GgoGKN6uTjtWdNcF7obu88iLSTZdm");
            boolean add =kit.wallet().isAddressWatched(address);
            Wallet wallet = new Wallet(params);
            DumpedPrivateKey key = new DumpedPrivateKey(params,
                   "cTH6YyRZSqF8VvtjkfqABqjGF682cQkW3mMuageraH4CEzCrweqT");
            wallet.addKey(key.getKey());
            wallet.addWatchedAddress(new Address(params, "mj255GgoGKN6uTjtWdNcF7obu88iLSTZdm"));
            BlockChain chain = new BlockChain(params, wallet,
                   new MemoryBlockStore(params));
         PeerGroup peerGroup = new PeerGroup(params, chain);
         peerGroup.addPeerDiscovery(new DnsDiscovery(params));
         peerGroup.addWallet(wallet);
         peerGroup.start();
         peerGroup.downloadBlockChain();
         BigInteger balance = wallet.getBalance();
         System.out.println("Wallet balance: " + balance);
}

```

Edit 1: The below given code retrieves balance from address but each and everytime it is creating a new address.

```
public static void main(String[] args) {

    NetworkParameters params = TestNet3Params.get();

    String filePrefix = "forwarding-service-testnet";

    WalletAppKit kit = new WalletAppKit(params, new File("."), filePrefix);

    // Download the block chain and wait until it's done.
    kit.startAsync();
    kit.awaitRunning();

    List<Address> list = kit.wallet().getWatchedAddresses();
    if (list.size() < 2) {
        kit.wallet().addWatchedAddress(kit.wallet().freshReceiveAddress());
        System.out.println("New address created");
    }

    System.out.println("You have " + list.size() + " addresses!");
    for (Address a: list) {
        System.out.println(a.toString());
    }

    String balance = kit.wallet().getBalance().toFriendlyString();
    System.out.println(balance);
}

```

**Tags:** address, bitcoinj, balance

> **Comments:**
> **username_0**: @alcio I did check that one but still I'm not getting my balance  

---

## 1 answers

### Answer by username_1 on 2017-08-04. Score: 0

I can offer you the workaround for this problem. I used web API for this feature. For example <https://www.blockcypher.com/dev/bitcoin/#address-balance-endpoint>.

It will allow you refuse block chain downloading part and make your code more simple.

> **Comments:**
> **username_0**: Thanks @username_1 ,But I need it this way "using bitcoinj" as mentioned  

---

