@opensea/sdk 10.3.0 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/api/api.d.ts +30 -43
  2. package/lib/api/api.js +36 -49
  3. package/lib/api/api.js.map +1 -1
  4. package/lib/api/apiPaths.d.ts +7 -2
  5. package/lib/api/apiPaths.js +25 -6
  6. package/lib/api/apiPaths.js.map +1 -1
  7. package/lib/api/listings.d.ts +10 -15
  8. package/lib/api/listings.js +12 -30
  9. package/lib/api/listings.js.map +1 -1
  10. package/lib/api/offers.d.ts +2 -2
  11. package/lib/api/offers.js +2 -9
  12. package/lib/api/offers.js.map +1 -1
  13. package/lib/api/orders.d.ts +4 -21
  14. package/lib/api/orders.js +15 -96
  15. package/lib/api/orders.js.map +1 -1
  16. package/lib/api/tokens.d.ts +6 -1
  17. package/lib/api/tokens.js +7 -0
  18. package/lib/api/tokens.js.map +1 -1
  19. package/lib/api/transactions.d.ts +16 -0
  20. package/lib/api/transactions.js +24 -0
  21. package/lib/api/transactions.js.map +1 -0
  22. package/lib/api/types.d.ts +33 -66
  23. package/lib/api/types.js.map +1 -1
  24. package/lib/orders/types.d.ts +0 -67
  25. package/lib/orders/types.js.map +1 -1
  26. package/lib/orders/utils.d.ts +1 -19
  27. package/lib/orders/utils.js +1 -62
  28. package/lib/orders/utils.js.map +1 -1
  29. package/lib/sdk/base.d.ts +9 -7
  30. package/lib/sdk/base.js +2 -2
  31. package/lib/sdk/orders.d.ts +13 -10
  32. package/lib/sdk/orders.js +6 -22
  33. package/lib/sdk/orders.js.map +1 -1
  34. package/lib/types.d.ts +0 -6
  35. package/package.json +2 -2
  36. package/src/api/api.ts +59 -91
  37. package/src/api/apiPaths.ts +26 -8
  38. package/src/api/listings.ts +24 -46
  39. package/src/api/offers.ts +8 -16
  40. package/src/api/orders.ts +40 -177
  41. package/src/api/tokens.ts +11 -0
  42. package/src/api/transactions.ts +28 -0
  43. package/src/api/types.ts +55 -72
  44. package/src/orders/types.ts +0 -74
  45. package/src/orders/utils.ts +2 -73
  46. package/src/sdk/base.ts +6 -6
  47. package/src/sdk/orders.ts +31 -32
  48. package/src/types.ts +0 -6
package/src/api/api.ts CHANGED
@@ -1,11 +1,5 @@
1
1
  import { API_BASE_MAINNET } from "../constants"
