Skip to content

Authenticating on API

1. Get your credentials

The first step to authenticate on the API is to register on the Orbit Codes dashboard.

Navigate to the API page, and click on key rotation to generate a new key.

You will now be able to copy the content of the fields and extract the API Client Key and the API Client Secret. Make sure to keep them safe, as they will be used to authenticate on the API. Client secret won’t be displayed again, and is stored encrypted on the server.

2. Authenticate on the API

Authentication in the API is done by using the API Client Key and the API Client Secret in the X-Client-Key and X-Client-Secret headers.

Here is an example of how to authenticate on the API using curl:

Terminal window
curl -X POST https://api.orbit.codes/graphql \
-H "Content-Type: application/json" \
-H "X-Client-Key: YOUR_API_CLIENT_KEY" \
-H "X-Client-Secret: YOUR_API_CLIENT_SECRET" \
-d '{"query":"{ blocks(dataset: "nim") { height } }"}'

If you use the Apollo Client on React, you can authenticate on the API by passing the headers in the HttpLink:

import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
const getClient = () => {
return new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: process.env.API_BASE_URL ?? 'https://api.orbit.codes/graphql',
headers: {
'X-Client-Key': process.env.API_KEY ?? '',
'X-Client-Secret': process.env.API_SECRET ?? '',
},
}),
});
};

3. Chose your dataset

The dataset parameter is used to specify the dataset you want to query. It is a required parameter for all queries. It represents the chain you want to query, and can be one of the following values:

Note: we only index the main networks for now, test nets are done on demand.

4. Enjoy the data

You are now authenticated on the API and can start querying the data you need. You can find the available queries and mutations in the API IDE.

query Block($dataset: String!, $height: Int!) {
block(dataset: $dataset, height: $height) {
height
transactions {
count
}
minted_at
proposer_hash
app_hash
}
}