Skip to main content

Introduction

In this tutorial, you’ll learn how to discover and filter ERC20 tokens using the Moralis API. You can sort tokens by market cap, trading volume, price change, and other metrics. This is essential for building token discovery platforms, market dashboards, or trading screeners. 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-top-tokens && cd get-top-tokens
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'],
        sortBy: {
          metric: 'marketCap',
          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 top tokens:
node index.js

Example Response

{
  "page": 1,
  "page_size": 20,
  "result": [
    {
      "token_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "name": "Wrapped Ether",
      "symbol": "WETH",
      "decimals": 18,
      "logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
      "market_cap": 420000000000,
      "fully_diluted_valuation": 420000000000,
      "price_usd": 3500.50,
      "price_24h_percent_change": 2.5,
      "price_7d_percent_change": 5.2,
      "volume_24h_usd": 15000000000,
      "holders": 7500000,
      "total_supply": "120000000",
      "total_supply_formatted": "120000000",
      "verified_contract": true,
      "possible_spam": false,
      "security_score": 85
    }
  ]
}

Understanding the Response

FieldDescription
token_addressToken contract address
name / symbolToken name and symbol
market_capCurrent market capitalization in USD
fully_diluted_valuationFDV based on max supply
price_usdCurrent price in USD
price_24h_percent_change24-hour price change percentage
price_7d_percent_change7-day price change percentage
volume_24h_usd24-hour trading volume in USD
holdersNumber of unique holders
verified_contractWhether contract is verified
possible_spamWhether flagged as spam
security_scoreToken security score (0-100)

Next Steps