TON Api
GraphQL

GraphQL API Documentation

Our GraphQL service is conveniently accessible via the API endpoint found at https://tonapi.io/v2/graphql (opens in a new tab). You can perform various queris and mutations utilizing this tier.

GraphQL Playground

For a better interactive experience, we have made the GraphQL Playground available for you. Feel free to use this feature at the endpoint https://tonapi.io/v2/graphql/playground (opens in a new tab) to test your queries, mutations and perform real-time queries alongside a schema documentation view.

Fetching data with Node.js

Here's an example of how to interact with the given endpoint in a Node.js environment to specifically fetch data for one account:

const axios = require('axios');
 
// Define the GraphQL query structure
const query = `
  query {
    allAccounts(first: 1) {
      nodes {
        id
        name
      }
    }
  }
`;
 
// The endpoint where we will be sending our GraphQL request
const endpoint = 'https://tonapi.io/v2/graphql';
 
axios.post(endpoint, {query})
  .then(response => {
    const { data } = response.data;
    console.log(data);
  })
  .catch(error => console.error(error));

In this example, we're using the axios library to send a POST request to the specified endpoint.

We're requesting the first account using the allAccounts(first: 1) query. This returns only the first account from the list.

The fields included in the nodes are arbitrary and you should replace id and name with actual fields from the API.

Remember to install the axios package in your Node.js environment using npm:

npm install axios

Fetching data with graphql-request library

npm install graphql-request
const { request } = require('graphql-request');
 
// Define the GraphQL query structure
const query = `
  query {
    allAccounts(first: 1) {
      nodes {
        id
        name
      }
    }
  }
`;
 
// The endpoint where we will be sending our GraphQL request
const endpoint = 'https://tonapi.io/v2/graphql';
 
request(endpoint, query)
  .then(response => console.log(response))
  .catch(error => console.error(error));

In this example, we're using the request method from the graphql-request library to send a request to the mentioned endpoint.

We're requesting for the first account from allAccounts(first: 1). This will return only the first account from the list.

Note that the fields inside nodes are just placeholders and you should replace id and name with the actual fields as per your API.