opensea-js 6.1.15 → 7.0.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 (62) hide show
  1. package/README.md +2 -2
  2. package/lib/api/api.d.ts +39 -78
  3. package/lib/api/api.js +152 -337
  4. package/lib/api/api.js.map +1 -1
  5. package/lib/api/apiPaths.d.ts +20 -0
  6. package/lib/api/apiPaths.js +78 -0
  7. package/lib/api/apiPaths.js.map +1 -0
  8. package/lib/api/types.d.ts +3 -35
  9. package/lib/constants.d.ts +1 -4
  10. package/lib/constants.js +6 -12
  11. package/lib/constants.js.map +1 -1
  12. package/lib/index.d.ts +6 -7
  13. package/lib/index.js +3 -8
  14. package/lib/index.js.map +1 -1
  15. package/lib/orders/privateListings.js +14 -9
  16. package/lib/orders/privateListings.js.map +1 -1
  17. package/lib/orders/types.d.ts +5 -15
  18. package/lib/orders/utils.d.ts +4 -19
  19. package/lib/orders/utils.js +7 -68
  20. package/lib/orders/utils.js.map +1 -1
  21. package/lib/sdk.d.ts +11 -56
  22. package/lib/sdk.js +370 -497
  23. package/lib/sdk.js.map +1 -1
  24. package/lib/typechain/contracts/ERC1155.d.ts +216 -167
  25. package/lib/typechain/contracts/ERC20.d.ts +120 -143
  26. package/lib/typechain/contracts/ERC721.d.ts +190 -194
  27. package/lib/typechain/contracts/common.d.ts +40 -11
  28. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +2 -3
  29. package/lib/typechain/contracts/factories/ERC1155__factory.js +3 -3
  30. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -1
  31. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +2 -3
  32. package/lib/typechain/contracts/factories/ERC20__factory.js +3 -3
  33. package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -1
  34. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +2 -3
  35. package/lib/typechain/contracts/factories/ERC721__factory.js +3 -3
  36. package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -1
  37. package/lib/types.d.ts +117 -438
  38. package/lib/types.js +11 -56
  39. package/lib/types.js.map +1 -1
  40. package/lib/utils/utils.d.ts +15 -40
  41. package/lib/utils/utils.js +99 -237
  42. package/lib/utils/utils.js.map +1 -1
  43. package/package.json +9 -10
  44. package/src/api/api.ts +142 -327
  45. package/src/api/apiPaths.ts +93 -0
  46. package/src/api/types.ts +3 -43
  47. package/src/constants.ts +3 -9
  48. package/src/index.ts +6 -31
  49. package/src/orders/privateListings.ts +4 -5
  50. package/src/orders/types.ts +5 -15
  51. package/src/orders/utils.ts +6 -86
  52. package/src/sdk.ts +149 -268
  53. package/src/typechain/contracts/ERC1155.ts +336 -397
  54. package/src/typechain/contracts/ERC20.ts +208 -289
  55. package/src/typechain/contracts/ERC721.ts +297 -446
  56. package/src/typechain/contracts/common.ts +108 -21
  57. package/src/typechain/contracts/factories/ERC1155__factory.ts +4 -8
  58. package/src/typechain/contracts/factories/ERC20__factory.ts +4 -5
  59. package/src/typechain/contracts/factories/ERC721__factory.ts +4 -5
  60. package/src/types.ts +115 -555
  61. package/src/utils/utils.ts +100 -262
  62. package/lib/bundle.js +0 -58051
package/README.md CHANGED
@@ -12,11 +12,11 @@
12
12
 
13
13
  # OpenSea.js <!-- omit in toc -->
14
14
 
