Having Problem With Purestake V2 java

I use the code below to create a client using the purestake java API

String[] headers = {"X-API-Key"};
        String[] values = {"B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab"};
 algodClient=new AlgodClient("https://testnet-algorand.api.purestake.io/ps2", 443,PURESTAKE_API_KEY);
        
        try {
            NodeStatusResponse status = algodClient.GetStatus().execute(headers, values).body();
            System.out.println("algod last round: " + status.lastRound);
         } catch (Exception e) {
                    System.err.print("Failed to get algod status: " + e.getMessage());
                    e.printStackTrace();
                }

and it successfully prints out the last round, but when I want to use the same algodClient to get an account balance using the code below, the accountInfo object returned is null

com.algorand.algosdk.v2.client.model.Account accountInfo = null;
        try {
            accountInfo = algodClient.AccountInformation(
new Address("LL2ZGXSHW7FJGOOVSV76RRZ6IGU5ZF4DPCHQ23G7ZLIWCB4WEMIATDBTLY"))
.execute().body();
            System.out.println("Account Balance: "+ accountInfo.amount+" microAlgos");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();

        }

But this all works fine when I create the algodClient from the Hackathon Instance.
I also noticed that entering a wrong or right purestake API Key did not seem to make any observable difference. I have also tried swapping “B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab” for my Purestake API key in values for X-API-KEY and did not notice any difference too.

Please any help is appreciated @rfustino @ryanRfox @JasonW
Thanks

Can you post the complete class file? Specifically your imports.

Ok, I’ll do that now

import com.algorand.algosdk.algod.client.api.AlgodApi;
import com.algorand.algosdk.algod.client.model.PendingTransactions;
import com.algorand.algosdk.algod.client.model.TransactionID;
import com.algorand.algosdk.crypto.Ed25519PublicKey;
import com.algorand.algosdk.crypto.MultisigAddress;
import com.algorand.algosdk.transaction.SignedTransaction;
import com.algorand.algosdk.util.Encoder;
import com.algorand.algosdk.v2.client.algod.RawTransaction;
import com.algorand.algosdk.v2.client.common.AlgodClient;
import com.algorand.algosdk.v2.client.common.Response;
import com.algorand.algosdk.v2.client.common.Utils;
import com.algorand.algosdk.v2.client.model.*;
import com.algorand.algosdk.account.Account;
import com.algorand.algosdk.crypto.Address;
import com.algorand.algosdk.transaction.Transaction;
import com.algorand.algosdk.templates.Split;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.ByteArrayOutputStream;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.List;

@JasonW

look at the way you are constructing the API client. Compare to this tutorial:

Specifically

        final String ALGOD_API_ADDR = "https://testnet-algorand.api.purestake.io/ps2";
        final int  ALGOD_PORT = 443;
        final String ALGOD_API_TOKEN = "";

        String[] headers = {"X-API-Key"};
        String[] values = {"YOUR API KEY HERE"};

        AlgodClient client = new AlgodClient(ALGOD_API_ADDR, ALGOD_PORT, ALGOD_API_TOKEN);

Just to be clear, I think the ALGOD_API_TOKEN should be blank: “”

Ok, thanks
I believe have done this though but I’ll try it again and get back to you

The issue is that you need to pass the arguments headers, values each time you call .execute. You do it with GetStatus(), but you don’t do it when you use .AccountInformation.

1 Like

Thanks a lot @fabrice, your suggestion works like charm :grinning: :smiley: , am really grateful. Also thanks a lot @JasonW for trying to help me out