如何在Solana上获取NFT系列的地板价

  • Shyft_to
  • 发布于 2024-02-20 11:57
  • 阅读 5

本文介绍了如何使用 Shyft API 和 GraphQL API 获取 Solana 链上 NFT 系列的地板价。

在本文中,我们将探索使用 Shyft API 和 Shyft GraphQL API 获取 Solana 区块链上 NFT 系列底价的最简单方法之一。

在本文中,我们将探索使用 Shyft 的 DAS API 和 Shyft 的 GraphQL API 获取 Solana 区块链上 NFT 系列底价的最简单方法之一。

在此处阅读 SHYFT API 文档 here .

开始之前

要开始使用,我们需要准备一些东西。

注册你的 Shyft 帐户并获取你自己的 Shyft API 密钥。

x-api-key 是一个身份验证参数,它允许你访问 Shyft API你可以从 Shyft 网站获取你自己的 API密钥。 只需在此处使用你的电子邮件 ID 注册,你就可以免费获得它。如果你已经拥有 Shyft API 密钥,请跳过此步骤。

我们的教程将分为三个步骤

  • 在第一步中,我们使用 Shyft DAS API 来检索 属于此集合的所有 NFT。
  • 在第二步中,对于每个 NFT,我们利用 Shyft 的 GraphQL API 从三大市场获取上市信息MagicEdenTensorSniper
  • 第三个步骤包括汇总来自所有平台的数据、比较上市价格 并确定最低的价格。

获取属于某个系列的所有 NFT

DAS APIMetaplex 的一项开放规范,旨在简化对 NFT 和压缩 NFT 的访问。在本教程中,我们可以利用 Shyft 的 DAS API 来获取 属于某个集合的所有 NFT。以下代码演示了我们如何实现这一点。

let page = 1;
let assets = [];

const shyft = new ShyftSdk({ apiKey: process.env.SHYFT_API_KEY, network: Network.Mainnet });

while (page > 0) {
  const assetsByGroup = await shyft.rpc.getAssetsByGroup({
    groupKey: 'collection',
    groupValue: args[0],
    page,
    limit: 1000,
  });

  assets.push(...assetsByGroup.items);
  page = assetsByGroup.total !== 1000 ? -1 : page + 1;
}

console.log('Total NFT ', assets.length);

获取 NFT 上市信息

在收到属于该系列的所有 NFT 后,对于每个 NFT,使用 Shyft 的 GraphQL API 从三大市场获取上市信息:Magic EdenTensorSniper

Shyft GraphQL Program API 改变了你与 Solana 程序帐户数据交互的方式。简而言之,我们的解决方案使你可以轻松查询任何程序的帐户数据,从而为传统的 getProgramAccounts() 提供了一个强大的替代方案。要开始使用 Shyft GraphQL API,请随时查看 article

以下代码片段演示了如何使用 Shyft GraphQL API 获取 NFT 在 Magic Eden 中的上市信息。我们可以对 Tensor 和 Sniper 执行相同的操作。

async function queryMagicEdenListingState(nftAddress: string[]) {
  const query = gql`
    query MAGIC_EDEN_V2_SellerTradeStateV2($where: MAGIC_EDEN_V2_SellerTradeStateV2_bool_exp) {
      MAGIC_EDEN_V2_SellerTradeStateV2(where: $where) {
        seller
        tokenMint
        tokenAccount
        sellerReferral
        tokenSize
        pubkey
        paymentMint
        expiry
        buyerPrice
        bump
        auctionHouseKey
      }
    }
  `;

  const variables = {
    where: {
      tokenMint: {
        _in: nftAddress,
      },
    },
  };

  const response: any = await graphQLClient.request(query, variables);

  return response.MAGIC_EDEN_V2_SellerTradeStateV2;
}

聚合和比较数据

在获得所有 NFT 的所有上市数据后,我们的任务是聚合和比较它以确定 NFT 的底价。 底价是在 NFT 系列中 NFT 的最低在售价格。但是,请记住,本教程中的上市价格不一定与这些市场上显示的官方底价相符,因为它没有考虑平台费用或版税。

const [magicEden, tensor, sniper] = await Promise.all([\
    queryMagicEdenListingState(nftAddresses),\
    queryTensorListingState(nftAddresses),\
    querySniperListingState(nftAddresses),\
  ]); //This is done for ease of demo
  // All this information can also be fetched using a single graphQL call

  console.log('Magic Eden Listings', magicEden.length);
  console.log('Tensor Listings', tensor.length);
  console.log('Sniper Listings', sniper.length);

  const smallestOne = findSmallestItem(magicEden, 'buyerPrice');
  const smallestTwo = findSmallestItem(tensor, 'price');
  const smallestThree = findSmallestItem(sniper, 'price');

  console.log('Smallest Magic Eden', smallestOne);
  console.log('Smallest Tensor', smallestTwo);
  console.log('Smallest Sniper', smallestThree);

  const smallest = findSmallestItem(
    [\
      smallestOne\
        ? {\
            price: smallestOne.buyerPrice,\
            owner: smallestOne.seller,\
            mint: smallestOne.tokenMint,\
          }\
        : null,\
      smallestTwo\
        ? {\
            price: smallestOne.price,\
            owner: smallestOne.owner,\
            mint: smallestOne.nftMint,\
          }\
        : null,\
      smallestThree\
        ? {\
            price: smallestOne.price,\
            owner: smallestOne.owner,\
            mint: smallestOne.nftMint,\
          }\
        : null,\
    ].filter(Boolean),
    'price',
  );

  if (smallest) {
    console.log(`The floor price: ${smallest.price / 10 ** 9} (without fees)`);
    console.log('Floor price NFT: ', smallest.mint);
  } else {
    console.log('Cannot find the floor price of this collection');
  }

这是一个如何查找 Madlads 系列底价的示例

用于获取 Solana 上 NFT 系列底价的演示视频

结论

就这样!我们希望这个简短的指南对你有所帮助。你可以在此处找到此演示的完整源代码。

我们衷心希望你喜欢阅读这篇博文!如果你有任何疑问或想法,请随时访问我们的 Discord 社区。

非常感谢你抽出时间阅读它!

资源

  • 原文链接: blogs.shyft.to/how-to-ge...
  • 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
Shyft_to
Shyft_to
在 Solana上更快更智能地构建,使用Shyft的SuperIndexer、gRPC、RPC、API和SDK