15
- This is the JavaScript SDK for [OpenSea](https://opensea.io), the largest marketplace for NFTs.
15
+ This is the TypeScript SDK for [OpenSea](https://opensea.io), the largest marketplace for NFTs.
16
16
 
17
17
  It allows developers to access the official orderbook, filter it, create listings and offers, and complete trades programmatically.
18
18
 
19
- Get started by [requesting an API key](https://docs.opensea.io/reference/api-keys) and instantiating your own OpenSea SDK instance. Then you can create orders off-chain or fulfill orders on-chain, and listen to events (like `ApproveAllAssets` or `WrapEth`) in the process.
19
+ Get started by [requesting an API key](https://docs.opensea.io/reference/api-keys) and instantiating your own OpenSea SDK instance. Then you can create orders off-chain or fulfill orders on-chain, and listen to events in the process.
20
20
 
21
21
  Happy seafaring! ⛵️
22
22
 
package/lib/api/api.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { ethers } from "ethers";
2
- import { BuildOfferResponse, ListNFTsResponse, GetNFTResponse, ListCollectionOffersResponse, GetAssetsResponse, GetOrdersResponse, GetPaymentTokensResponse, GetBundlesResponse, GetBestOfferResponse, GetBestListingResponse, GetOffersResponse, GetListingsResponse, CollectionOffer } from "./types";
3
- import { FulfillmentDataResponse, OrderAPIOptions, OrderSide, OrdersQueryOptions, OrderV2, ProtocolData } from "../orders/types";
4
- import { Chain, OpenSeaAPIConfig, OpenSeaAsset, OpenSeaAssetBundle, OpenSeaAssetBundleQuery, OpenSeaAssetQuery, OpenSeaCollection, OpenSeaFungibleTokenQuery } from "../types";
1
+ import { BuildOfferResponse, ListNFTsResponse, GetNFTResponse, ListCollectionOffersResponse, GetOrdersResponse, GetBestOfferResponse, GetBestListingResponse, GetOffersResponse, GetListingsResponse, CollectionOffer } from "./types";
2
+ import { FulfillmentDataResponse, OrderAPIOptions, OrdersQueryOptions, OrderV2, ProtocolData } from "../orders/types";
3
+ import { Chain, OpenSeaAPIConfig, OpenSeaAccount, OpenSeaCollection, OpenSeaCollectionStats, OpenSeaPaymentToken, OrderSide } from "../types";
5
4
  /**
6
5
  * The API class for the OpenSea SDK.
7
6
  * @category Main Classes
@@ -21,11 +20,10 @@ export declare class OpenSeaAPI {
21
20
  logger: (arg: string) => void;
22
21
  private apiKey;
23
22
  private chain;
24
- private retryDelay;
25
23
  /**
26
- * Create an instance of the OpenSea API
24
+ * Create an instance of the OpenSeaAPI
27
25
  * @param config OpenSeaAPIConfig for setting up the API, including an optional API key, Chain name, and base URL
28
- * @param logger Optional function for logging debug strings before and after requests are made
26
+ * @param logger Optional function for logging debug strings before and after requests are made. Defaults to no logging
29
27
  */
30
28
  constructor(config: OpenSeaAPIConfig, logger?: (arg: string) => void);
31
29
  /**
@@ -94,6 +92,12 @@ export declare class OpenSeaAPI {
94
92
  * @returns The {@link GetBestListingResponse} returned by the API.
95
93
  */
96
94
  getBestListing(collectionSlug: string, tokenId: string | number): Promise<GetBestListingResponse>;
95
+ /**
96
+ * Gets the best listing for a given collection.
97
+ * @param collectionSlug The slug of the collection.
98
+ * @returns The {@link GetListingsResponse} returned by the API.
99
+ */
100
+ getBestListings(collectionSlug: string): Promise<GetListingsResponse>;
97
101
  /**
98
102
  * Generate the data needed to fulfill a listing or an offer onchain.
99
103
  * @param fulfillerAddress The wallet address which will be used to fulfill the order
@@ -111,102 +115,65 @@ export declare class OpenSeaAPI {
111
115
  * @param apiOptions.side The side of the order (buy or sell).
112
116
  * @param apiOptions.protocolAddress The address of the seaport contract.
113
117
  * @param options
114
- * @param options.retries Number of times to retry if the service is unavailable for any reason.
115
118
  * @returns The {@link OrderV2} posted to the API.
116
119
  */
117
- postOrder(order: ProtocolData, apiOptions: OrderAPIOptions, { retries }?: {
118
- retries?: number;
119
- }): Promise<OrderV2>;
120
+ postOrder(order: ProtocolData, apiOptions: OrderAPIOptions): Promise<OrderV2>;
120
121
  /**
121
122
  * Build a OpenSea collection offer.
122
123
  * @param offererAddress The wallet address which is creating the offer.
123
124
  * @param quantity The number of NFTs requested in the offer.
124
125
  * @param collectionSlug The slug (identifier) of the collection to build the offer for.
126
+ * @param offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading.
125
127
  * @returns The {@link BuildOfferResponse} returned by the API.
126
128
  */
127
- buildOffer(offererAddress: string, quantity: number, collectionSlug: string): Promise<BuildOfferResponse>;
129
+ buildOffer(offererAddress: string, quantity: number, collectionSlug: string, offerProtectionEnabled?: boolean): Promise<BuildOfferResponse>;
128
130
  /**
129
131
  * Get a list collection offers for a given slug.
130
132
  * @param slug The slug (identifier) of the collection to list offers for
131
- * @param retries Number of times to retry if the service is unavailable for any reason.
132
133
  * @returns The {@link ListCollectionOffersResponse} returned by the API.
133
134
  */
134
- getCollectionOffers(slug: string, retries?: number): Promise<ListCollectionOffersResponse | null>;
135
+ getCollectionOffers(slug: string): Promise<ListCollectionOffersResponse | null>;
135
136
  /**
136
137
  * Post a collection offer to OpenSea.
137
138
  * @param order The collection offer to post.
138
139
  * @param slug The slug (identifier) of the collection to post the offer for.
139
- * @param retries Number of times to retry if the service is unavailable for any reason.
140
140
  * @returns The {@link Offer} returned to the API.
141
141
  */
142
- postCollectionOffer(order: ProtocolData, slug: string, retries?: number): Promise<CollectionOffer | null>;
143
- /**
144
- * Fetch an asset.
145
- * @deprecated Use {@link getNFT} for multichain capabilities.
146
- * @param options
147
- * @param options.tokenAddress The asset's contract address.
148
- * @param options.tokenId The asset's token ID, or null if ERC-20
149
- * @param retries Number of times to retry if the service is unavailable for any reason
150
- * @returns The {@link OpenSeaAsset} returned by the API.
151
- * @throws An error if the function is called on an unsupported chain.
152
- */
153
- getAsset({ tokenAddress, tokenId, }: {
154
- tokenAddress: string;
155
- tokenId: string | number | null;
156
- }, retries?: number): Promise<OpenSeaAsset>;
142
+ postCollectionOffer(order: ProtocolData, slug: string): Promise<CollectionOffer | null>;
157
143
  /**
158
144
  * Fetch multiple NFTs for a collection.
159
145
  * @param slug The slug (identifier) of the collection
160
146
  * @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
161
147
  * @param next Cursor to retrieve the next page of NFTs
162
- * @param retries Number of times to retry if the service is unavailable for any reason.
163
148
  * @returns The {@link ListNFTsResponse} returned by the API.
164
149
  */
165
- getNFTsByCollection(slug: string, limit?: number | undefined, next?: string | undefined, retries?: number): Promise<ListNFTsResponse>;
150
+ getNFTsByCollection(slug: string, limit?: number | undefined, next?: string | undefined): Promise<ListNFTsResponse>;
166
151
  /**
167
152
  * Fetch multiple NFTs for a contract.
168
- * @param chain The NFT's chain.
169
153
  * @param address The NFT's contract address.
170
154
  * @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
171
155
  * @param next Cursor to retrieve the next page of NFTs.
172
- * @param retries Number of times to retry if the service is unavailable for any reason.
156
+ * @param chain The NFT's chain.
173
157
  * @returns The {@link ListNFTsResponse} returned by the API.
174
158
  */
175
- getNFTsByContract(chain: Chain, address: string, limit?: number | undefined, next?: string | undefined, retries?: number): Promise<ListNFTsResponse>;
159
+ getNFTsByContract(address: string, limit?: number | undefined, next?: string | undefined, chain?: Chain): Promise<ListNFTsResponse>;
176
160
  /**
177
161
  * Fetch NFTs owned by an account.
178
162
  * @param address The address of the account
179
163
  * @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
180
164
  * @param next Cursor to retrieve the next page of NFTs
181
- * @param retries Number of times to retry if the service is unavailable for any reason.
182
165
  * @param chain The chain to query. Defaults to the chain set in the constructor.
183
166
  * @returns The {@link ListNFTsResponse} returned by the API.
184
167
  */
185
- getNFTsByAccount(address: string, limit?: number | undefined, next?: string | undefined, retries?: number, chain?: Chain): Promise<ListNFTsResponse>;
168
+ getNFTsByAccount(address: string, limit?: number | undefined, next?: string | undefined, chain?: Chain): Promise<ListNFTsResponse>;
186
169
  /**
187
170
  * Fetch metadata, traits, ownership information, and rarity for a single NFT.
188
- * @param chain The NFT's chain.
189
171
  * @param address The NFT's contract address.
190
172
  * @param identifier the identifier of the NFT (i.e. Token ID)
191
- * @param retries Number of times to retry if the service is unavailable for any reason
173
+ * @param chain The NFT's chain.
192
174
  * @returns The {@link GetNFTResponse} returned by the API.
193
175
  */
194
- getNFT(chain: Chain, address: string, identifier: string, retries?: number): Promise<GetNFTResponse>;
195
- /**
196
- * Fetch a list of assets.
197
- * @deprecated Use {@link getNFTsByContract} or {@link getNFTsByCollection} for multichain capabilities.
198
- * @param query Options to filter the list returned.
199
- * @param query.owner The wallet address of the owner of the assets.
200
- * @param query.asset_contract_address The Asset's contract address.
201
- * @param query.token_ids String array of token IDs to filter by.
202
- * @param query.order_by The field to order the list by.
203
- * @param query.order_direction The direction to order the list.
204
- * @param query.limit The number of assets to retrieve. Must be greater than 0 and less than 201.
205
- * @param query.cursor Cursor to retrieve the next page of assets.
206
- * @throws An error if the function is called on an unsupported chain.
207
- * @returns The {@link GetAssetsResponse} returned by the API.
208
- */
209
- getAssets(query?: OpenSeaAssetQuery): Promise<GetAssetsResponse>;
176
+ getNFT(address: string, identifier: string, chain?: Chain): Promise<GetNFTResponse>;
210
177
  /**
211
178
  * Fetch an OpenSea collection.
212
179
  * @param slug The slug (identifier) of the collection.
@@ -214,39 +181,33 @@ export declare class OpenSeaAPI {
214
181
  */
215
182
  getCollection(slug: string): Promise<OpenSeaCollection>;
216
183
  /**
217
- * Fetch list of fungible tokens.
218
- * @param query Query to use for getting tokens. See {@link OpenSeaFungibleTokenQuery}.
219
- * @param page Page number to fetch. Defaults to 1.
220
- * @param retries Number of times to retry if the service is unavailable for any reason.
221
- * @throws An error if the function is called on an unsupported chain.
222
- * @returns The {@link GetPaymentTokensResponse} returned by the API.
184
+ * Fetch stats for an OpenSea collection.
185
+ * @param slug The slug (identifier) of the collection.
186
+ * @returns The {@link OpenSeaCollection} returned by the API.
223
187
  */
224
- getPaymentTokens(query?: OpenSeaFungibleTokenQuery, page?: number, retries?: number): Promise<GetPaymentTokensResponse>;
188
+ getCollectionStats(slug: string): Promise<OpenSeaCollectionStats>;
225
189
  /**
226
- * Fetch a bundle from the API.
227
- * @param options
228
- * @param options.slug The bundle's identifier
229
- * @returns The {@link OpenSeaAssetBundle} returned by the API. If not found, returns null.
190
+ * Fetch a payment token.
191
+ * @param query Query to use for getting tokens. See {@link OpenSeaPaymentTokenQuery}.
192
+ * @param next The cursor for the next page of results. This is returned from a previous request.
193
+ * @returns The {@link OpenSeaPaymentToken} returned by the API.
230
194
  */
231
- getBundle({ slug, }: {
232
- slug: string;
233
- }): Promise<OpenSeaAssetBundle | null>;
195
+ getPaymentToken(address: string, chain?: Chain): Promise<OpenSeaPaymentToken>;
234
196
  /**
235
- * Fetch list of bundles from the API.
236
- * @param query Query to use for getting bundles. See {@link OpenSeaAssetBundleQuery}.
237
- * @param page Page number to fetch. Defaults to 1.
238
- * @returns The {@link GetBundlesResponse} returned by the API.
197
+ * Fetch account for an address.
198
+ * @param query Query to use for getting tokens. See {@link OpenSeaPaymentTokenQuery}.
199
+ * @param next The cursor for the next page of results. This is returned from a previous request.
200
+ * @returns The {@link GetAccountResponse} returned by the API.
239
201
  */
240
- getBundles(query?: OpenSeaAssetBundleQuery, page?: number): Promise<GetBundlesResponse>;
202
+ getAccount(address: string): Promise<OpenSeaAccount>;
241
203
  /**
242
204
  * Force refresh the metadata for an NFT.
243
- * @param chain The chain where the NFT is located.
244
205
  * @param address The address of the NFT's contract.
245
206
  * @param identifier The identifier of the NFT.
246
- * @param retries Number of times to retry if the service is unavailable for any reason.
207
+ * @param chain The chain where the NFT is located.
247
208
  * @returns The response from the API.
248
209
  */
249
- refreshNFTMetadata(chain: Chain, address: string, identifier: string, retries?: number): Promise<Response>;
210
+ refreshNFTMetadata(address: string, identifier: string, chain?: Chain): Promise<Response>;
250
211
  /**
251
212
  * Generic fetch method for any API endpoint
252
213
  * @param apiPath Path to URL endpoint under API
@@ -261,7 +222,7 @@ export declare class OpenSeaAPI {
261
222
  * @param opts ethers ConnectionInfo, similar to Fetch API.
262
223
  * @returns @typeParam T The response from the API.
263
224
  */
264
- post<T>(apiPath: string, body?: object, opts?: ethers.utils.ConnectionInfo): Promise<T>;
225
+ post<T>(apiPath: string, body?: object, opts?: object): Promise<T>;
265
226
  private objectToSearchParams;
266
227
  /**
267
228
  * Get from an API Endpoint, sending auth token in headers