opensea-js
Version:
TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data
101 lines • 3.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OffersAPI = void 0;
const apiPaths_1 = require("./apiPaths");
const utils_1 = require("../orders/utils");
const types_1 = require("../types");
/**
* Offer-related API operations
*/
class OffersAPI {
constructor(fetcher, chain) {
this.fetcher = fetcher;
this.chain = chain;
}
/**
* Gets all offers for a given collection.
*/
async getAllOffers(collectionSlug, limit, next) {
const response = await this.fetcher.get((0, apiPaths_1.getAllOffersAPIPath)(collectionSlug), {
limit,
next,
});
return response;
}
/**
* Gets trait offers for a given collection.
*/
async getTraitOffers(collectionSlug, type, value, limit, next, floatValue, intValue) {
const response = await this.fetcher.get((0, apiPaths_1.getTraitOffersPath)(collectionSlug), {
type,
value,
limit,
next,
float_value: floatValue,
int_value: intValue,
});
return response;
}
/**
* Gets the best offer for a given token.
*/
async getBestOffer(collectionSlug, tokenId) {
const response = await this.fetcher.get((0, apiPaths_1.getBestOfferAPIPath)(collectionSlug, tokenId));
return response;
}
/**
* Build a OpenSea collection offer.
*/
async buildOffer(offererAddress, quantity, collectionSlug, offerProtectionEnabled = true, traitType, traitValue, traits) {
// Validate trait parameters
if (traits && traits.length > 0 && (traitType || traitValue)) {
throw new Error("Cannot use both 'traits' array and individual 'traitType'/'traitValue' parameters. Please use only one approach.");
}
if (traitType || traitValue) {
if (!traitType || !traitValue) {
throw new Error("Both traitType and traitValue must be defined if one is defined.");
}
}
if (traits && traits.length > 0) {
// Validate each trait in the array has both type and value
for (const trait of traits) {
if (!trait.type || !trait.value) {
throw new Error("Each trait must have both 'type' and 'value' properties.");
}
}
}
const payload = (0, utils_1.getBuildCollectionOfferPayload)(offererAddress, quantity, collectionSlug, offerProtectionEnabled, traitType, traitValue, traits);
const response = await this.fetcher.post((0, apiPaths_1.getBuildOfferPath)(), payload);
return response;
}
/**
* Get a list of collection offers for a given slug.
*/
async getCollectionOffers(slug, limit, next) {
return await this.fetcher.get((0, apiPaths_1.getCollectionOffersPath)(slug), {
limit,
next,
});
}
/**
* Post a collection offer to OpenSea.
*/
async postCollectionOffer(order, slug, traitType, traitValue, traits) {
const payload = (0, utils_1.getPostCollectionOfferPayload)(slug, order, traitType, traitValue, traits);
return await this.fetcher.post((0, apiPaths_1.getPostCollectionOfferPath)(), payload);
}
/**
* Gets all active offers for a specific NFT.
*/
async getNFTOffers(assetContractAddress, tokenId, limit, next, chain = this.chain) {
const response = await this.fetcher.get((0, apiPaths_1.getOrdersAPIPath)(chain, "seaport", types_1.OrderSide.OFFER), (0, utils_1.serializeOrdersQueryOptions)({
assetContractAddress,
tokenIds: [tokenId],
limit,
next,
}));
return response;
}
}
exports.OffersAPI = OffersAPI;
//# sourceMappingURL=offers.js.map