Skip to content

Latest commit

 

History

History
79 lines (57 loc) · 4 KB

File metadata and controls

79 lines (57 loc) · 4 KB
title Token API Quick Start
sidebarTitle Schnellstart

The Graph Token API Quick Start banner

[!CAUTION] This product is currently in Beta and under active development. If you have any feedback, please reach out to us on Discord.

The Graph's Token API lets you access blockchain token information via a GET request. This guide is designed to help you quickly integrate the Token API into your application.

The Token API provides access to onchain token data, including balances, holders, detailed token metadata, and historical transfers. This API also uses the Model Context Protocol (MCP) to enrich raw blockchain data with contextual insights using AI tools, such as Claude.

Voraussetzungen

Before you begin, get a JWT token by signing up on The Graph Market. You can generate a JWT token for each of your API keys using the dropdown menu.

Authentication

All API endpoints are authenticated using a JWT token inserted in the header as Authorization: Bearer <token>.

{
  "headers": {
    "Authorization": "Bearer eyJh•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••NnlA"
  }
}

Using JavaScript

Make an API request using JavaScript by adding the request parameters, and then fetching from the relevant endpoint. For example:

const address = '0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208'
const options = {
  method: 'GET',
  headers: {
    Accept: 'application/json',
    Authorization: 'Bearer <token>',
  },
}

fetch(`https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=${address}`)
  .then((response) => response.json())
  .then((response) => console.log(response))
  .catch((err) => console.error(err))

Make sure to replace <token> with the JWT Token generated from your API key.

Using cURL (Command Line)

To make an API request using cURL, open your command line and run the following command.

curl --request GET \
  --url https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=${address} \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <token>'

Make sure to replace <token> with the JWT Token generated from your API key.

Most Unix-like systems come with cURL preinstalled. For Windows, you may need to install cURL.

Troubleshooting

If the API call fails, try printing out the full response object for additional error details. For example:

fetch(`https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=${address}`)
  .then((response) => {
    console.log('Status Code:', response.status)
    return response.json()
  })
  .then((data) => console.log(data))
  .catch((err) => console.error('Error:', err))