2
- import type {
3
- FulfillmentDataResponse,
4
- OrderAPIOptions,
5
- OrdersQueryOptions,
6
- OrderV2,
7
- ProtocolData,
8
- } from "../orders/types"
2
+ import type { FulfillmentDataResponse, ProtocolData } from "../orders/types"
9
3
  import {
10
4
  Chain,
11
5
  type OpenSeaAccount,
@@ -30,13 +24,14 @@ import { OffersAPI } from "./offers"
30
24
  import { OrdersAPI } from "./orders"
31
25
  import { SearchAPI } from "./search"
32
26
  import { TokensAPI } from "./tokens"
27
+ import { TransactionsAPI } from "./transactions"
33
28
  import {
34
29
  type BuildOfferResponse,
35
30
  type CancelOrderResponse,
36
31
  type CollectionOffer,
37
32
  CollectionOrderByOption,
38
- type CrossChainFulfillmentDataRequest,
39
- type CrossChainFulfillmentDataResponse,
33
+ type CrossChainFulfillmentRequest,
34
+ type CrossChainFulfillmentResponse,
40
35
  type DropMintRequest,
41
36
  type DropMintResponse,
42
37
  type GetAccountTokensArgs,
@@ -58,7 +53,6 @@ import {
58
53
  type GetNFTResponse,
59
54
  type GetOffersResponse,
60
55
  type GetOrderByHashResponse,
61
- type GetOrdersResponse,
62
56
  type GetSwapQuoteArgs,
63
57
  type GetSwapQuoteResponse,
64
58
  type GetTokenGroupResponse,
@@ -78,7 +72,13 @@ import {
78
72
  type ResolveAccountResponse,
79
73
  type SearchArgs,
80
74
  type SearchResponse,
75
+ type SwapExecuteRequest,
76
+ type SwapExecuteResponse,
77
+ type SweepCollectionRequest,
78
+ type SweepCollectionResponse,
81
79
  type TraitFilter,
80
+ type TransactionReceiptRequest,
81
+ type TransactionReceiptResponse,
82
82
  type ValidateMetadataResponse,
83
83
  } from "./types"
84
84
 
@@ -115,6 +115,7 @@ export class OpenSeaAPI {
115
115
  private tokensAPI: TokensAPI
116
116
  private chainsAPI: ChainsAPI
117
117
  private dropsAPI: DropsAPI
118
+ private transactionsAPI: TransactionsAPI
118
119
 
119
120
  /**
120
121
  * Create an instance of the OpenSeaAPI
@@ -143,7 +144,7 @@ export class OpenSeaAPI {
143
144
  // Initialize specialized API clients
144
145
  this.ordersAPI = new OrdersAPI(fetcher, this.chain)
145
146
  this.offersAPI = new OffersAPI(fetcher, this.chain)
146
- this.listingsAPI = new ListingsAPI(fetcher, this.chain)
147
+ this.listingsAPI = new ListingsAPI(fetcher)
147
148
  this.collectionsAPI = new CollectionsAPI(fetcher)
148
149
  this.nftsAPI = new NFTsAPI(fetcher, this.chain)
149
150
  this.accountsAPI = new AccountsAPI(fetcher, this.chain)
@@ -152,20 +153,7 @@ export class OpenSeaAPI {
152
153
  this.tokensAPI = new TokensAPI(fetcher)
153
154
  this.chainsAPI = new ChainsAPI(fetcher)
154
155
  this.dropsAPI = new DropsAPI(fetcher)
155
- }
156
-
157
- /**
158
- * Gets an order from API based on query options.
159
- * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
160
- * @param options Query options for fetching an order
161
- * @returns The first {@link OrderV2} returned by the API
162
- *
163
- * @throws An error if there are no matching orders.
164
- */
165
- public async getOrder(
166
- options: Omit<OrdersQueryOptions, "limit">,
167
- ): Promise<OrderV2> {
168
- return this.ordersAPI.getOrder(options)
156
+ this.transactionsAPI = new TransactionsAPI(fetcher)
169
157
  }
170
158
 
171
159
  /**
@@ -184,18 +172,6 @@ export class OpenSeaAPI {
184
172
  return this.ordersAPI.getOrderByHash(orderHash, protocolAddress, chain)
185
173
  }
186
174
 
187
- /**
188
- * Gets a list of orders from API based on query options.
189
- * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
190
- * @param options Query options for fetching orders
191
- * @returns The {@link GetOrdersResponse} returned by the API.
192
- */
193
- public async getOrders(
194
- options: Omit<OrdersQueryOptions, "limit">,
195
- ): Promise<GetOrdersResponse> {
196
- return this.ordersAPI.getOrders({ ...options, pageSize: this.pageSize })
197
- }
198
-
199
175
  /**
200
176
  * Gets all offers for a given collection.
201
177
  * @param collectionSlug The slug of the collection.
@@ -326,11 +302,11 @@ export class OpenSeaAPI {
326
302
  * Supports same-chain, cross-token, and cross-chain purchases (up to 50 listings).
327
303
  * All listings must be EVM (Seaport orders). Payment can be from any chain (EVM or SVM).
328
304
  * @param request The cross-chain fulfillment request containing listings, fulfiller, payment, and optional recipient
329
- * @returns The {@link CrossChainFulfillmentDataResponse} with ordered transactions to sign and submit
305
+ * @returns The {@link CrossChainFulfillmentResponse} with ordered transactions to sign and submit
330
306
  */
331
307
  public async getCrossChainFulfillmentData(
332
- request: CrossChainFulfillmentDataRequest,
333
- ): Promise<CrossChainFulfillmentDataResponse> {
308
+ request: CrossChainFulfillmentRequest,
309
+ ): Promise<CrossChainFulfillmentResponse> {
334
310
  return this.listingsAPI.getCrossChainFulfillmentData(request)
335
311
  }
336
312
 
@@ -371,20 +347,6 @@ export class OpenSeaAPI {
371
347
  )
372
348
  }
373
349
 
374
- /**
375
- * Post an order to OpenSea.
376
- * @deprecated Use postListing or postOffer instead.
377
- * @param order The order to post
378
- * @param apiOptions API options for the order
379
- * @returns The {@link OrderV2} posted to the API.
380
- */
381
- public async postOrder(
382
- order: ProtocolData,
383
- apiOptions: OrderAPIOptions,
384
- ): Promise<OrderV2> {
385
- return this.ordersAPI.postOrder(order, apiOptions)
386
- }
387
-
388
350
  /**
389
351
  * Post a listing to OpenSea. Returns the new v2 Listing response format.
390
352
  * @param order The order to post
@@ -864,55 +826,61 @@ export class OpenSeaAPI {
864
826
 
865
827
  /**
866
828
  * Gets all active offers for a specific NFT (not just the best offer).
867
- * @param assetContractAddress The NFT contract address.
868
- * @param tokenId The token identifier.
869
- * @param limit The number of offers to return. Must be between 1 and 100.
870
- * @param next The cursor for the next page of results. This is returned from a previous request.
871
- * @param chain The chain where the NFT is located. Defaults to the chain set in the constructor.
829
+ * @param collectionSlug The collection slug.
830
+ * @param identifier The NFT token id.
831
+ * @param limit The number of offers to return. Must be between 1 and 200.
832
+ * @param next The cursor for the next page of results.
872
833
  * @returns The {@link GetOffersResponse} returned by the API.
873
834
  */
874
- public async getNFTOffers(
875
- assetContractAddress: string,
876
- tokenId: string,
835
+ public async getOffersByNFT(
836
+ collectionSlug: string,
837
+ identifier: string | number,
877
838
  limit?: number,
878
839
  next?: string,
879
- chain: Chain = this.chain,
880
840
  ): Promise<GetOffersResponse> {
881
- return this.offersAPI.getNFTOffers(
882
- assetContractAddress,
883
- tokenId,
841
+ return this.offersAPI.getOffersByNFT(
842
+ collectionSlug,
843
+ identifier,
884
844
  limit,
885
845
  next,
886
- chain,
887
846
  )
888
847
  }
889
848
 
890
849
  /**
891
- * Gets all active listings for a specific NFT (not just the best listing).
892
- * @param assetContractAddress The NFT contract address.
893
- * @param tokenId The token identifier.
894
- * @param limit The number of listings to return. Must be between 1 and 100.
895
- * @param next The cursor for the next page of results. This is returned from a previous request.
896
- * @param chain The chain where the NFT is located. Defaults to the chain set in the constructor.
897
- * @param includePrivateListings Whether to include private listings (default: false)
898
- * @returns The {@link GetListingsResponse} returned by the API.
850
+ * Bulk-buy items from a collection using any payment token, including
851
+ * cross-chain. Returns an ordered list of transactions to execute.
852
+ * @param request The sweep request containing buyer, collection, payment, and item caps.
853
+ * @returns The {@link SweepCollectionResponse} returned by the API.
899
854
  */
900
- public async getNFTListings(
901
- assetContractAddress: string,
902
- tokenId: string,
903
- limit?: number,
904
- next?: string,
905
- chain: Chain = this.chain,
906
- includePrivateListings?: boolean,
907
- ): Promise<GetListingsResponse> {
908
- return this.listingsAPI.getNFTListings(
909
- assetContractAddress,
910
- tokenId,
911
- limit,
912
- next,
913
- chain,
914
- includePrivateListings,
915
- )
855
+ public async sweepCollection(
856
+ request: SweepCollectionRequest,
857
+ ): Promise<SweepCollectionResponse> {
858
+ return this.listingsAPI.sweepCollection(request)
859
+ }
860
+
861
+ /**
862
+ * Get executable transactions for a token swap. Companion to
863
+ * {@link OpenSeaAPI.getSwapQuote} — quote first, then execute.
864
+ * @param request The swap execution request.
865
+ * @returns The {@link SwapExecuteResponse} with transactions and a quote.
866
+ */
867
+ public async executeSwap(
868
+ request: SwapExecuteRequest,
869
+ ): Promise<SwapExecuteResponse> {
870
+ return this.tokensAPI.executeSwap(request)
871
+ }
872
+
873
+ /**
874
+ * Get the receipt/status for a submitted transaction. Works for all transaction
875
+ * types: listing fulfillments, cross-chain buys, sweeps, offer fulfillments,
876
+ * and token swaps. Poll this endpoint to check completion status.
877
+ * @param request The transaction receipt request.
878
+ * @returns The {@link TransactionReceiptResponse} returned by the API.
879
+ */
880
+ public async getTransactionReceipt(
881
+ request: TransactionReceiptRequest,
882
+ ): Promise<TransactionReceiptResponse> {
883
+ return this.transactionsAPI.getTransactionReceipt(request)
916
884
  }
917
885
 
918
886
  /**
@@ -1,16 +1,15 @@
1
1
  import type { OrderProtocol } from "../orders/types"
2
- import { type Chain, OrderSide } from "../types"
2
+ import type { Chain } from "../types"
3
3
 
4
4
  /** Base path prefix for all OpenSea API v2 endpoints. */
5
5
  export const API_V2_PREFIX = "/api/v2"
6
6
 
7
- export const getOrdersAPIPath = (
8
- chain: Chain,
9
- protocol: OrderProtocol,
10
- side: OrderSide,
11
- ) => {
12
- const sidePath = side === OrderSide.LISTING ? "listings" : "offers"
13
- return `${API_V2_PREFIX}/orders/${chain}/${protocol}/${sidePath}`
7
+ export const getPostListingPath = (chain: Chain, protocol: OrderProtocol) => {
8
+ return `${API_V2_PREFIX}/orders/${chain}/${protocol}/listings`
9
+ }
10
+
11
+ export const getPostOfferPath = (chain: Chain, protocol: OrderProtocol) => {
12
+ return `${API_V2_PREFIX}/orders/${chain}/${protocol}/offers`
14
13
  }
15
14
 
16
15
  export const getAllOffersAPIPath = (collectionSlug: string) => {
@@ -119,6 +118,25 @@ export const getTraitOffersPath = (collectionSlug: string) => {
119
118
  return `${API_V2_PREFIX}/offers/collection/${collectionSlug}/traits`
120
119
  }
121
120
 
121
+ export const getOffersByNFTPath = (
122
+ collectionSlug: string,
123
+ identifier: string | number,
124
+ ) => {
125
+ return `${API_V2_PREFIX}/offers/collection/${collectionSlug}/nfts/${identifier}`
126
+ }
127
+
128
+ export const getSweepListingsPath = () => {
129
+ return `${API_V2_PREFIX}/listings/sweep`
130
+ }
131
+
132
+ export const getSwapExecutePath = () => {
133
+ return `${API_V2_PREFIX}/swap/execute`
134
+ }
135
+
136
+ export const getTransactionReceiptPath = () => {
137
+ return `${API_V2_PREFIX}/transactions/receipt`
138
+ }
139
+
122
140
  export const getEventsAPIPath = () => {
123
141
  return `${API_V2_PREFIX}/events`
124
142
  }
@@ -1,19 +1,19 @@
1
- import { serializeOrdersQueryOptions } from "../orders/utils"
2
- import { type Chain, OrderSide } from "../types"
3
1
  import {
4
2
  getAllListingsAPIPath,
5
3
  getBestListingAPIPath,
6
4
  getBestListingsAPIPath,
7
5
  getCrossChainFulfillmentDataPath,
8
- getOrdersAPIPath,
6
+ getSweepListingsPath,
9
7
  } from "./apiPaths"
10
8
  import type { Fetcher } from "./fetcher"
11
9
  import {
12
- type CrossChainFulfillmentDataRequest,
13
- type CrossChainFulfillmentDataResponse,
10
+ type CrossChainFulfillmentRequest,
11
+ type CrossChainFulfillmentResponse,
14
12
  encodeTraitsParam,
15
13
  type GetBestListingResponse,
16
14
  type GetListingsResponse,
15
+ type SweepCollectionRequest,
16
+ type SweepCollectionResponse,
17
17
  type TraitFilter,
18
18
  } from "./types"
19
19
 
@@ -21,10 +21,7 @@ import {
21
21
  * Listing-related API operations
22
22
  */
23
23
  export class ListingsAPI {
24
- constructor(
25
- private fetcher: Fetcher,
26
- private chain: Chain,
27
- ) {}
24
+ constructor(private fetcher: Fetcher) {}
28
25
 
29
26
  /**
30
27
  * Gets all listings for a given collection.
@@ -97,51 +94,32 @@ export class ListingsAPI {
97
94
  return response
98
95
  }
99
96
 
100
- /**
101
- * Gets all active listings for a specific NFT.
102
- * @param assetContractAddress The NFT contract address
103
- * @param tokenId The token ID
104
- * @param limit The number of listings to return
105
- * @param next The cursor for pagination
106
- * @param chain The blockchain chain
107
- * @param includePrivateListings Whether to include private listings (default: false)
108
- */
109
- async getNFTListings(
110
- assetContractAddress: string,
111
- tokenId: string,
112
- limit?: number,
113
- next?: string,
114
- chain: Chain = this.chain,
115
- includePrivateListings?: boolean,
116
- ): Promise<GetListingsResponse> {
117
- const response = await this.fetcher.get<GetListingsResponse>(
118
- getOrdersAPIPath(chain, "seaport", OrderSide.LISTING),
119
- {
120
- ...serializeOrdersQueryOptions({
121
- assetContractAddress,
122
- tokenIds: [tokenId],
123
- limit,
124
- next,
125
- }),
126
- ...(includePrivateListings !== undefined && {
127
- include_private_listings: includePrivateListings,
128
- }),
129
- },
130
- )
131
- return response
132
- }
133
-
134
97
  /**
135
98
  * Get cross-chain fulfillment data for one or more listings.
136
99
  * Supports same-chain, cross-token, and cross-chain purchases.
137
100
  * @param request The cross-chain fulfillment request
138
101
  */
139
102
  async getCrossChainFulfillmentData(
140
- request: CrossChainFulfillmentDataRequest,
141
- ): Promise<CrossChainFulfillmentDataResponse> {
142
- return this.fetcher.post<CrossChainFulfillmentDataResponse>(
103
+ request: CrossChainFulfillmentRequest,
104
+ ): Promise<CrossChainFulfillmentResponse> {
105
+ return this.fetcher.post<CrossChainFulfillmentResponse>(
143
106
  getCrossChainFulfillmentDataPath(),
144
107
  request,
145
108
  )
146
109
  }
110
+
111
+ /**
112
+ * Bulk-buy items from a collection.
113
+ * If a requested item becomes unavailable, the system can automatically
114
+ * substitute it with the next cheapest listing from the same collection
115
+ * (enabled by default). Returns an ordered list of transactions to execute.
116
+ */
117
+ async sweepCollection(
118
+ request: SweepCollectionRequest,
119
+ ): Promise<SweepCollectionResponse> {
120
+ return this.fetcher.post<SweepCollectionResponse>(
121
+ getSweepListingsPath(),
122
+ request,
123
+ )
124
+ }
147
125
  }
package/src/api/offers.ts CHANGED
@@ -2,15 +2,14 @@ import type { ProtocolData } from "../orders/types"
2
2
  import {
3
3
  getBuildCollectionOfferPayload,
4
4
  getPostCollectionOfferPayload,
5
- serializeOrdersQueryOptions,
6
5
  } from "../orders/utils"
7
- import { type Chain, OrderSide } from "../types"
6
+ import type { Chain } from "../types"
8
7
  import {
9
8
  getAllOffersAPIPath,
10
9
  getBestOfferAPIPath,
11
10
  getBuildOfferPath,
12
11
  getCollectionOffersPath,
13
- getOrdersAPIPath,
12
+ getOffersByNFTPath,
14
13
  getPostCollectionOfferPath,
15
14
  getTraitOffersPath,
16
15
  } from "./apiPaths"
@@ -221,22 +220,15 @@ export class OffersAPI {
221
220
  /**
222
221
  * Gets all active offers for a specific NFT.
223
222
  */
224
- async getNFTOffers(
225
- assetContractAddress: string,
226
- tokenId: string,
223
+ async getOffersByNFT(
224
+ collectionSlug: string,
225
+ identifier: string | number,
227
226
  limit?: number,
228
227
  next?: string,
229
- chain: Chain = this.chain,
230
228
  ): Promise<GetOffersResponse> {
231
- const response = await this.fetcher.get<GetOffersResponse>(
232
- getOrdersAPIPath(chain, "seaport", OrderSide.OFFER),
233
- serializeOrdersQueryOptions({
234
- assetContractAddress,
235
- tokenIds: [tokenId],
236
- limit,
237
- next,
238
- }),
229
+ return this.fetcher.get<GetOffersResponse>(
230
+ getOffersByNFTPath(collectionSlug, identifier),
231
+ { limit, next },
239
232
  )
240
- return response
241
233
  }
242
234
  }