This question already has an answer here:

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");
            Address address = new Address(params, "mj255GgoGKN6uTjtWdNcF7obu88iLSTZdm");
            boolean add =kit.wallet().isAddressWatched(address);
            Wallet wallet = new Wallet(params);
            DumpedPrivateKey key = new DumpedPrivateKey(params,
            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));
         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.

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

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

    String balance = kit.wallet().getBalance().toFriendlyString();

marked as duplicate by Pieter Wuille, j4ck, Jestin, MeshCollider, Andrew Chow Aug 7 '17 at 6:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @alcio I did check that one but still I'm not getting my balance – sano143 Aug 4 '17 at 8:54

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.

  • 1
    Thanks @Konstantin ,But I need it this way "using bitcoinj" as mentioned – sano143 Aug 4 '17 at 7:36

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