Subgraph data (GraphQL)

Subgraph data (GraphQL)

Introduction#

The Graph and GraphQL#

The Graph is a decentralized protocol used to index and query data from blockchains, starting with Ethereum. This means it is a simpler way to retrieve specific data from the blockchain, aligning with the principles of web3 and offering the advantages of decentralization and reliability.

GraphQL is the underlying query language used in The Graph. What is the difference between standard RESTful API calls and GraphQL calls? The main difference is that traditional APIs require developers to create specific endpoints for users to retrieve specific data. If users need more information, they may have to make multiple API calls, sometimes hundreds of calls, to get the data they need. With The Graph (GraphQL), developers only need to make one call to the subgraph as long as they have created a flexible schema.

For more information about The Graph and the underlying GraphQL, please refer to this GraphQL introduction.

If you are using GraphQL data in your application, we recommend using feature-rich packages like Apollo or minimal implementations like GraphQL-Request.

DODO Subgraph#

To view the source of the subgraph, please refer to our GitHub repository.

DODOEX#

Indexing DODO smart routing trade data, liquidity pool data, liquidity pool trade data, liquidity pool TVL data, and crowdfunding pool data.

To view the subgraph development introduction, please refer to the Subgraph project introduction.

For other subgraphs, you only need to change the corresponding chainName and chainId, such as:

ChainNameChainId
moonriver1285
aurora1313161554
avax43114
optimism10

vDODO#

Indexing vDODO-related data Data application page: https://app.dodoex.io/gov/vdodo?network=mainnet

ChainsProvidersSubgraph service address
ethereumthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-vdodo
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=1&schemaName=vdodo

ERC20Token#

Indexing data related to token creation on DODO. Data application page: https://app.dodoex.io/dev/erc20?network=mainnet

ChainsProvidersSubgraph service address
ethereumthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-token
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=1&schemaName=token
bscthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-token-bsc
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=56&schemaName=token
polygonthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-token-polygon
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=137&schemaName=token
arbitrum
moonriver
aurora
boba
optimism
To replace the corresponding chainName or chainId, simply substitute them with the desired values for other chains.

DODO Ming V3#

Indexing data related to mining pool creation on DODO. Data application page: https://app.dodoex.io/dev/pool?network=mainnet

ChainsProvidersSubgraph service address
ethereumthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-mine-v3
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=1&schemaName=mine-v3
bscthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-mine-v3-bsc
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=56&schemaName=mine-v3
polygonthe graph hosted-servicehttps://thegraph.com/hosted-service/subgraph/dodoex/dodoex-mine-v3-polygon
DODO Self-hosted Subgraphhttps://api.dodoex.io/subgraph/graphql?chainId=137&schemaName=mine-v3
arbitrum
moonriver
aurora
boba
optimism
To replace the corresponding chainName or chainId, simply substitute them with the desired values for other chains.

Query Example#

Using The Graph hosted service#

Open the subgraph page to obtain the QUERIES (HTTP) address.

subgraph1
curl 'https://api.thegraph.com/subgraphs/name/dodoex/dodoex-v2' \
  -H 'content-type: application/json' \
  --data-raw '{"query":"{\n  dodoZoos(first: 5) {\n    id\n    pairCount\n    tokenCount\n    crowdpoolingCount\n  }\n}"}' \
  --compressed

Using The Graph Subgraph Studio#

You need to create an account with a wallet and deposit GRT tokens as query fees. Then, replace [api-key] with your own.

subgraph2
curl 'https://gateway.thegraph.com/api/[api-key]/subgraphs/id/GxV9XL6Wnjz75z919NPNdrLhEkqDR99PweUY3oh7Lh94' \
  -H 'content-type: application/json' \
  --data-raw '{"query":"{\n  dodoZoos(first: 5) {\n    id\n    pairCount\n    tokenCount\n    crowdpoolingCount\n  }\n}"}' \
  --compressed

Using DODO Self-hosted Subgraph#

You need to register an account on the DODO Developer Platform and apply for an API key.

curl --location --request GET 'https://api.dodoex.io/subgraph/graphql?chainId=1&schemaName=dodoex&apikey=${apikey}' \
  -H 'User-Agent: DODO-${your_id}'
  --data-raw '{"query":"{\n  dodoZoos(first: 5) {\n    id\n    pairCount\n    tokenCount\n    crowdpoolingCount\n  }\n}"}' \
  --compressed

Query the latest 10 transaction records, including orders from smart routing.#

{
  orderHistories(first:10, orderBy: timestamp, orderDirection: desc){
    id
    hash
    block
    from
    to
    fromToken{
      id
      symbol
    }
    toToken{
      id
      symbol
    }
    amountIn
    amountOut
    timestamp
  }
}

Query swap records for liquidity pools.#

{
  swaps(where:{pair:"0xc9f93163c99695c6526b799ebca2207fdf7d61ad"},first:10){
    hash
    from
    to
    fromToken{id}
    toToken{id}
    amountIn
    amountOut
  }
}

Query the most recently updated pools.#

{
  pairs(first:100,where:{type_not:"VIRTUAL"}, orderBy:updatedAt, orderDirection: desc){
    id
    type
    baseToken{
      id
    }
    quoteToken{
      id
    }
    baseReserve
    quoteReserve
    updatedAt
  }
}

Retrieve pool status based on daily and hourly dimensions.#

{
  pairDayDatas(first:100, where: {date_gt: 1684113421},orderBy:date,orderDirection:desc){
    date
    volumeBase
    volumeQuote
    feeBase
    feeQuote
    baseToken{
      symbol
    }
    quoteToken{
      symbol
    }
  }
}

Query user liquidity provision data.#

{
  liquidityPositions{
    id
    pair{
      id
      baseSymbol
      quoteSymbol
    }
    user{
      id
    }
    lpToken{
      id
      symbol
    }
    liquidityTokenBalance
    liquidityTokenInMining
    updatedAt
  }
}

Query user information.#

{
  user(id:"0x8982a82a77eaf1cd6f490b67ad982304ecc590af"){
    id
    txCount
    tradingRewardRecieved
  }
}

Query crowdfunding pool status.#

{
  crowdPoolingDayDatas{
    date
    crowdPooling {
      id
      creator
      baseToken{
        symbol
      }
      quoteToken{
        symbol
      }
    }
    investedQuote
    investCount
    newcome
    poolQuote
  }
}

FAQ#

How can I retrieve the latest updated data from a subgraph?#

You can use the parameters first:10, orderBy: timestamp, orderDirection: desc to retrieve the most recently updated data in descending order based on timestamp.