Purestake API + Java SDK to read and post transaction on to mainnet

Hi all, I did not find this in documentation so sharing this. instead of running a node and using that node to post the transaction, create purestake login and get API key. Use it within java sdk.

private static AlgodApi getAlgodApi()
{
	
	final String ALGOD_API_ADDR = "https://mainnet-algorand.api.purestake.io/ps1";
            final String PS_API_TOKEN = "XXXXXXXXXXXXXXXXX";

            //Create an instance of the algod API client
            AlgodClient client = (AlgodClient) new AlgodClient().setBasePath(ALGOD_API_ADDR);

           return new AlgodApi(client.addDefaultHeader("x-api-key", PS_API_TOKEN)); 
	
	
}

Thanks for posting this Visybl - the Java SDK is fully compatible with the PureStake API as you note using a custom header.

Another example is now up in the PureStake public repo - https://github.com/PureStake/api-examples/blob/master/java-examples/ExampleCustomHeader.java

Thanks Tim. Not sure what ALGOD_API_TOKEN to use here? It worked for me without ALGOD_API_TOKEN by simply passing Purestake API TOKEN in the defaultheader.

final String ALGOD_API_TOKEN = “”;
api_key.setApiKey(ALGOD_API_TOKEN);

It doesn’t require it, the example does show it as there and empty, but removing it won’t cause errors.

PureStake will update the examples to remove it entirely to prevent future confusion, thanks for pointing this out.

Thanks Tim.

For benefit of other users: Anyone following the developer Doc SDK examples can easily by-pass the step on creating a dedicated node and rather use Purestake API to submit transaction and display transaction. Dedicated node instance is only required if you are going to play with KMD (key management daemon).