本文介绍了如何使用 Shyft API 和 GraphQL API 获取 Solana 链上 NFT 系列的地板价。
在本文中,我们将探索使用 Shyft 的 DAS API 和 Shyft 的 GraphQL API 获取 Solana 区块链上 NFT 系列底价的最简单方法之一。
在此处阅读 SHYFT API 文档 here .
要开始使用,我们需要准备一些东西。
x-api-key
是一个身份验证参数,它允许你访问 Shyft API。你可以从 Shyft 网站获取你自己的 API密钥。 只需在此处使用你的电子邮件 ID 注册,你就可以免费获得它。如果你已经拥有 Shyft API 密钥,请跳过此步骤。
我们的教程将分为三个步骤:
DAS API 是 Metaplex 的一项开放规范,旨在简化对 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,使用 Shyft 的 GraphQL API 从三大市场获取上市信息:Magic Eden、Tensor 和 Sniper。
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 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!