Skip to main content

Samples

In the following section, you will find example code for interacting with the API using JavaScript and Python. These examples demonstrate how to send a GraphQL query to the API endpoint and print the response.

const endpoint = "https://api.stakingrewards.com/public/query";
const query = `
{
assets(where: {symbols: ["ETH"]}, limit: 1) {
name
slug
description
symbol
}
}
`;

fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": "YOUR_API_KEY",
},
body: JSON.stringify({ query }),
})
.then((response) => response.json())
.then((data) => console.log(data.data));

This code sends a POST request to our endpoint with a Content-Type of application/json and an X-API-KEY header containing your API key. The request body contains the GraphQL query as a string, which is passed as the query variable. The fetch function returns a promise, which is resolved with the JSON response from the server when the request is successful. You can then access the data returned by the query by accessing the data property of the response.

Note: You will need to replace YOUR_API_KEY with a valid API key in order for the request to be successful. You may also need to modify the query and endpoint to match the structure and requirements of the API you are using.

The response looks like this:

{
"data": {
"assets": [
{
"name": "Ethereum",
"slug": "ethereum-2-0",
"description": "the worlds largest and most decentralised Layer1 blockchain. The network is used for building dApps, holding assets, transacting and communicating without being controlled by a central authority. The Ethereum vision is to build a digital future on a global scale, that is powerful enough to help all of humanity. The native token of the network is Ether ($ETH) which is used to pay for certain activities on the Ethereum network",
"symbol": "ETH"
}
]
}
}