You can query Uniswap data on The Graph using GraphQL.
One way is to query token
directly:
{
token(id: "0x1381f369d9d5df87a1a04ed856c9dbc90f5db2fa") {
derivedETH
}
}
... where derivedETH
is ETH price.
Another is to query pair (by pair id
or, in this example, using token id
's):
{
pairs(where: { token0: "0x1381f369d9d5df87a1a04ed856c9dbc90f5db2fa" token1: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" }) {
token0Price
token1Price
}
}
... where token0Price
and token1Price
are prices of tokens relative to each other (VRGN\WETH).
You can play with these in sandbox or you might need a client.
Alternatively, to keep things simple, you can do request directly, like this:
curl -X POST -H "Content-Type: application/json" -d '{"query": "{ token(id: \"0x1381f369d9d5df87a1a04ed856c9dbc90f5db2fa\") { derivedETH } }"}' https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2
... to get:
{"data":{"token":{"derivedETH":"0.0004465905539042863338157407540331524"}}}