Skip to main content

Introduction

In this tutorial, you’ll learn how to find DEX liquidity pair addresses for any two tokens using the Moralis API. This is essential for getting trading data, liquidity information, and price data for token pairs on decentralized exchanges like Uniswap, PancakeSwap, and SushiSwap. 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-pair-address && cd get-pair-address
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';

// Token addresses
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';

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

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

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

Step 3: Run the Script

Execute the script to find the pair address:
node index.js

Example Response

{
  "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"
  },
  "pairAddress": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
  "exchange": "uniswapv3",
  "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
  "exchangeLogo": "https://cdn.moralis.io/eth/0x1f98431c8ad98523631ae4a59f267346ea31f984.png"
}

Understanding the Response

FieldDescription
token0First token in the pair with metadata
token1Second token in the pair with metadata
pairAddressThe liquidity pair contract address
exchangeName of the DEX (uniswapv2, uniswapv3, sushiswap, etc.)
exchangeAddressThe DEX factory contract address
exchangeLogoURL to the exchange logo

Next Steps