Skip to main content

Introduction

In this tutorial, you’ll learn how to build a DEX token screener similar to DexScreener using the Moralis API. The screener will display top tokens by volume with real-time prices, market cap, and price changes. 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 dex-screener && cd dex-screener
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';

async function getTopTokens() {
  const response = await fetch(
    'https://deep-index.moralis.io/api/v2.2/discovery/tokens',
    {
      method: 'POST',
      headers: {
        'X-API-Key': API_KEY,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        chains: ['eth'],
        filters: [
          { metric: 'marketCap', gt: 100000 },
          { metric: 'volumeUsd', timeFrame: 'oneDay', gt: 10000 },
          { metric: 'securityScore', gt: 70 }
        ],
        sortBy: {
          metric: 'volumeUsd',
          timeFrame: 'oneDay',
          type: 'DESC'
        },
        limit: 20
      }),
    }
  );

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

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

Step 3: Run the Script

Execute the script to get the top tokens:
node index.js

Example Response

{
  "result": [
    {
      "tokenAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
      "chain": "eth",
      "name": "Tether USD",
      "symbol": "USDT",
      "logo": "https://cdn.moralis.io/eth/0xdac17f958d2ee523a2206206994597c13d831ec7.png",
      "priceUsd": "1.00",
      "marketCap": "83000000000",
      "volumeUsd": {
        "oneDay": "25000000000"
      },
      "pricePercentChange": {
        "oneDay": "0.01"
      },
      "securityScore": 85,
      "holders": 4500000,
      "createdAt": "2017-11-28T00:00:00.000Z"
    }
  ],
  "cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Understanding the Response

FieldDescription
tokenAddressContract address of the token
chainBlockchain the token is on
nameToken name
symbolToken ticker symbol
logoURL to token logo image
priceUsdCurrent price in USD
marketCapTotal market capitalization
volumeUsd.oneDay24-hour trading volume in USD
pricePercentChange.oneDay24-hour price change percentage
securityScoreToken security score (0-100)
holdersNumber of token holders
createdAtWhen the token was created

Next Steps