Skip to content

Instantly share code, notes, and snippets.

@alejoacosta74
Created April 7, 2021 19:00
Show Gist options
  • Save alejoacosta74/55044445dec594f33c10c432b39f1116 to your computer and use it in GitHub Desktop.
Save alejoacosta74/55044445dec594f33c10c432b39f1116 to your computer and use it in GitHub Desktop.
Node.js script to query token data via GraphQL (The Graph)
const axios = require('axios');
uniswapURL = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2" ; // https://thegraph.com/explorer/subgraph/uniswap/uniswap-v2
const main = async () =>{
try {
const result = await axios.post(
uniswapURL,
{
query: `
{
tokens(first: 10, orderBy:tradeVolumeUSD, orderDirection: desc)
{
symbol
name
totalLiquidity
}
}
`
}
);
console.log ("Query result: \n", result.data.data.tokens);
} catch (err){
console.log(err);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment