opensea-js
Version:
TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data
86 lines • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListingsAPI = void 0;
const apiPaths_1 = require("./apiPaths");
const utils_1 = require("../orders/utils");
const types_1 = require("../types");
/**
* Listing-related API operations
*/
class ListingsAPI {
constructor(fetcher, chain) {
this.fetcher = fetcher;
this.chain = chain;
}
/**
* Gets all listings for a given collection.
* @param collectionSlug The collection slug
* @param limit The number of listings to return
* @param next The cursor for pagination
* @param includePrivateListings Whether to include private listings (default: false)
*/
async getAllListings(collectionSlug, limit, next, includePrivateListings) {
const response = await this.fetcher.get((0, apiPaths_1.getAllListingsAPIPath)(collectionSlug), {
limit,
next,
...(includePrivateListings !== undefined && {
include_private_listings: includePrivateListings,
}),
});
return response;
}
/**
* Gets the best listing for a given token.
* @param collectionSlug The collection slug
* @param tokenId The token ID
* @param includePrivateListings Whether to include private listings (default: false)
*/
async getBestListing(collectionSlug, tokenId, includePrivateListings) {
const response = await this.fetcher.get((0, apiPaths_1.getBestListingAPIPath)(collectionSlug, tokenId), includePrivateListings !== undefined
? { include_private_listings: includePrivateListings }
: undefined);
return response;
}
/**
* Gets the best listings for a given collection.
* @param collectionSlug The collection slug
* @param limit The number of listings to return
* @param next The cursor for pagination
* @param includePrivateListings Whether to include private listings (default: false)
*/
async getBestListings(collectionSlug, limit, next, includePrivateListings) {
const response = await this.fetcher.get((0, apiPaths_1.getBestListingsAPIPath)(collectionSlug), {
limit,
next,
...(includePrivateListings !== undefined && {
include_private_listings: includePrivateListings,
}),
});
return response;
}
/**
* Gets all active listings for a specific NFT.
* @param assetContractAddress The NFT contract address
* @param tokenId The token ID
* @param limit The number of listings to return
* @param next The cursor for pagination
* @param chain The blockchain chain
* @param includePrivateListings Whether to include private listings (default: false)
*/
async getNFTListings(assetContractAddress, tokenId, limit, next, chain = this.chain, includePrivateListings) {
const response = await this.fetcher.get((0, apiPaths_1.getOrdersAPIPath)(chain, "seaport", types_1.OrderSide.LISTING), {
...(0, utils_1.serializeOrdersQueryOptions)({
assetContractAddress,
tokenIds: [tokenId],
limit,
next,
}),
...(includePrivateListings !== undefined && {
include_private_listings: includePrivateListings,
}),
});
return response;
}
}
exports.ListingsAPI = ListingsAPI;
//# sourceMappingURL=listings.js.map