> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moralis.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Get Top ERC20 Tokens by Market Cap

> Learn how to discover and filter top ERC20 tokens by market cap, volume, and other metrics using the Moralis API.

## 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:

* [Get Filtered Tokens](/data-api/evm/token/discovery/filtered-tokens) - Search and filter tokens by various metrics

## Prerequisites

* Node.js v18+ installed
* A Moralis API key ([get one free](https://admin.moralis.io))

## Step 1: Set Up Your Project

Create a new directory for your project and initialize it:

```bash theme={null}
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:

```javascript theme={null}
// 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:

```bash theme={null}
node index.js
```

## Example Response

```json theme={null}
{
  "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

| Field                      | Description                          |
| -------------------------- | ------------------------------------ |
| `token_address`            | Token contract address               |
| `name` / `symbol`          | Token name and symbol                |
| `market_cap`               | Current market capitalization in USD |
| `fully_diluted_valuation`  | FDV based on max supply              |
| `price_usd`                | Current price in USD                 |
| `price_24h_percent_change` | 24-hour price change percentage      |
| `price_7d_percent_change`  | 7-day price change percentage        |
| `volume_24h_usd`           | 24-hour trading volume in USD        |
| `holders`                  | Number of unique holders             |
| `verified_contract`        | Whether contract is verified         |
| `possible_spam`            | Whether flagged as spam              |
| `security_score`           | Token security score (0-100)         |

## Next Steps

* [Get Token Price](/get-started/tutorials/data-api/prices-and-charts/get-the-price-of-an-erc-20-token) - Get current token prices
* [Get Token Pairs](/get-started/tutorials/data-api/tokens-and-markets/get-token-pairs-and-liquidity-data) - Find trading pairs
* [Build a DEX Screener](/get-started/tutorials/data-api/tokens-and-markets/build-a-dex-screener-clone) - Create a trading dashboard
* [API Reference](/data-api/evm/token/discovery/filtered-tokens) - Full API documentation
