Get floor price of a collection

Get floor price of NFT collections with graphQl APIs.

SHYFT’s SuperIndexer can also be used to create various utility functions which can readily be used in real-life dApps. One such example can be getting floor price of a particular NFT collection across 3 marketplaces. This also requires a little help from SHYFT’s DAS APIs. The steps are as follows,

  • Firstly, we get all NFTs belonging to a collection using DAS getAssetByGroup method, which accepts the collection address and returns the list of NFTs

  • This list can be used to filter the nftMint/tokenMint field of the marketplaces using graphQl, using the _in check, which enables graphQl to check for a list of values. This can be fetched using a single cross-program query

  • once we have the prices of all NFTs from all three marketplaces, we can easily find out the lowest price NFT from each marketplace belonging to that collection

  • The lowest price NFT among 3 marketplaces is the floor price of the collection

Getting NFT mintlist for a collection using DAS

let page = 1;
let assets = [];

while (page > 0) {
  const assetsByGroup = await shyft.rpc.getAssetsByGroup({
    groupKey: 'collection',
    groupValue: collectionAdress,
    page,
    limit: 1000,
  }); //getting NFTs for a collection in a paginated manner

  assets.push(...assetsByGroup.items); //adding to an array
  page = assetsByGroup.total !== 1000 ? -1 : page + 1;
}

You can also use our MintList tool to get a collection's mint list.

Get all listings from marketplace using graphQl


async function getAllBidsFromCollection(allNftMintsforCollection) {
    const query = gql`
    query MyQuery {
        MAGIC_EDEN_V2_SellerTradeStateV2(
          where: {tokenMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          tokenMint
          pubkey
          seller
          buyerPrice
        }
        Tensor_SingleListing(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          owner
          nftMint
          price
        }
        SNIPER_MARKET_SOLNFTOrderV1(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          nftMint
          price
          owner
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
}

This step would give us all NFT listings across 3 marketplaces, along with their prices. In the next step we have to filter the listings to get NFTs with the lowest price.

The GraphQL _in filter can be used to check for keys in a range of values

Getting the lowest price NFTs and the floor price

function findSmallestItem(items, property) {
  if (items.length === 0) {
    return undefined;
  }

  return items.reduce((smallest, item) => {
    return item[property] < smallest[property] ? item : smallest;
  }, items[0]);
}

This function can be used to retrieve the lowest priced NFT for each marketplace, and then the lowest price NFT among three is the floor price of the collection

Last updated