Get all Bids of a Collection
Getting all bids of on NFTs belonging to a specific collection
Active Bids on a cNFT Collection (Compressed NFT collection)
import { gql, GraphQLClient } from "graphql-request";
import { Network, ShyftSdk } from '@shyft-to/js';
const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;
const graphQLClient = new GraphQLClient(endpoint, {
method: `POST`,
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
});
const shyft = new ShyftSdk({ apiKey: YOUR-KEY, network: Network.Mainnet }); //Initialize Shyft SDK to use DAS
async function getAllBidsFromCollection(collectionAddr:string) {
const allNftMintsforCollection = await getAllMintsofColl(collectionAddr);
// all fields can be cherry-picked as per your requirement
const query = gql`
query MyQuery {
TENSOR_CNFT_bidState(
where: {target: {_has_key: "assetId"}, targetId: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
) {
targetId
target
bidId
owner
cosigner
currency
makerBroker
rentPayer
pubkey
amount
}
}
`;
const response = await graphQLClient.request(query);
console.dir(response,{depth: null});
}
getAllBidsFromCollection('AGSmrgdkkwYRpvWXZ2kf4KoPdG5jPMj8KrNjnAgsum54')
//replace with your NFT collection address
async function getAllMintsofColl(collectionAddr:string) { //get all NFTs from a specific collection
let page = 1;
const assets = [];
while (page > 0) {
const assetsByGroup = await shyft.rpc.getAssetsByGroup({
groupKey: 'collection',
groupValue: collectionAddr,
page,
limit: 1000,
});
assets.push(...assetsByGroup.items);
page = assetsByGroup.total !== 1000 ? -1 : page + 1;
}
console.log('Total NFT ', assets.length);
const nftAddresses = assets.map((nft) => nft.id);
return nftAddresses;
}
Active Bids on a NFT Collection (Non-Compressed NFT collection)
Last updated