Skip to main content

Using the QuickNode Graph API

Updated on
Jun 5, 2023

The QuickNode GraphQL API is a flexible and easy to use API giving you access to enriched NFT and ERC20 Token data.

Making a GraphQL Query

To make a GraphQL query, send a POST request to https://api.quicknode.com/graphql with a JSON body containing the query and any variables, and an x-api-key header containing your QuickNode Graph API key. Here are examples of how to make a GraphQL query in several programming languages:

Apollo Client (React)

Apollo Client (React) example
import React from 'react';
import { useQuery, gql } from '@apollo/client';

const GET_COLLECTION = gql`
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
`;

function CollectionData() {
const { loading, error, data } = useQuery(GET_COLLECTION, {
context: {
headers: {
'x-api-key': 'your-api-key-here',
},
},
});

if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;

return (
<div>
<p>Name: {data.ethereum.collection.name}</p>
<p>Symbol: {data.ethereum.collection.symbol}</p>
<p>Total Supply: {data.ethereum.collection.totalSupply}</p>
</div>
);
}

export default function App() {
return (
<div>
<h2>NFT Collection Details</h2>
<CollectionData />
</div>
);
}

Apollo Client (JS)

Apollo Client (JS) example
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';

const client = new ApolloClient({
uri: 'https://api.quicknode.com/graphql',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key-here'
},
cache: new InMemoryCache()
});

client
.query({
query: gql`
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
`
})
.then(result => console.log(result));

JavaScript

JavaScript example

const fetch = require('node-fetch');

const query = `
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
`;

fetch('https://api.quicknode.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key-here'
},
body: JSON.stringify({ query }),
})
.then(res => res.json())
.then(data => console.log(data));

cURL

cURL example
curl -X POST https://api.quicknode.com/graphql \
-H 'Content-Type: application/json' \
-H 'x-api-key: your-api-key-here' \
-d '{"query":"{ ethereum { collection(contractAddress: \"0x2106c00ac7da0a3430ae667879139e832307aeaa\") { name symbol totalSupply } } }"}'

PHP

PHP example
$ch = curl_init();

$query = '
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
';

curl_setopt($ch, CURLOPT_URL, 'https://api.quicknode.com/graphql');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['query' => $query]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'x-api-key: your-api-key-here'
]);

$result = curl_exec($ch);

curl_close($ch);

$data = json_decode($result, true);

Python

Python example
import requests

query = '''
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
'''

response = requests.post('https://api.quicknode.com/graphql', json={'query': query}, headers={
'Content-Type': 'application/json',
'x-api-key': 'your-api-key-here'
})

data = response.json()

Go

Go example
package main

import (
"bytes"
"encoding/json"
"net/http"
)

func main() {
query := `
query {
ethereum {
collection(contractAddress: "0x2106c00ac7da0a3430ae667879139e832307aeaa") {
name
symbol
totalSupply
}
}
}
`

body, _ := json.Marshal(map[string]string{
"query": query,
})

req, _ := http.NewRequest("POST", "https://api.quicknode.com/graphql", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your-api-key-here")

client := &http.Client{}
resp, _ := client.Do(req)

var data map[string]interface{}
json.NewDecoder(resp.Body).Decode(&data)
}


Important Notes

Replace the example query with the one you want to use, and be sure to include an x-api-key header containing your QuickNode Graph API key.

Share this doc