Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Tutorial Thumbnail
Beginner · 15 minutes or less

Getting Started with the PureStake API Service

The following is a simple walkthrough for using the PureStake API to interact with the Algorand network. While you can always run your own node, using an API service to query the network is significantly faster than downloading transaction data and configuring your own infrastructure.

Requirements

None

Background

For more information on the PureStake API, here are some helpful links:

Steps

1. Create a PureStake API Account

Register for an account at https://developer.purestake.io/ . You can use the free tier with unlimited daily TestNet requests, up to 5,000 requests daily MainNet requests, and 5 requests per second for both TestNet or MainNet. More about PureStake’s pricing tiers.

EditorImages/2020/04/07 20:09/01-algorand-api-service-homepage.png

Hit the Sign Up for Free option and fill out the registration form.

EditorImages/2020/04/07 20:11/02-algorand-api-service-register.png

You will need a working email address since you’ll need to verify it as part of the signup process. Scroll to the bottom of the Terms & Conditions to enable the “I agree to the Terms and Conditions” checkbox.

You will get an email from [email protected] with a registration code that looks like this:

EditorImages/2020/04/07 20:12/03-algorand-api-service-verification-email.png

Make note of the code you are sent and enter that code into the following screen when prompted:

EditorImages/2020/04/07 20:13/04-algorand-api-service-email-verification.png

After submitting you will be logged into the API Services application.

2. Get Your Unique API Key

Once logged in, you will have access to an API key that is unique to your account.

EditorImages/2020/04/07 20:29/05-algorand-api-service-dashboard-alt.png

Here you will see your API Key at the top of the screen. You will need to copy that key to be able to access the PureStake API service.

3. Verify the API Key with the Swagger UI, cURL, or Postman

Before using the API, you’ll want to verify that your key works. There are three primary ways to do that: directly in the PureStake interface using the Swagger UI, via a cURL command, or by using the Postman application.

Option A: Swagger UI

Navigate to the APIs section in the API portal. Choose the network (e.g., Algorand BetaNet, TestNet, or MainNet) in the left sidebar.

Click on /v1/status in the accordion menu to see more options.

EditorImages/2020/04/07 20:32/12-swagger-step1.png

Click the Try it out button.

EditorImages/2020/04/07 20:31/12-swagger-step2.png

Click Execute.

EditorImages/2020/04/07 20:32/12-swagger-step3.png

Scroll down to the Server response section. If the response body contains a valid entry, your API key has worked successfully.

EditorImages/2020/04/07 20:34/12-swagger-step4.png

Option B: cURL

To verify your API key, copy the cURL command from the top left sidebar of the PureStake API dashboard.

EditorImages/2020/04/07 20:49/05-algorand-api-service-dashboard-zoom.png

Paste the command into your terminal of choice and hit Enter.

EditorImages/2020/04/07 20:51/CURL_Ubuntu.png

If you receive a similar response from the server, your API key is valid. If not, double-check that copied and pasted the cURL command correctly.

Option C: Postman

If you’re new to Postman, it’s a graphical way to work with and test APIs. It’s free to download, and you can find more information on their website.

If you don’t already have an account, you’ll need to create one. Once you’ve signed up or logged in, select the New option in the left sidebar, and then Request from the dropdown menu.

EditorImages/2020/04/07 20:54/07-Postman_New_Request_Step_1.png

Enter a name for the request and create or choose a folder.

EditorImages/2020/04/07 20:54/07-Postman_New_Request_Step_2.png EditorImages/2020/04/07 20:55/07-Postman_New_Request_Step_4.png

You’ll need the URL of the endpoint for your GET Request. To find that, return to the PureStake API portal and copy the URL at the top of the APIs page (note that this URL will vary between BetaNet, TestNet, and MainNet). You can also find the URLs on the dashboard home page.

To create a URL for a specific endpoint, choose the BetaNet, TestNet, or MainNet URL and append it with the name of the endpoint (e.g., /health).

EditorImages/2020/04/07 20:56/08-Algod_TestNet_URL.png

Optional: You can also find the full URL in the Swagger UI for the endpoint you want. Click the endpoint, click “Try It Out” and then “Execute.” This actually runs the request on the live endpoint. You can then grab the URL or the cURL command for that request.

EditorImages/2020/04/07 20:57/09-TestNet_Status_URL.png

For this example, let’s check the status of the Algorand TestNet. The URL we need is https://testnet-algorand.api.purestake.io/ps1/v1/status.

Copy the URL for the endpoint and return to Postman. In the GET field of the GET request you just created, paste the URL of the endpoint you’d like to query.

In the tabs below, click Headers. Under KEY, add x-api-key. Under VALUE, paste the API key you received in Step 2.

EditorImages/2020/04/07 20:58/10-GET_query_enter_url.png

Once you’ve populated both of these fields, click “Send.” You will receive a response as seen in the below screenshot. This verifies your API key is working.

EditorImages/2020/04/07 20:58/11-get_request_response.png