4. Get On-Chain Data

Here are some of the important parameters to take note while using On-Chain DEX API Endpoints:

  • Blockchain Networks
  • DEXs
  • Pool Contract Address
  • Token Contract Address

Blockchain Networks

πŸ“˜

Notes

  • Please do not use CoinGecko Asset Platform ID as the Network ID in On-Chain DEX API Endpoints (CoinGecko Asset Platform ID β‰  GT Network ID)
  • Example:
    • Asset Platform on CoinGecko: ethereum
    • On-Chain Network ID: eth

How to obtain Network ID?

  • Use /onchain/networks endpoint.
    Example of responses:

    {
      "data": [
        {
          "id": "eth",  πŸ‘ˆ Network ID
          "type": "network",
          "attributes": {
            "name": "Ethereum",
            "coingecko_asset_platform_id": "ethereum" πŸ‘ˆ CoinGecko Asset Platform ID
          }
        },
       ......
      ]
    }
    
  • Go to GeckoTerminal

    [1] Select or search for a blockchain network.

    [2] Copy the slug from the URL:


DEXs

Some of the pools endpoints require you to provide DEX ID along with Network ID to query the pools on a particular DEX (Decentralized Exchange).

Using /onchain/networks/{network}/dexes/{dex}/pools as example:

https://pro-api.coingecko.com/api/v3/onchain/networks/eth/dexes/uniswap_v3/pools?x_cg_pro_api_key=YOUR_API_KEY

There are 2 parameter values required to apply for this endpoint:

  • network: eth (network ID)
  • dex: uniswap_v3 (dex ID)

How to obtain DEX ID?

  • Use /onchain/networks/{network}/dexes endpoint.
    Example of responses:

    {
      "data": [
        {
          "id": "uniswap_v2", πŸ‘ˆ DEX ID
          "type": "dex",
          "attributes": {
            "name": "Uniswap V2"
          }
        },
      ......
      ]
    }
    
  • Go to GeckoTerminal

    [1] Select or search for a blockchain network.

    [2] Choose the DEX from the DEXs List on the top (e.g. Uniswap V3).

    [3] Copy the slug from the URL:


Methods to query On-Chain Data

a. Pool Contract Address

Most of the time, you will need a pool contract address along with Network ID to query the on-chain data, especially when using the Pools Endpoints.

Using /onchain/networks/{network}/pools/{address} as example:

https://pro-api.coingecko.com/api/v3/onchain/networks/eth/pools/0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc?x_cg_pro_api_key=YOUR_API_KEY

There are 2 parameter values required to apply for this endpoint:

  • network: eth (network ID)
  • address: 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc (pool contract address)

How to obtain the pool contract address? (e.g. WETH/USDC)

b. Token Contract Address

Apart from the pool contract address, you also have the option to query on-chain data by using the token contract address, using /onchain/networks/{network}/tokens/{token_address}/pools as example:

https://pro-api.coingecko.com/api/v3/onchain/networks/eth/tokens/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48/pools?x_cg_pro_api_key=YOUR_API_KEY

There are 2 parameter values required to apply for this endpoint:

  • network: eth (network ID)
  • address: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 (token contract address)

How to obtain tokens contract address (e.g. UNI):