Skip to main content

Introduction

In this tutorial, you’ll learn how to retrieve floor prices for any NFT collection using the Moralis API. Floor prices represent the lowest listed price for an NFT in a collection, which is a key metric for understanding collection value and market trends. 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-nft-floor-price && cd get-nft-floor-price
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 NFT_ADDRESS = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'; // BAYC

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

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

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

Step 3: Run the Script

Execute the script to fetch the floor price:
node index.js

Example Response

{
  "floor_price": 25.5,
  "floor_price_usd": 89250.75,
  "floor_price_currency": "ETH",
  "marketplace": "opensea",
  "marketplace_logo": "https://cdn.moralis.io/marketplaces/opensea.png",
  "last_updated": "2024-01-15T10:30:00.000Z"
}

Understanding the Response

FieldDescription
floor_priceFloor price in native token (ETH)
floor_price_usdFloor price converted to USD
floor_price_currencyCurrency of the floor price
marketplaceMarketplace where floor was found
marketplace_logoLogo URL of the marketplace
last_updatedWhen the floor price was last updated

Next Steps