Skip to content

Instantly share code, notes, and snippets.

@Paulius11
Created March 11, 2021 12:17
Show Gist options
  • Save Paulius11/d688c31d67c7e9fb6ab46da930bea085 to your computer and use it in GitHub Desktop.
Save Paulius11/d688c31d67c7e9fb6ab46da930bea085 to your computer and use it in GitHub Desktop.
xdai-honey
# Running your own xdai done
# # # # # # # # # # # # # # # # # #
https://forum.1hive.org/t/run-your-own-xdai-node/2875/8
# The graph api
# # # # # # # # # # # # # # # # # #
https://thegraph.com/explorer/subgraph/1hive/uniswap-v2
POST: https://api.thegraph.com/subgraphs/name/1hive/uniswap-v2
{
swaps(where: {pair: "0x50a4867aee9cafd6ddc84de3ce59df027cb29084"}, orderBy: timestamp, orderDirection: asc, first: 10) {
id
pair {
id
}
sender
amount0In
amount1In
amount0Out
amount1Out
to
logIndex
amountUSD
timestamp
}
}
# Connecting to the-graph
# # # # # # # # # # # # # # # # # #
const gql = require('graphql-tag')
const { GraphQLWrapper } = require('@aragon/connect-thegraph')
const dotenv = require('dotenv')
dotenv.config()
const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/1hive/uniswap-v2'
const PRICE_QUERY = gql`
query {
token(id: "${process.env.TOKEN_ID}") {
derivedETH
symbol
}
}
`
const fetchData = async () => {
const graphqlClient = new GraphQLWrapper(SUBGRAPH_URL)
const result = await graphqlClient.performQuery(PRICE_QUERY)
if (!result.data) return undefined
return result
}
exports.getTokenPrice = async () => {
const res = await fetchData()
const price = parseFloat(res.data.token.derivedETH).toFixed(2)
return price
}
exports.getTokenSymbol = async () => {
const res = await fetchData()
return res.data.token.symbol
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment