Skip to navigation

4. Get On-chain Data

Here are some of the important parameters to take note of while using Onchain 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 Onchain DEX API Endpoints (CoinGecko Asset Platform ID ≠ GT Network ID)

  • Example:

    • Asset Platform on CoinGecko: ethereum
    • Onchain Network ID: eth

How to obtain Network ID?

  • Use /onchain/networks endpoint, example of response:

    JSON
    {
    "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 a DEX ID along with a Network ID to query the pools on a particular DEX (Decentralized Exchange).

Using the /onchain/networks/{network}/dexes/{dex}/pools endpoint as an 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 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 response:

    JSON
    {
    "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 Onchain Data

a. Pool Contract Address

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

Using the /onchain/networks/{network}/pools/{address} endpoint as an 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 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 onchain data by using the token contract address, using the /onchain/networks/{network}/tokens/{token_address}/pools endpoint as an 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 for this endpoint:

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

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