Skip to main content

Introduction

In this tutorial, you’ll learn how to retrieve all trading pairs and liquidity data for any ERC20 token using the Moralis API. This includes pair addresses, liquidity amounts, volume data, and exchange information. This is essential for building token analytics, DEX aggregators, or trading interfaces. We’ll use the following Moralis API endpoint:

Prerequisites

Step 1: Set Up Your Project

Create a new directory for your project and initialize it:
mkdir get-token-pairs && cd get-token-pairs
npm init -y

Step 2: Create the Script

Create a file called index.js and add the following code:
// index.js
const API_KEY = 'YOUR_API_KEY';
const TOKEN_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; // USDC

async function getTokenPairs() {
  const response = await fetch(
    `https://deep-index.moralis.io/api/v2.2/erc20/${TOKEN_ADDRESS}/pairs?chain=eth`,
    {
      headers: {
        'X-API-Key': API_KEY,
      },
    }
  );

  const data = await response.json();
  console.log(JSON.stringify(data, null, 2));
}

getTokenPairs();
Replace YOUR_API_KEY with your actual Moralis API key.

Step 3: Run the Script

Execute the script to fetch the token pairs:
node index.js

Example Response

{
  "page": 1,
  "page_size": 100,
  "cursor": null,
  "result": [
    {
      "pairAddress": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
      "pairLabel": "WETH/USDC",
      "exchange": "uniswapv3",
      "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
      "exchangeLogo": "https://cdn.moralis.io/eth/0x1f98431c8ad98523631ae4a59f267346ea31f984.png",
      "token0": {
        "address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        "name": "USD Coin",
        "symbol": "USDC",
        "decimals": 6,
        "logo": "https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png"
      },
      "token1": {
        "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        "name": "Wrapped Ether",
        "symbol": "WETH",
        "decimals": 18,
        "logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png"
      },
      "usdPrice": 3500.50,
      "usdPriceFormatted": "3500.50",
      "liquidityUsd": 250000000,
      "volume24h": 15000000,
      "priceChange24h": 2.5
    }
  ]
}

Understanding the Response

FieldDescription
pairAddressThe liquidity pair contract address
pairLabelHuman-readable pair name (e.g., WETH/USDC)
exchangeDEX name (uniswapv2, uniswapv3, sushiswap)
token0 / token1Token metadata for both sides of the pair
usdPriceCurrent price in USD
liquidityUsdTotal liquidity in USD
volume24h24-hour trading volume in USD
priceChange24h24-hour price change percentage

Next Steps