@opensea/sdk 9.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.
- package/LICENSE +7 -0
- package/README.md +70 -0
- package/lib/api/accounts.d.ts +27 -0
- package/lib/api/accounts.js +46 -0
- package/lib/api/accounts.js.map +1 -0
- package/lib/api/api.d.ts +489 -0
- package/lib/api/api.js +754 -0
- package/lib/api/api.js.map +1 -0
- package/lib/api/apiPaths.d.ts +46 -0
- package/lib/api/apiPaths.js +176 -0
- package/lib/api/apiPaths.js.map +1 -0
- package/lib/api/chains.d.ts +13 -0
- package/lib/api/chains.js +22 -0
- package/lib/api/chains.js.map +1 -0
- package/lib/api/collections.d.ts +34 -0
- package/lib/api/collections.js +80 -0
- package/lib/api/collections.js.map +1 -0
- package/lib/api/drops.d.ts +21 -0
- package/lib/api/drops.js +39 -0
- package/lib/api/drops.js.map +1 -0
- package/lib/api/events.d.ts +26 -0
- package/lib/api/events.js +43 -0
- package/lib/api/events.js.map +1 -0
- package/lib/api/fetcher.d.ts +24 -0
- package/lib/api/fetcher.js +3 -0
- package/lib/api/fetcher.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +19 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/listings.d.ts +44 -0
- package/lib/api/listings.js +88 -0
- package/lib/api/listings.js.map +1 -0
- package/lib/api/nfts.d.ts +39 -0
- package/lib/api/nfts.js +79 -0
- package/lib/api/nfts.js.map +1 -0
- package/lib/api/offers.d.ts +54 -0
- package/lib/api/offers.js +124 -0
- package/lib/api/offers.js.map +1 -0
- package/lib/api/orders.d.ts +50 -0
- package/lib/api/orders.js +153 -0
- package/lib/api/orders.js.map +1 -0
- package/lib/api/search.d.ts +13 -0
- package/lib/api/search.js +22 -0
- package/lib/api/search.js.map +1 -0
- package/lib/api/tokens.d.ts +25 -0
- package/lib/api/tokens.js +43 -0
- package/lib/api/tokens.js.map +1 -0
- package/lib/api/types.d.ts +1113 -0
- package/lib/api/types.js +65 -0
- package/lib/api/types.js.map +1 -0
- package/lib/constants.d.ts +22 -0
- package/lib/constants.js +52 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/orders/privateListings.d.ts +12 -0
- package/lib/orders/privateListings.js +130 -0
- package/lib/orders/privateListings.js.map +1 -0
- package/lib/orders/types.d.ts +160 -0
- package/lib/orders/types.js +10 -0
- package/lib/orders/types.js.map +1 -0
- package/lib/orders/utils.d.ts +89 -0
- package/lib/orders/utils.js +177 -0
- package/lib/orders/utils.js.map +1 -0
- package/lib/sdk/assets.d.ts +104 -0
- package/lib/sdk/assets.js +398 -0
- package/lib/sdk/assets.js.map +1 -0
- package/lib/sdk/cancellation.d.ts +97 -0
- package/lib/sdk/cancellation.js +235 -0
- package/lib/sdk/cancellation.js.map +1 -0
- package/lib/sdk/context.d.ts +28 -0
- package/lib/sdk/context.js +3 -0
- package/lib/sdk/context.js.map +1 -0
- package/lib/sdk/fulfillment.d.ts +153 -0
- package/lib/sdk/fulfillment.js +298 -0
- package/lib/sdk/fulfillment.js.map +1 -0
- package/lib/sdk/orders.d.ts +253 -0
- package/lib/sdk/orders.js +679 -0
- package/lib/sdk/orders.js.map +1 -0
- package/lib/sdk/tokens.d.ts +31 -0
- package/lib/sdk/tokens.js +65 -0
- package/lib/sdk/tokens.js.map +1 -0
- package/lib/sdk.d.ts +560 -0
- package/lib/sdk.js +693 -0
- package/lib/sdk.js.map +1 -0
- package/lib/src/api/accounts.d.ts +18 -0
- package/lib/src/api/accounts.js +30 -0
- package/lib/src/api/accounts.js.map +1 -0
- package/lib/src/api/api.d.ts +429 -0
- package/lib/src/api/api.js +652 -0
- package/lib/src/api/api.js.map +1 -0
- package/lib/src/api/apiPaths.d.ts +37 -0
- package/lib/src/api/apiPaths.js +140 -0
- package/lib/src/api/apiPaths.js.map +1 -0
- package/lib/src/api/collections.d.ts +26 -0
- package/lib/src/api/collections.js +57 -0
- package/lib/src/api/collections.js.map +1 -0
- package/lib/src/api/events.d.ts +26 -0
- package/lib/src/api/events.js +42 -0
- package/lib/src/api/events.js.map +1 -0
- package/lib/src/api/fetcher.d.ts +24 -0
- package/lib/src/api/fetcher.js +3 -0
- package/lib/src/api/fetcher.js.map +1 -0
- package/lib/src/api/index.d.ts +2 -0
- package/lib/src/api/index.js +19 -0
- package/lib/src/api/index.js.map +1 -0
- package/lib/src/api/listings.d.ts +44 -0
- package/lib/src/api/listings.js +86 -0
- package/lib/src/api/listings.js.map +1 -0
- package/lib/src/api/nfts.d.ts +35 -0
- package/lib/src/api/nfts.js +66 -0
- package/lib/src/api/nfts.js.map +1 -0
- package/lib/src/api/offers.d.ts +54 -0
- package/lib/src/api/offers.js +122 -0
- package/lib/src/api/offers.js.map +1 -0
- package/lib/src/api/orders.d.ts +50 -0
- package/lib/src/api/orders.js +151 -0
- package/lib/src/api/orders.js.map +1 -0
- package/lib/src/api/search.d.ts +13 -0
- package/lib/src/api/search.js +21 -0
- package/lib/src/api/search.js.map +1 -0
- package/lib/src/api/tokens.d.ts +25 -0
- package/lib/src/api/tokens.js +42 -0
- package/lib/src/api/tokens.js.map +1 -0
- package/lib/src/api/types.d.ts +840 -0
- package/lib/src/api/types.js +65 -0
- package/lib/src/api/types.js.map +1 -0
- package/lib/src/constants.d.ts +22 -0
- package/lib/src/constants.js +52 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/index.d.ts +18 -0
- package/lib/src/index.js +24 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/orders/privateListings.d.ts +12 -0
- package/lib/src/orders/privateListings.js +130 -0
- package/lib/src/orders/privateListings.js.map +1 -0
- package/lib/src/orders/types.d.ts +160 -0
- package/lib/src/orders/types.js +10 -0
- package/lib/src/orders/types.js.map +1 -0
- package/lib/src/orders/utils.d.ts +89 -0
- package/lib/src/orders/utils.js +177 -0
- package/lib/src/orders/utils.js.map +1 -0
- package/lib/src/sdk/assets.d.ts +104 -0
- package/lib/src/sdk/assets.js +397 -0
- package/lib/src/sdk/assets.js.map +1 -0
- package/lib/src/sdk/cancellation.d.ts +97 -0
- package/lib/src/sdk/cancellation.js +234 -0
- package/lib/src/sdk/cancellation.js.map +1 -0
- package/lib/src/sdk/context.d.ts +28 -0
- package/lib/src/sdk/context.js +3 -0
- package/lib/src/sdk/context.js.map +1 -0
- package/lib/src/sdk/fulfillment.d.ts +153 -0
- package/lib/src/sdk/fulfillment.js +296 -0
- package/lib/src/sdk/fulfillment.js.map +1 -0
- package/lib/src/sdk/orders.d.ts +253 -0
- package/lib/src/sdk/orders.js +677 -0
- package/lib/src/sdk/orders.js.map +1 -0
- package/lib/src/sdk/tokens.d.ts +31 -0
- package/lib/src/sdk/tokens.js +64 -0
- package/lib/src/sdk/tokens.js.map +1 -0
- package/lib/src/sdk.d.ts +560 -0
- package/lib/src/sdk.js +675 -0
- package/lib/src/sdk.js.map +1 -0
- package/lib/src/typechain/contracts/ERC1155.d.ts +236 -0
- package/lib/src/typechain/contracts/ERC1155.js +3 -0
- package/lib/src/typechain/contracts/ERC1155.js.map +1 -0
- package/lib/src/typechain/contracts/ERC20.d.ts +141 -0
- package/lib/src/typechain/contracts/ERC20.js +3 -0
- package/lib/src/typechain/contracts/ERC20.js.map +1 -0
- package/lib/src/typechain/contracts/ERC721.d.ts +213 -0
- package/lib/src/typechain/contracts/ERC721.js +3 -0
- package/lib/src/typechain/contracts/ERC721.js.map +1 -0
- package/lib/src/typechain/contracts/Multicall3.d.ts +57 -0
- package/lib/src/typechain/contracts/Multicall3.js +3 -0
- package/lib/src/typechain/contracts/Multicall3.js.map +1 -0
- package/lib/src/typechain/contracts/TransferHelper.d.ts +55 -0
- package/lib/src/typechain/contracts/TransferHelper.js +3 -0
- package/lib/src/typechain/contracts/TransferHelper.js.map +1 -0
- package/lib/src/typechain/contracts/common.d.ts +50 -0
- package/lib/src/typechain/contracts/common.js +3 -0
- package/lib/src/typechain/contracts/common.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js +332 -0
- package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.js +240 -0
- package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.js +351 -0
- package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js +68 -0
- package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +71 -0
- package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
- package/lib/src/typechain/contracts/factories/index.d.ts +5 -0
- package/lib/src/typechain/contracts/factories/index.js +17 -0
- package/lib/src/typechain/contracts/factories/index.js.map +1 -0
- package/lib/src/typechain/contracts/index.d.ts +11 -0
- package/lib/src/typechain/contracts/index.js +48 -0
- package/lib/src/typechain/contracts/index.js.map +1 -0
- package/lib/src/types.d.ts +387 -0
- package/lib/src/types.js +127 -0
- package/lib/src/types.js.map +1 -0
- package/lib/src/utils/chain.d.ts +60 -0
- package/lib/src/utils/chain.js +248 -0
- package/lib/src/utils/chain.js.map +1 -0
- package/lib/src/utils/converters.d.ts +37 -0
- package/lib/src/utils/converters.js +137 -0
- package/lib/src/utils/converters.js.map +1 -0
- package/lib/src/utils/dateHelper.d.ts +38 -0
- package/lib/src/utils/dateHelper.js +52 -0
- package/lib/src/utils/dateHelper.js.map +1 -0
- package/lib/src/utils/fees.d.ts +13 -0
- package/lib/src/utils/fees.js +29 -0
- package/lib/src/utils/fees.js.map +1 -0
- package/lib/src/utils/index.d.ts +2 -0
- package/lib/src/utils/index.js +19 -0
- package/lib/src/utils/index.js.map +1 -0
- package/lib/src/utils/protocol.d.ts +75 -0
- package/lib/src/utils/protocol.js +161 -0
- package/lib/src/utils/protocol.js.map +1 -0
- package/lib/src/utils/rateLimit.d.ts +34 -0
- package/lib/src/utils/rateLimit.js +97 -0
- package/lib/src/utils/rateLimit.js.map +1 -0
- package/lib/src/utils/stringHelper.d.ts +18 -0
- package/lib/src/utils/stringHelper.js +24 -0
- package/lib/src/utils/stringHelper.js.map +1 -0
- package/lib/src/utils/utils.d.ts +18 -0
- package/lib/src/utils/utils.js +45 -0
- package/lib/src/utils/utils.js.map +1 -0
- package/lib/typechain/contracts/ERC1155.d.ts +236 -0
- package/lib/typechain/contracts/ERC1155.js +3 -0
- package/lib/typechain/contracts/ERC1155.js.map +1 -0
- package/lib/typechain/contracts/ERC20.d.ts +141 -0
- package/lib/typechain/contracts/ERC20.js +3 -0
- package/lib/typechain/contracts/ERC20.js.map +1 -0
- package/lib/typechain/contracts/ERC721.d.ts +213 -0
- package/lib/typechain/contracts/ERC721.js +3 -0
- package/lib/typechain/contracts/ERC721.js.map +1 -0
- package/lib/typechain/contracts/Multicall3.d.ts +57 -0
- package/lib/typechain/contracts/Multicall3.js +3 -0
- package/lib/typechain/contracts/Multicall3.js.map +1 -0
- package/lib/typechain/contracts/TransferHelper.d.ts +55 -0
- package/lib/typechain/contracts/TransferHelper.js +3 -0
- package/lib/typechain/contracts/TransferHelper.js.map +1 -0
- package/lib/typechain/contracts/common.d.ts +50 -0
- package/lib/typechain/contracts/common.js +3 -0
- package/lib/typechain/contracts/common.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.js +332 -0
- package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
- package/lib/typechain/contracts/factories/ERC20__factory.js +240 -0
- package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
- package/lib/typechain/contracts/factories/ERC721__factory.js +351 -0
- package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.js +68 -0
- package/lib/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.js +71 -0
- package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
- package/lib/typechain/contracts/factories/index.d.ts +5 -0
- package/lib/typechain/contracts/factories/index.js +17 -0
- package/lib/typechain/contracts/factories/index.js.map +1 -0
- package/lib/typechain/contracts/index.d.ts +11 -0
- package/lib/typechain/contracts/index.js +48 -0
- package/lib/typechain/contracts/index.js.map +1 -0
- package/lib/types.d.ts +389 -0
- package/lib/types.js +129 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/chain.d.ts +64 -0
- package/lib/utils/chain.js +211 -0
- package/lib/utils/chain.js.map +1 -0
- package/lib/utils/chainIds.generated.d.ts +7 -0
- package/lib/utils/chainIds.generated.js +37 -0
- package/lib/utils/chainIds.generated.js.map +1 -0
- package/lib/utils/converters.d.ts +37 -0
- package/lib/utils/converters.js +137 -0
- package/lib/utils/converters.js.map +1 -0
- package/lib/utils/dateHelper.d.ts +38 -0
- package/lib/utils/dateHelper.js +52 -0
- package/lib/utils/dateHelper.js.map +1 -0
- package/lib/utils/fees.d.ts +13 -0
- package/lib/utils/fees.js +29 -0
- package/lib/utils/fees.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +19 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/protocol.d.ts +75 -0
- package/lib/utils/protocol.js +161 -0
- package/lib/utils/protocol.js.map +1 -0
- package/lib/utils/rateLimit.d.ts +34 -0
- package/lib/utils/rateLimit.js +97 -0
- package/lib/utils/rateLimit.js.map +1 -0
- package/lib/utils/stringHelper.d.ts +18 -0
- package/lib/utils/stringHelper.js +24 -0
- package/lib/utils/stringHelper.js.map +1 -0
- package/lib/utils/utils.d.ts +18 -0
- package/lib/utils/utils.js +45 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +72 -0
- package/src/abi/ERC1155.json +314 -0
- package/src/abi/ERC20.json +222 -0
- package/src/abi/ERC721.json +333 -0
- package/src/abi/Multicall3.json +50 -0
- package/src/abi/TransferHelper.json +53 -0
- package/src/api/accounts.ts +69 -0
- package/src/api/api.ts +1152 -0
- package/src/api/apiPaths.ts +208 -0
- package/src/api/chains.ts +18 -0
- package/src/api/collections.ts +120 -0
- package/src/api/drops.ts +49 -0
- package/src/api/events.ts +71 -0
- package/src/api/fetcher.ts +31 -0
- package/src/api/index.ts +2 -0
- package/src/api/listings.ts +126 -0
- package/src/api/nfts.ts +144 -0
- package/src/api/offers.ts +242 -0
- package/src/api/orders.ts +283 -0
- package/src/api/search.ts +21 -0
- package/src/api/tokens.ts +67 -0
- package/src/api/types.ts +1210 -0
- package/src/constants.ts +90 -0
- package/src/index.ts +22 -0
- package/src/orders/privateListings.ts +173 -0
- package/src/orders/types.ts +191 -0
- package/src/orders/utils.ts +253 -0
- package/src/sdk/assets.ts +591 -0
- package/src/sdk/cancellation.ts +346 -0
- package/src/sdk/context.ts +33 -0
- package/src/sdk/fulfillment.ts +478 -0
- package/src/sdk/orders.ts +1149 -0
- package/src/sdk/tokens.ts +95 -0
- package/src/sdk.ts +1051 -0
- package/src/typechain/contracts/ERC1155.ts +440 -0
- package/src/typechain/contracts/ERC20.ts +286 -0
- package/src/typechain/contracts/ERC721.ts +412 -0
- package/src/typechain/contracts/Multicall3.ts +117 -0
- package/src/typechain/contracts/TransferHelper.ts +122 -0
- package/src/typechain/contracts/common.ts +131 -0
- package/src/typechain/contracts/factories/ERC1155__factory.ts +331 -0
- package/src/typechain/contracts/factories/ERC20__factory.ts +239 -0
- package/src/typechain/contracts/factories/ERC721__factory.ts +350 -0
- package/src/typechain/contracts/factories/Multicall3__factory.ts +67 -0
- package/src/typechain/contracts/factories/TransferHelper__factory.ts +76 -0
- package/src/typechain/contracts/factories/index.ts +8 -0
- package/src/typechain/contracts/index.ts +14 -0
- package/src/types.ts +413 -0
- package/src/utils/chain.ts +224 -0
- package/src/utils/chainIds.generated.ts +34 -0
- package/src/utils/converters.ts +145 -0
- package/src/utils/dateHelper.ts +48 -0
- package/src/utils/fees.ts +31 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/protocol.ts +185 -0
- package/src/utils/rateLimit.ts +147 -0
- package/src/utils/stringHelper.ts +25 -0
- package/src/utils/utils.ts +36 -0
package/src/api/api.ts
ADDED
|
@@ -0,0 +1,1152 @@
|
|
|
1
|
+
import { ethers } from "ethers"
|
|
2
|
+
import { API_BASE_MAINNET } from "../constants"
|
|
3
|
+
import type {
|
|
4
|
+
FulfillmentDataResponse,
|
|
5
|
+
OrderAPIOptions,
|
|
6
|
+
OrdersQueryOptions,
|
|
7
|
+
OrderV2,
|
|
8
|
+
ProtocolData,
|
|
9
|
+
} from "../orders/types"
|
|
10
|
+
import {
|
|
11
|
+
Chain,
|
|
12
|
+
type OpenSeaAccount,
|
|
13
|
+
type OpenSeaAPIConfig,
|
|
14
|
+
type OpenSeaCollection,
|
|
15
|
+
type OpenSeaCollectionStats,
|
|
16
|
+
type OpenSeaPaymentToken,
|
|
17
|
+
type OpenSeaRateLimitError,
|
|
18
|
+
type OrderSide,
|
|
19
|
+
type RequestOptions,
|
|
20
|
+
} from "../types"
|
|
21
|
+
import { executeWithRateLimit } from "../utils/rateLimit"
|
|
22
|
+
import { AccountsAPI } from "./accounts"
|
|
23
|
+
import { ChainsAPI } from "./chains"
|
|
24
|
+
import { CollectionsAPI } from "./collections"
|
|
25
|
+
import { DropsAPI } from "./drops"
|
|
26
|
+
import { EventsAPI } from "./events"
|
|
27
|
+
import { ListingsAPI } from "./listings"
|
|
28
|
+
import { NFTsAPI } from "./nfts"
|
|
29
|
+
import { OffersAPI } from "./offers"
|
|
30
|
+
import { OrdersAPI } from "./orders"
|
|
31
|
+
import { SearchAPI } from "./search"
|
|
32
|
+
import { TokensAPI } from "./tokens"
|
|
33
|
+
import {
|
|
34
|
+
type BuildOfferResponse,
|
|
35
|
+
type CancelOrderResponse,
|
|
36
|
+
type CollectionOffer,
|
|
37
|
+
CollectionOrderByOption,
|
|
38
|
+
type DropMintRequest,
|
|
39
|
+
type DropMintResponse,
|
|
40
|
+
type GetAccountTokensArgs,
|
|
41
|
+
type GetAccountTokensResponse,
|
|
42
|
+
type GetBestListingResponse,
|
|
43
|
+
type GetBestOfferResponse,
|
|
44
|
+
type GetChainsResponse,
|
|
45
|
+
type GetCollectionsPaginatedResponse,
|
|
46
|
+
type GetCollectionsResponse,
|
|
47
|
+
type GetContractResponse,
|
|
48
|
+
type GetDropResponse,
|
|
49
|
+
type GetDropsArgs,
|
|
50
|
+
type GetDropsResponse,
|
|
51
|
+
type GetEventsArgs,
|
|
52
|
+
type GetEventsResponse,
|
|
53
|
+
type GetListingsResponse,
|
|
54
|
+
type GetNFTResponse,
|
|
55
|
+
type GetOffersResponse,
|
|
56
|
+
type GetOrderByHashResponse,
|
|
57
|
+
type GetOrdersResponse,
|
|
58
|
+
type GetSwapQuoteArgs,
|
|
59
|
+
type GetSwapQuoteResponse,
|
|
60
|
+
type GetTokenResponse,
|
|
61
|
+
type GetTokensArgs,
|
|
62
|
+
type GetTopCollectionsArgs,
|
|
63
|
+
type GetTopTokensResponse,
|
|
64
|
+
type GetTraitsResponse,
|
|
65
|
+
type GetTrendingCollectionsArgs,
|
|
66
|
+
type GetTrendingTokensResponse,
|
|
67
|
+
type Listing,
|
|
68
|
+
type ListNFTsResponse,
|
|
69
|
+
type Offer,
|
|
70
|
+
type ResolveAccountResponse,
|
|
71
|
+
type SearchArgs,
|
|
72
|
+
type SearchResponse,
|
|
73
|
+
type ValidateMetadataResponse,
|
|
74
|
+
} from "./types"
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The API class for the OpenSea SDK.
|
|
78
|
+
* @category Main Classes
|
|
79
|
+
*/
|
|
80
|
+
export class OpenSeaAPI {
|
|
81
|
+
/**
|
|
82
|
+
* Base url for the API
|
|
83
|
+
*/
|
|
84
|
+
public readonly apiBaseUrl: string
|
|
85
|
+
/**
|
|
86
|
+
* Default size to use for fetching orders
|
|
87
|
+
*/
|
|
88
|
+
public pageSize = 20
|
|
89
|
+
/**
|
|
90
|
+
* Logger function to use when debugging
|
|
91
|
+
*/
|
|
92
|
+
public logger: (arg: string) => void
|
|
93
|
+
|
|
94
|
+
private apiKey: string | undefined
|
|
95
|
+
private chain: Chain
|
|
96
|
+
|
|
97
|
+
// Specialized API clients
|
|
98
|
+
private ordersAPI: OrdersAPI
|
|
99
|
+
private offersAPI: OffersAPI
|
|
100
|
+
private listingsAPI: ListingsAPI
|
|
101
|
+
private collectionsAPI: CollectionsAPI
|
|
102
|
+
private nftsAPI: NFTsAPI
|
|
103
|
+
private accountsAPI: AccountsAPI
|
|
104
|
+
private eventsAPI: EventsAPI
|
|
105
|
+
private searchAPI: SearchAPI
|
|
106
|
+
private tokensAPI: TokensAPI
|
|
107
|
+
private chainsAPI: ChainsAPI
|
|
108
|
+
private dropsAPI: DropsAPI
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Create an instance of the OpenSeaAPI
|
|
112
|
+
* @param config OpenSeaAPIConfig for setting up the API, including an optional API key, Chain name, and base URL
|
|
113
|
+
* @param logger Optional function for logging debug strings before and after requests are made. Defaults to no logging
|
|
114
|
+
*/
|
|
115
|
+
constructor(config: OpenSeaAPIConfig, logger?: (arg: string) => void) {
|
|
116
|
+
this.apiKey = config.apiKey
|
|
117
|
+
this.chain = config.chain ?? Chain.Mainnet
|
|
118
|
+
|
|
119
|
+
if (config.apiBaseUrl) {
|
|
120
|
+
this.apiBaseUrl = config.apiBaseUrl
|
|
121
|
+
} else {
|
|
122
|
+
this.apiBaseUrl = API_BASE_MAINNET
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Debugging: default to nothing
|
|
126
|
+
this.logger = logger ?? ((arg: string) => arg)
|
|
127
|
+
|
|
128
|
+
// Create fetcher context
|
|
129
|
+
const fetcher = {
|
|
130
|
+
get: this.get.bind(this),
|
|
131
|
+
post: this.post.bind(this),
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Initialize specialized API clients
|
|
135
|
+
this.ordersAPI = new OrdersAPI(fetcher, this.chain)
|
|
136
|
+
this.offersAPI = new OffersAPI(fetcher, this.chain)
|
|
137
|
+
this.listingsAPI = new ListingsAPI(fetcher, this.chain)
|
|
138
|
+
this.collectionsAPI = new CollectionsAPI(fetcher)
|
|
139
|
+
this.nftsAPI = new NFTsAPI(fetcher, this.chain)
|
|
140
|
+
this.accountsAPI = new AccountsAPI(fetcher, this.chain)
|
|
141
|
+
this.eventsAPI = new EventsAPI(fetcher)
|
|
142
|
+
this.searchAPI = new SearchAPI(fetcher)
|
|
143
|
+
this.tokensAPI = new TokensAPI(fetcher)
|
|
144
|
+
this.chainsAPI = new ChainsAPI(fetcher)
|
|
145
|
+
this.dropsAPI = new DropsAPI(fetcher)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Gets an order from API based on query options.
|
|
150
|
+
* @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
|
|
151
|
+
* @param options Query options for fetching an order
|
|
152
|
+
* @returns The first {@link OrderV2} returned by the API
|
|
153
|
+
*
|
|
154
|
+
* @throws An error if there are no matching orders.
|
|
155
|
+
*/
|
|
156
|
+
public async getOrder(
|
|
157
|
+
options: Omit<OrdersQueryOptions, "limit">,
|
|
158
|
+
): Promise<OrderV2> {
|
|
159
|
+
return this.ordersAPI.getOrder(options)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Gets a single order by its order hash.
|
|
164
|
+
* @param orderHash The hash of the order to fetch
|
|
165
|
+
* @param protocolAddress The address of the seaport contract
|
|
166
|
+
* @param chain The chain where the order is located. Defaults to the chain set in the constructor.
|
|
167
|
+
* @returns The {@link GetOrderByHashResponse} returned by the API (can be Offer or Listing)
|
|
168
|
+
* @throws An error if the order is not found
|
|
169
|
+
*/
|
|
170
|
+
public async getOrderByHash(
|
|
171
|
+
orderHash: string,
|
|
172
|
+
protocolAddress: string,
|
|
173
|
+
chain: Chain = this.chain,
|
|
174
|
+
): Promise<GetOrderByHashResponse> {
|
|
175
|
+
return this.ordersAPI.getOrderByHash(orderHash, protocolAddress, chain)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Gets a list of orders from API based on query options.
|
|
180
|
+
* @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
|
|
181
|
+
* @param options Query options for fetching orders
|
|
182
|
+
* @returns The {@link GetOrdersResponse} returned by the API.
|
|
183
|
+
*/
|
|
184
|
+
public async getOrders(
|
|
185
|
+
options: Omit<OrdersQueryOptions, "limit">,
|
|
186
|
+
): Promise<GetOrdersResponse> {
|
|
187
|
+
return this.ordersAPI.getOrders({ ...options, pageSize: this.pageSize })
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Gets all offers for a given collection.
|
|
192
|
+
* @param collectionSlug The slug of the collection.
|
|
193
|
+
* @param limit The number of offers to return. Must be between 1 and 100. Default: 100
|
|
194
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
195
|
+
* @returns The {@link GetOffersResponse} returned by the API.
|
|
196
|
+
*/
|
|
197
|
+
public async getAllOffers(
|
|
198
|
+
collectionSlug: string,
|
|
199
|
+
limit?: number,
|
|
200
|
+
next?: string,
|
|
201
|
+
): Promise<GetOffersResponse> {
|
|
202
|
+
return this.offersAPI.getAllOffers(collectionSlug, limit, next)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Gets all listings for a given collection.
|
|
207
|
+
* @param collectionSlug The slug of the collection.
|
|
208
|
+
* @param limit The number of listings to return. Must be between 1 and 100. Default: 100
|
|
209
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
210
|
+
* @param includePrivateListings Whether to include private listings (default: false)
|
|
211
|
+
* @returns The {@link GetListingsResponse} returned by the API.
|
|
212
|
+
*/
|
|
213
|
+
public async getAllListings(
|
|
214
|
+
collectionSlug: string,
|
|
215
|
+
limit?: number,
|
|
216
|
+
next?: string,
|
|
217
|
+
includePrivateListings?: boolean,
|
|
218
|
+
): Promise<GetListingsResponse> {
|
|
219
|
+
return this.listingsAPI.getAllListings(
|
|
220
|
+
collectionSlug,
|
|
221
|
+
limit,
|
|
222
|
+
next,
|
|
223
|
+
includePrivateListings,
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Gets trait offers for a given collection.
|
|
229
|
+
* @param collectionSlug The slug of the collection.
|
|
230
|
+
* @param type The name of the trait (e.g. 'Background').
|
|
231
|
+
* @param value The value of the trait (e.g. 'Red').
|
|
232
|
+
* @param limit The number of offers to return. Must be between 1 and 100. Default: 100
|
|
233
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
234
|
+
* @param floatValue The value of the trait for decimal-based numeric traits.
|
|
235
|
+
* @param intValue The value of the trait for integer-based numeric traits.
|
|
236
|
+
* @returns The {@link GetOffersResponse} returned by the API.
|
|
237
|
+
*/
|
|
238
|
+
public async getTraitOffers(
|
|
239
|
+
collectionSlug: string,
|
|
240
|
+
type: string,
|
|
241
|
+
value: string,
|
|
242
|
+
limit?: number,
|
|
243
|
+
next?: string,
|
|
244
|
+
floatValue?: number,
|
|
245
|
+
intValue?: number,
|
|
246
|
+
): Promise<GetOffersResponse> {
|
|
247
|
+
return this.offersAPI.getTraitOffers(
|
|
248
|
+
collectionSlug,
|
|
249
|
+
type,
|
|
250
|
+
value,
|
|
251
|
+
limit,
|
|
252
|
+
next,
|
|
253
|
+
floatValue,
|
|
254
|
+
intValue,
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Gets the best offer for a given token.
|
|
260
|
+
* @param collectionSlug The slug of the collection.
|
|
261
|
+
* @param tokenId The token identifier.
|
|
262
|
+
* @returns The {@link GetBestOfferResponse} returned by the API.
|
|
263
|
+
*/
|
|
264
|
+
public async getBestOffer(
|
|
265
|
+
collectionSlug: string,
|
|
266
|
+
tokenId: string | number,
|
|
267
|
+
): Promise<GetBestOfferResponse> {
|
|
268
|
+
return this.offersAPI.getBestOffer(collectionSlug, tokenId)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Gets the best listing for a given token.
|
|
273
|
+
* @param collectionSlug The slug of the collection.
|
|
274
|
+
* @param tokenId The token identifier.
|
|
275
|
+
* @param includePrivateListings Whether to include private listings (default: false)
|
|
276
|
+
* @returns The {@link GetBestListingResponse} returned by the API.
|
|
277
|
+
*/
|
|
278
|
+
public async getBestListing(
|
|
279
|
+
collectionSlug: string,
|
|
280
|
+
tokenId: string | number,
|
|
281
|
+
includePrivateListings?: boolean,
|
|
282
|
+
): Promise<GetBestListingResponse> {
|
|
283
|
+
return this.listingsAPI.getBestListing(
|
|
284
|
+
collectionSlug,
|
|
285
|
+
tokenId,
|
|
286
|
+
includePrivateListings,
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Gets the best listings for a given collection.
|
|
292
|
+
* @param collectionSlug The slug of the collection.
|
|
293
|
+
* @param limit The number of listings to return. Must be between 1 and 100. Default: 100
|
|
294
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
295
|
+
* @param includePrivateListings Whether to include private listings (default: false)
|
|
296
|
+
* @returns The {@link GetListingsResponse} returned by the API.
|
|
297
|
+
*/
|
|
298
|
+
public async getBestListings(
|
|
299
|
+
collectionSlug: string,
|
|
300
|
+
limit?: number,
|
|
301
|
+
next?: string,
|
|
302
|
+
includePrivateListings?: boolean,
|
|
303
|
+
): Promise<GetListingsResponse> {
|
|
304
|
+
return this.listingsAPI.getBestListings(
|
|
305
|
+
collectionSlug,
|
|
306
|
+
limit,
|
|
307
|
+
next,
|
|
308
|
+
includePrivateListings,
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Generate the data needed to fulfill a listing or an offer onchain.
|
|
314
|
+
* @param fulfillerAddress The wallet address which will be used to fulfill the order
|
|
315
|
+
* @param orderHash The hash of the order to fulfill
|
|
316
|
+
* @param protocolAddress The address of the seaport contract
|
|
317
|
+
* @param side The side of the order (buy or sell)
|
|
318
|
+
* @param assetContractAddress Optional address of the NFT contract for criteria offers (e.g., collection offers)
|
|
319
|
+
* @param tokenId Optional token ID for criteria offers (e.g., collection offers)
|
|
320
|
+
* @param unitsToFill Optional number of units to fill. Defaults to 1 for both listings and offers.
|
|
321
|
+
* @param recipientAddress Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.
|
|
322
|
+
* @param includeOptionalCreatorFees Whether to include optional creator fees in the fulfillment. If creator fees are already required, this is a no-op. Defaults to false.
|
|
323
|
+
* @returns The {@link FulfillmentDataResponse}
|
|
324
|
+
*/
|
|
325
|
+
public async generateFulfillmentData(
|
|
326
|
+
fulfillerAddress: string,
|
|
327
|
+
orderHash: string,
|
|
328
|
+
protocolAddress: string,
|
|
329
|
+
side: OrderSide,
|
|
330
|
+
assetContractAddress?: string,
|
|
331
|
+
tokenId?: string,
|
|
332
|
+
unitsToFill?: string,
|
|
333
|
+
recipientAddress?: string,
|
|
334
|
+
includeOptionalCreatorFees: boolean = false,
|
|
335
|
+
): Promise<FulfillmentDataResponse> {
|
|
336
|
+
return this.ordersAPI.generateFulfillmentData(
|
|
337
|
+
fulfillerAddress,
|
|
338
|
+
orderHash,
|
|
339
|
+
protocolAddress,
|
|
340
|
+
side,
|
|
341
|
+
assetContractAddress,
|
|
342
|
+
tokenId,
|
|
343
|
+
unitsToFill,
|
|
344
|
+
recipientAddress,
|
|
345
|
+
includeOptionalCreatorFees,
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Post an order to OpenSea.
|
|
351
|
+
* @deprecated Use postListing or postOffer instead.
|
|
352
|
+
* @param order The order to post
|
|
353
|
+
* @param apiOptions API options for the order
|
|
354
|
+
* @returns The {@link OrderV2} posted to the API.
|
|
355
|
+
*/
|
|
356
|
+
public async postOrder(
|
|
357
|
+
order: ProtocolData,
|
|
358
|
+
apiOptions: OrderAPIOptions,
|
|
359
|
+
): Promise<OrderV2> {
|
|
360
|
+
return this.ordersAPI.postOrder(order, apiOptions)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Post a listing to OpenSea. Returns the new v2 Listing response format.
|
|
365
|
+
* @param order The order to post
|
|
366
|
+
* @param protocolAddress The contract address of the seaport protocol
|
|
367
|
+
* @returns The {@link Listing} posted to the API.
|
|
368
|
+
*/
|
|
369
|
+
public async postListing(
|
|
370
|
+
order: ProtocolData,
|
|
371
|
+
protocolAddress: string,
|
|
372
|
+
): Promise<Listing> {
|
|
373
|
+
return this.ordersAPI.postListing(order, protocolAddress)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Post an offer to OpenSea. Returns the new v2 Offer response format.
|
|
378
|
+
* @param order The order to post
|
|
379
|
+
* @param protocolAddress The contract address of the seaport protocol
|
|
380
|
+
* @returns The {@link Offer} posted to the API.
|
|
381
|
+
*/
|
|
382
|
+
public async postOffer(
|
|
383
|
+
order: ProtocolData,
|
|
384
|
+
protocolAddress: string,
|
|
385
|
+
): Promise<Offer> {
|
|
386
|
+
return this.ordersAPI.postOffer(order, protocolAddress)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Build a OpenSea collection offer.
|
|
391
|
+
* @param offererAddress The wallet address which is creating the offer.
|
|
392
|
+
* @param quantity The number of NFTs requested in the offer.
|
|
393
|
+
* @param collectionSlug The slug (identifier) of the collection to build the offer for.
|
|
394
|
+
* @param offerProtectionEnabled Build the offer on OpenSea's signed zone to provide offer protections from receiving an item which is disabled from trading.
|
|
395
|
+
* @param traitType If defined, the trait name to create the collection offer for.
|
|
396
|
+
* @param traitValue If defined, the trait value to create the collection offer for.
|
|
397
|
+
* @param traits If defined, an array of traits to create the multi-trait collection offer for.
|
|
398
|
+
* @param numericTraits If defined, an array of numeric trait criteria with min/max ranges.
|
|
399
|
+
* @returns The {@link BuildOfferResponse} returned by the API.
|
|
400
|
+
*/
|
|
401
|
+
public async buildOffer(
|
|
402
|
+
offererAddress: string,
|
|
403
|
+
quantity: number,
|
|
404
|
+
collectionSlug: string,
|
|
405
|
+
offerProtectionEnabled = true,
|
|
406
|
+
traitType?: string,
|
|
407
|
+
traitValue?: string,
|
|
408
|
+
traits?: Array<{ type: string; value: string }>,
|
|
409
|
+
numericTraits?: Array<{ type: string; min?: number; max?: number }>,
|
|
410
|
+
): Promise<BuildOfferResponse> {
|
|
411
|
+
return this.offersAPI.buildOffer(
|
|
412
|
+
offererAddress,
|
|
413
|
+
quantity,
|
|
414
|
+
collectionSlug,
|
|
415
|
+
offerProtectionEnabled,
|
|
416
|
+
traitType,
|
|
417
|
+
traitValue,
|
|
418
|
+
traits,
|
|
419
|
+
numericTraits,
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Get a list collection offers for a given slug.
|
|
425
|
+
* @param slug The slug (identifier) of the collection to list offers for
|
|
426
|
+
* @param limit Optional limit for number of results.
|
|
427
|
+
* @param next Optional cursor for pagination.
|
|
428
|
+
* @returns The {@link GetOffersResponse} returned by the API.
|
|
429
|
+
*/
|
|
430
|
+
public async getCollectionOffers(
|
|
431
|
+
slug: string,
|
|
432
|
+
limit?: number,
|
|
433
|
+
next?: string,
|
|
434
|
+
): Promise<GetOffersResponse> {
|
|
435
|
+
return this.offersAPI.getCollectionOffers(slug, limit, next)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Post a collection offer to OpenSea.
|
|
440
|
+
* @param order The collection offer to post.
|
|
441
|
+
* @param slug The slug (identifier) of the collection to post the offer for.
|
|
442
|
+
* @param traitType If defined, the trait name to create the collection offer for.
|
|
443
|
+
* @param traitValue If defined, the trait value to create the collection offer for.
|
|
444
|
+
* @param traits If defined, an array of traits to create the multi-trait collection offer for.
|
|
445
|
+
* @param numericTraits If defined, an array of numeric trait criteria with min/max ranges.
|
|
446
|
+
* @returns The {@link Offer} returned to the API.
|
|
447
|
+
*/
|
|
448
|
+
public async postCollectionOffer(
|
|
449
|
+
order: ProtocolData,
|
|
450
|
+
slug: string,
|
|
451
|
+
traitType?: string,
|
|
452
|
+
traitValue?: string,
|
|
453
|
+
traits?: Array<{ type: string; value: string }>,
|
|
454
|
+
numericTraits?: Array<{ type: string; min?: number; max?: number }>,
|
|
455
|
+
): Promise<CollectionOffer | null> {
|
|
456
|
+
return this.offersAPI.postCollectionOffer(
|
|
457
|
+
order,
|
|
458
|
+
slug,
|
|
459
|
+
traitType,
|
|
460
|
+
traitValue,
|
|
461
|
+
traits,
|
|
462
|
+
numericTraits,
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Fetch multiple NFTs for a collection.
|
|
468
|
+
* @param slug The slug (identifier) of the collection
|
|
469
|
+
* @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
|
|
470
|
+
* @param next Cursor to retrieve the next page of NFTs
|
|
471
|
+
* @returns The {@link ListNFTsResponse} returned by the API.
|
|
472
|
+
*/
|
|
473
|
+
public async getNFTsByCollection(
|
|
474
|
+
slug: string,
|
|
475
|
+
limit: number | undefined = undefined,
|
|
476
|
+
next: string | undefined = undefined,
|
|
477
|
+
): Promise<ListNFTsResponse> {
|
|
478
|
+
return this.nftsAPI.getNFTsByCollection(slug, limit, next)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Fetch multiple NFTs for a contract.
|
|
483
|
+
* @param address The NFT's contract address.
|
|
484
|
+
* @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
|
|
485
|
+
* @param next Cursor to retrieve the next page of NFTs.
|
|
486
|
+
* @param chain The NFT's chain.
|
|
487
|
+
* @returns The {@link ListNFTsResponse} returned by the API.
|
|
488
|
+
*/
|
|
489
|
+
public async getNFTsByContract(
|
|
490
|
+
address: string,
|
|
491
|
+
limit: number | undefined = undefined,
|
|
492
|
+
next: string | undefined = undefined,
|
|
493
|
+
chain: Chain = this.chain,
|
|
494
|
+
): Promise<ListNFTsResponse> {
|
|
495
|
+
return this.nftsAPI.getNFTsByContract(address, limit, next, chain)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Fetch NFTs owned by an account.
|
|
500
|
+
* @param address The address of the account
|
|
501
|
+
* @param limit The number of NFTs to retrieve. Must be greater than 0 and less than 51.
|
|
502
|
+
* @param next Cursor to retrieve the next page of NFTs
|
|
503
|
+
* @param chain The chain to query. Defaults to the chain set in the constructor.
|
|
504
|
+
* @returns The {@link ListNFTsResponse} returned by the API.
|
|
505
|
+
*/
|
|
506
|
+
public async getNFTsByAccount(
|
|
507
|
+
address: string,
|
|
508
|
+
limit: number | undefined = undefined,
|
|
509
|
+
next: string | undefined = undefined,
|
|
510
|
+
chain = this.chain,
|
|
511
|
+
): Promise<ListNFTsResponse> {
|
|
512
|
+
return this.nftsAPI.getNFTsByAccount(address, limit, next, chain)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Fetch metadata, traits, ownership information, and rarity for a single NFT.
|
|
517
|
+
* @param address The NFT's contract address.
|
|
518
|
+
* @param identifier the identifier of the NFT (i.e. Token ID)
|
|
519
|
+
* @param chain The NFT's chain.
|
|
520
|
+
* @returns The {@link GetNFTResponse} returned by the API.
|
|
521
|
+
*/
|
|
522
|
+
public async getNFT(
|
|
523
|
+
address: string,
|
|
524
|
+
identifier: string,
|
|
525
|
+
chain = this.chain,
|
|
526
|
+
): Promise<GetNFTResponse> {
|
|
527
|
+
return this.nftsAPI.getNFT(address, identifier, chain)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Fetch an OpenSea collection.
|
|
532
|
+
* @param slug The slug (identifier) of the collection.
|
|
533
|
+
* @returns The {@link OpenSeaCollection} returned by the API.
|
|
534
|
+
*/
|
|
535
|
+
public async getCollection(slug: string): Promise<OpenSeaCollection> {
|
|
536
|
+
return this.collectionsAPI.getCollection(slug)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Fetch a list of OpenSea collections.
|
|
541
|
+
* @param orderBy The order to return the collections in. Default: CREATED_DATE
|
|
542
|
+
* @param chain The chain to filter the collections on. Default: all chains
|
|
543
|
+
* @param creatorUsername The creator's OpenSea username to filter the collections on.
|
|
544
|
+
* @param includeHidden If hidden collections should be returned. Default: false
|
|
545
|
+
* @param limit The limit of collections to return.
|
|
546
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
547
|
+
* @returns List of {@link OpenSeaCollection} returned by the API.
|
|
548
|
+
*/
|
|
549
|
+
public async getCollections(
|
|
550
|
+
orderBy: CollectionOrderByOption = CollectionOrderByOption.CREATED_DATE,
|
|
551
|
+
chain?: Chain,
|
|
552
|
+
creatorUsername?: string,
|
|
553
|
+
includeHidden: boolean = false,
|
|
554
|
+
limit?: number,
|
|
555
|
+
next?: string,
|
|
556
|
+
): Promise<GetCollectionsResponse> {
|
|
557
|
+
return this.collectionsAPI.getCollections(
|
|
558
|
+
orderBy,
|
|
559
|
+
chain,
|
|
560
|
+
creatorUsername,
|
|
561
|
+
includeHidden,
|
|
562
|
+
limit,
|
|
563
|
+
next,
|
|
564
|
+
)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Fetch stats for an OpenSea collection.
|
|
569
|
+
* @param slug The slug (identifier) of the collection.
|
|
570
|
+
* @returns The {@link OpenSeaCollection} returned by the API.
|
|
571
|
+
*/
|
|
572
|
+
public async getCollectionStats(
|
|
573
|
+
slug: string,
|
|
574
|
+
): Promise<OpenSeaCollectionStats> {
|
|
575
|
+
return this.collectionsAPI.getCollectionStats(slug)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Fetch a payment token.
|
|
580
|
+
* @param address The address of the payment token
|
|
581
|
+
* @param chain The chain of the payment token
|
|
582
|
+
* @returns The {@link OpenSeaPaymentToken} returned by the API.
|
|
583
|
+
*/
|
|
584
|
+
public async getPaymentToken(
|
|
585
|
+
address: string,
|
|
586
|
+
chain = this.chain,
|
|
587
|
+
): Promise<OpenSeaPaymentToken> {
|
|
588
|
+
return this.accountsAPI.getPaymentToken(address, chain)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Fetch account for an address.
|
|
593
|
+
* @param address The address to fetch the account for
|
|
594
|
+
* @returns The {@link OpenSeaAccount} returned by the API.
|
|
595
|
+
*/
|
|
596
|
+
public async getAccount(address: string): Promise<OpenSeaAccount> {
|
|
597
|
+
return this.accountsAPI.getAccount(address)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Force refresh the metadata for an NFT.
|
|
602
|
+
* @param address The address of the NFT's contract.
|
|
603
|
+
* @param identifier The identifier of the NFT.
|
|
604
|
+
* @param chain The chain where the NFT is located.
|
|
605
|
+
* @returns The response from the API.
|
|
606
|
+
*/
|
|
607
|
+
public async refreshNFTMetadata(
|
|
608
|
+
address: string,
|
|
609
|
+
identifier: string,
|
|
610
|
+
chain: Chain = this.chain,
|
|
611
|
+
): Promise<Response> {
|
|
612
|
+
return this.nftsAPI.refreshNFTMetadata(address, identifier, chain)
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
617
|
+
* Protocol and Chain are required to prevent hash collisions.
|
|
618
|
+
* Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
|
|
619
|
+
* @param protocolAddress The Seaport address for the order.
|
|
620
|
+
* @param orderHash The order hash, or external identifier, of the order.
|
|
621
|
+
* @param chain The chain where the order is located.
|
|
622
|
+
* @param offererSignature An EIP-712 signature from the offerer of the order.
|
|
623
|
+
* If this is not provided, the user associated with the API Key will be checked instead.
|
|
624
|
+
* The signature must be a EIP-712 signature consisting of the order's Seaport contract's
|
|
625
|
+
* name, version, address, and chain. The struct to sign is `OrderHash` containing a
|
|
626
|
+
* single bytes32 field.
|
|
627
|
+
* @returns The response from the API.
|
|
628
|
+
*/
|
|
629
|
+
public async offchainCancelOrder(
|
|
630
|
+
protocolAddress: string,
|
|
631
|
+
orderHash: string,
|
|
632
|
+
chain: Chain = this.chain,
|
|
633
|
+
offererSignature?: string,
|
|
634
|
+
): Promise<CancelOrderResponse> {
|
|
635
|
+
return this.ordersAPI.offchainCancelOrder(
|
|
636
|
+
protocolAddress,
|
|
637
|
+
orderHash,
|
|
638
|
+
chain,
|
|
639
|
+
offererSignature,
|
|
640
|
+
)
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Gets a list of events based on query parameters.
|
|
645
|
+
* @param args Query parameters for filtering events.
|
|
646
|
+
* @returns The {@link GetEventsResponse} returned by the API.
|
|
647
|
+
*/
|
|
648
|
+
public async getEvents(args?: GetEventsArgs): Promise<GetEventsResponse> {
|
|
649
|
+
return this.eventsAPI.getEvents(args)
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Gets a list of events for a specific account.
|
|
654
|
+
* @param address The account address.
|
|
655
|
+
* @param args Query parameters for filtering events.
|
|
656
|
+
* @returns The {@link GetEventsResponse} returned by the API.
|
|
657
|
+
*/
|
|
658
|
+
public async getEventsByAccount(
|
|
659
|
+
address: string,
|
|
660
|
+
args?: GetEventsArgs,
|
|
661
|
+
): Promise<GetEventsResponse> {
|
|
662
|
+
return this.eventsAPI.getEventsByAccount(address, args)
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Gets a list of events for a specific collection.
|
|
667
|
+
* @param collectionSlug The slug (identifier) of the collection.
|
|
668
|
+
* @param args Query parameters for filtering events.
|
|
669
|
+
* @returns The {@link GetEventsResponse} returned by the API.
|
|
670
|
+
*/
|
|
671
|
+
public async getEventsByCollection(
|
|
672
|
+
collectionSlug: string,
|
|
673
|
+
args?: GetEventsArgs,
|
|
674
|
+
): Promise<GetEventsResponse> {
|
|
675
|
+
return this.eventsAPI.getEventsByCollection(collectionSlug, args)
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Gets a list of events for a specific NFT.
|
|
680
|
+
* @param chain The chain where the NFT is located.
|
|
681
|
+
* @param address The contract address of the NFT.
|
|
682
|
+
* @param identifier The token identifier.
|
|
683
|
+
* @param args Query parameters for filtering events.
|
|
684
|
+
* @returns The {@link GetEventsResponse} returned by the API.
|
|
685
|
+
*/
|
|
686
|
+
public async getEventsByNFT(
|
|
687
|
+
chain: Chain,
|
|
688
|
+
address: string,
|
|
689
|
+
identifier: string,
|
|
690
|
+
args?: GetEventsArgs,
|
|
691
|
+
): Promise<GetEventsResponse> {
|
|
692
|
+
return this.eventsAPI.getEventsByNFT(chain, address, identifier, args)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Fetch smart contract information for a given chain and address.
|
|
697
|
+
* @param address The contract address.
|
|
698
|
+
* @param chain The chain where the contract is deployed. Defaults to the chain set in the constructor.
|
|
699
|
+
* @returns The {@link GetContractResponse} returned by the API.
|
|
700
|
+
*/
|
|
701
|
+
public async getContract(
|
|
702
|
+
address: string,
|
|
703
|
+
chain: Chain = this.chain,
|
|
704
|
+
): Promise<GetContractResponse> {
|
|
705
|
+
return this.nftsAPI.getContract(address, chain)
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Fetch all traits for a collection with their possible values and counts.
|
|
710
|
+
* @param collectionSlug The slug (identifier) of the collection.
|
|
711
|
+
* @returns The {@link GetTraitsResponse} returned by the API.
|
|
712
|
+
*/
|
|
713
|
+
public async getTraits(collectionSlug: string): Promise<GetTraitsResponse> {
|
|
714
|
+
return this.collectionsAPI.getTraits(collectionSlug)
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Gets a list of trending tokens.
|
|
719
|
+
* @param args Optional query parameters for pagination.
|
|
720
|
+
* @returns The {@link GetTrendingTokensResponse} returned by the API.
|
|
721
|
+
*/
|
|
722
|
+
public async getTrendingTokens(
|
|
723
|
+
args?: GetTokensArgs,
|
|
724
|
+
): Promise<GetTrendingTokensResponse> {
|
|
725
|
+
return this.tokensAPI.getTrendingTokens(args)
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Gets a list of top tokens.
|
|
730
|
+
* @param args Optional query parameters for pagination.
|
|
731
|
+
* @returns The {@link GetTopTokensResponse} returned by the API.
|
|
732
|
+
*/
|
|
733
|
+
public async getTopTokens(
|
|
734
|
+
args?: GetTokensArgs,
|
|
735
|
+
): Promise<GetTopTokensResponse> {
|
|
736
|
+
return this.tokensAPI.getTopTokens(args)
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Gets a swap quote for exchanging tokens.
|
|
741
|
+
* @param args Query parameters for the swap quote including token addresses, amount, and chain.
|
|
742
|
+
* @returns The {@link GetSwapQuoteResponse} returned by the API.
|
|
743
|
+
*/
|
|
744
|
+
public async getSwapQuote(
|
|
745
|
+
args: GetSwapQuoteArgs,
|
|
746
|
+
): Promise<GetSwapQuoteResponse> {
|
|
747
|
+
return this.tokensAPI.getSwapQuote(args)
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Gets details for a specific token.
|
|
752
|
+
* @param chain The chain the token is on.
|
|
753
|
+
* @param address The token contract address.
|
|
754
|
+
* @returns The {@link GetTokenResponse} returned by the API.
|
|
755
|
+
*/
|
|
756
|
+
public async getToken(
|
|
757
|
+
chain: string,
|
|
758
|
+
address: string,
|
|
759
|
+
): Promise<GetTokenResponse> {
|
|
760
|
+
return this.tokensAPI.getToken(chain, address)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Search across collections, tokens, NFTs, and accounts.
|
|
765
|
+
* Results are ranked by relevance.
|
|
766
|
+
* @param args Query parameters including query text, optional chain/asset type filters, and limit.
|
|
767
|
+
* @returns The {@link SearchResponse} returned by the API.
|
|
768
|
+
*/
|
|
769
|
+
public async search(args: SearchArgs): Promise<SearchResponse> {
|
|
770
|
+
return this.searchAPI.search(args)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Gets the list of supported blockchains and their capabilities.
|
|
775
|
+
* @returns The {@link GetChainsResponse} returned by the API.
|
|
776
|
+
*/
|
|
777
|
+
public async getChains(): Promise<GetChainsResponse> {
|
|
778
|
+
return this.chainsAPI.getChains()
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Gets token balances for a given account.
|
|
783
|
+
* @param address The wallet address to fetch token balances for.
|
|
784
|
+
* @param args Optional query parameters for filtering and pagination.
|
|
785
|
+
* @returns The {@link GetAccountTokensResponse} returned by the API.
|
|
786
|
+
*/
|
|
787
|
+
public async getAccountTokens(
|
|
788
|
+
address: string,
|
|
789
|
+
args?: GetAccountTokensArgs,
|
|
790
|
+
): Promise<GetAccountTokensResponse> {
|
|
791
|
+
return this.accountsAPI.getAccountTokens(address, args)
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Validate NFT metadata by fetching and parsing it.
|
|
796
|
+
* @param address The NFT contract address.
|
|
797
|
+
* @param identifier The token identifier.
|
|
798
|
+
* @param chain The chain where the NFT is located. Defaults to the chain set in the constructor.
|
|
799
|
+
* @param ignoreCachedItemUrls Whether to ignore cached item URLs and re-fetch from source.
|
|
800
|
+
* @returns The {@link ValidateMetadataResponse} returned by the API.
|
|
801
|
+
*/
|
|
802
|
+
public async validateNFTMetadata(
|
|
803
|
+
address: string,
|
|
804
|
+
identifier: string,
|
|
805
|
+
chain: Chain = this.chain,
|
|
806
|
+
ignoreCachedItemUrls?: boolean,
|
|
807
|
+
): Promise<ValidateMetadataResponse> {
|
|
808
|
+
return this.nftsAPI.validateMetadata(
|
|
809
|
+
address,
|
|
810
|
+
identifier,
|
|
811
|
+
chain,
|
|
812
|
+
ignoreCachedItemUrls,
|
|
813
|
+
)
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Gets all active offers for a specific NFT (not just the best offer).
|
|
818
|
+
* @param assetContractAddress The NFT contract address.
|
|
819
|
+
* @param tokenId The token identifier.
|
|
820
|
+
* @param limit The number of offers to return. Must be between 1 and 100.
|
|
821
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
822
|
+
* @param chain The chain where the NFT is located. Defaults to the chain set in the constructor.
|
|
823
|
+
* @returns The {@link GetOffersResponse} returned by the API.
|
|
824
|
+
*/
|
|
825
|
+
public async getNFTOffers(
|
|
826
|
+
assetContractAddress: string,
|
|
827
|
+
tokenId: string,
|
|
828
|
+
limit?: number,
|
|
829
|
+
next?: string,
|
|
830
|
+
chain: Chain = this.chain,
|
|
831
|
+
): Promise<GetOffersResponse> {
|
|
832
|
+
return this.offersAPI.getNFTOffers(
|
|
833
|
+
assetContractAddress,
|
|
834
|
+
tokenId,
|
|
835
|
+
limit,
|
|
836
|
+
next,
|
|
837
|
+
chain,
|
|
838
|
+
)
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Gets all active listings for a specific NFT (not just the best listing).
|
|
843
|
+
* @param assetContractAddress The NFT contract address.
|
|
844
|
+
* @param tokenId The token identifier.
|
|
845
|
+
* @param limit The number of listings to return. Must be between 1 and 100.
|
|
846
|
+
* @param next The cursor for the next page of results. This is returned from a previous request.
|
|
847
|
+
* @param chain The chain where the NFT is located. Defaults to the chain set in the constructor.
|
|
848
|
+
* @param includePrivateListings Whether to include private listings (default: false)
|
|
849
|
+
* @returns The {@link GetListingsResponse} returned by the API.
|
|
850
|
+
*/
|
|
851
|
+
public async getNFTListings(
|
|
852
|
+
assetContractAddress: string,
|
|
853
|
+
tokenId: string,
|
|
854
|
+
limit?: number,
|
|
855
|
+
next?: string,
|
|
856
|
+
chain: Chain = this.chain,
|
|
857
|
+
includePrivateListings?: boolean,
|
|
858
|
+
): Promise<GetListingsResponse> {
|
|
859
|
+
return this.listingsAPI.getNFTListings(
|
|
860
|
+
assetContractAddress,
|
|
861
|
+
tokenId,
|
|
862
|
+
limit,
|
|
863
|
+
next,
|
|
864
|
+
chain,
|
|
865
|
+
includePrivateListings,
|
|
866
|
+
)
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Gets a list of drops (mints).
|
|
871
|
+
* @param args Optional query parameters for filtering and pagination.
|
|
872
|
+
* @returns The {@link GetDropsResponse} returned by the API.
|
|
873
|
+
*/
|
|
874
|
+
public async getDrops(args?: GetDropsArgs): Promise<GetDropsResponse> {
|
|
875
|
+
return this.dropsAPI.getDrops(args)
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Gets detailed drop information for a collection.
|
|
880
|
+
* @param slug The collection slug identifying the drop.
|
|
881
|
+
* @returns The {@link GetDropResponse} returned by the API.
|
|
882
|
+
*/
|
|
883
|
+
public async getDrop(slug: string): Promise<GetDropResponse> {
|
|
884
|
+
return this.dropsAPI.getDrop(slug)
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Builds a mint transaction for a drop.
|
|
889
|
+
* @param slug The collection slug identifying the drop.
|
|
890
|
+
* @param request The mint request containing minter address and quantity.
|
|
891
|
+
* @returns The {@link DropMintResponse} with ready-to-sign transaction data.
|
|
892
|
+
*/
|
|
893
|
+
public async buildDropMintTransaction(
|
|
894
|
+
slug: string,
|
|
895
|
+
request: DropMintRequest,
|
|
896
|
+
): Promise<DropMintResponse> {
|
|
897
|
+
return this.dropsAPI.buildMintTransaction(slug, request)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Gets trending collections sorted by sales activity.
|
|
902
|
+
* @param args Optional query parameters for timeframe, chain, category, and pagination.
|
|
903
|
+
* @returns The {@link GetCollectionsPaginatedResponse} returned by the API.
|
|
904
|
+
*/
|
|
905
|
+
public async getTrendingCollections(
|
|
906
|
+
args?: GetTrendingCollectionsArgs,
|
|
907
|
+
): Promise<GetCollectionsPaginatedResponse> {
|
|
908
|
+
return this.collectionsAPI.getTrendingCollections(args)
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Gets top collections ranked by various stats.
|
|
913
|
+
* @param args Optional query parameters for sort_by, chain, category, and pagination.
|
|
914
|
+
* @returns The {@link GetCollectionsPaginatedResponse} returned by the API.
|
|
915
|
+
*/
|
|
916
|
+
public async getTopCollections(
|
|
917
|
+
args?: GetTopCollectionsArgs,
|
|
918
|
+
): Promise<GetCollectionsPaginatedResponse> {
|
|
919
|
+
return this.collectionsAPI.getTopCollections(args)
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Resolve an ENS name, OpenSea username, or wallet address to canonical account info.
|
|
924
|
+
* @param identifier An ENS name (e.g. vitalik.eth), OpenSea username, or wallet address.
|
|
925
|
+
* @returns The {@link ResolveAccountResponse} returned by the API.
|
|
926
|
+
*/
|
|
927
|
+
public async resolveAccount(
|
|
928
|
+
identifier: string,
|
|
929
|
+
): Promise<ResolveAccountResponse> {
|
|
930
|
+
return this.accountsAPI.resolveAccount(identifier)
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Generic fetch method for any API endpoint with automatic rate limit retry
|
|
935
|
+
* @param apiPath Path to URL endpoint under API
|
|
936
|
+
* @param query URL query params. Will be used to create a URLSearchParams object.
|
|
937
|
+
* @param options Request options like timeout and abort signal.
|
|
938
|
+
* @returns @typeParam T The response from the API.
|
|
939
|
+
*/
|
|
940
|
+
public async get<T>(
|
|
941
|
+
apiPath: string,
|
|
942
|
+
query: object = {},
|
|
943
|
+
options?: RequestOptions,
|
|
944
|
+
): Promise<T> {
|
|
945
|
+
return executeWithRateLimit(
|
|
946
|
+
async () => {
|
|
947
|
+
const qs = this.objectToSearchParams(query)
|
|
948
|
+
const url = qs
|
|
949
|
+
? `${this.apiBaseUrl}${apiPath}?${qs}`
|
|
950
|
+
: `${this.apiBaseUrl}${apiPath}`
|
|
951
|
+
return await this._fetch(url, undefined, undefined, options)
|
|
952
|
+
},
|
|
953
|
+
{ logger: this.logger },
|
|
954
|
+
)
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Generic post method for any API endpoint with automatic rate limit retry
|
|
959
|
+
* @param apiPath Path to URL endpoint under API
|
|
960
|
+
* @param body Data to send.
|
|
961
|
+
* @param headers Additional headers to send with the request.
|
|
962
|
+
* @param options Request options like timeout and abort signal.
|
|
963
|
+
* @returns @typeParam T The response from the API.
|
|
964
|
+
*/
|
|
965
|
+
public async post<T>(
|
|
966
|
+
apiPath: string,
|
|
967
|
+
body?: object,
|
|
968
|
+
headers?: object,
|
|
969
|
+
options?: RequestOptions,
|
|
970
|
+
): Promise<T> {
|
|
971
|
+
return executeWithRateLimit(
|
|
972
|
+
async () => {
|
|
973
|
+
const url = `${this.apiBaseUrl}${apiPath}`
|
|
974
|
+
return await this._fetch(url, headers, body, options)
|
|
975
|
+
},
|
|
976
|
+
{ logger: this.logger },
|
|
977
|
+
)
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
private objectToSearchParams(params: object = {}) {
|
|
981
|
+
const urlSearchParams = new URLSearchParams()
|
|
982
|
+
|
|
983
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
984
|
+
if (Array.isArray(value)) {
|
|
985
|
+
value.forEach(item => {
|
|
986
|
+
if (item != null) {
|
|
987
|
+
urlSearchParams.append(key, String(item))
|
|
988
|
+
}
|
|
989
|
+
})
|
|
990
|
+
} else if (value != null) {
|
|
991
|
+
urlSearchParams.append(key, String(value))
|
|
992
|
+
}
|
|
993
|
+
})
|
|
994
|
+
|
|
995
|
+
return urlSearchParams.toString()
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* Fetch from an API Endpoint, sending auth token in headers
|
|
1000
|
+
* @param url The URL to fetch
|
|
1001
|
+
* @param headers Additional headers to send with the request
|
|
1002
|
+
* @param body Optional body to send. If set, will POST, otherwise GET
|
|
1003
|
+
* @param options Request options like timeout and abort signal
|
|
1004
|
+
*/
|
|
1005
|
+
private async _fetch(
|
|
1006
|
+
url: string,
|
|
1007
|
+
headers?: object,
|
|
1008
|
+
body?: object,
|
|
1009
|
+
options?: RequestOptions,
|
|
1010
|
+
) {
|
|
1011
|
+
// Create the fetch request
|
|
1012
|
+
const req = new ethers.FetchRequest(url)
|
|
1013
|
+
|
|
1014
|
+
// Set the headers
|
|
1015
|
+
headers = {
|
|
1016
|
+
"x-app-id": "opensea-js",
|
|
1017
|
+
...(this.apiKey ? { "X-API-KEY": this.apiKey } : {}),
|
|
1018
|
+
...headers,
|
|
1019
|
+
}
|
|
1020
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1021
|
+
req.setHeader(key, value)
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// Set the body if provided
|
|
1025
|
+
if (body) {
|
|
1026
|
+
req.body = body
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// Apply request options
|
|
1030
|
+
if (options?.timeout !== undefined) {
|
|
1031
|
+
req.timeout = options.timeout
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// Set up abort signal handling
|
|
1035
|
+
let abortHandler: (() => void) | undefined
|
|
1036
|
+
if (options?.signal) {
|
|
1037
|
+
if (options.signal.aborted) {
|
|
1038
|
+
throw new Error("Request aborted")
|
|
1039
|
+
}
|
|
1040
|
+
abortHandler = () => req.cancel()
|
|
1041
|
+
options.signal.addEventListener("abort", abortHandler)
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Set the throttle params
|
|
1045
|
+
req.setThrottleParams({ slotInterval: 1000 })
|
|
1046
|
+
|
|
1047
|
+
const sanitizedHeaders = { ...req.headers }
|
|
1048
|
+
delete sanitizedHeaders["X-API-KEY"]
|
|
1049
|
+
this.logger(
|
|
1050
|
+
`Sending request: ${url} ${JSON.stringify({
|
|
1051
|
+
method: body ? "POST" : "GET",
|
|
1052
|
+
headers: sanitizedHeaders,
|
|
1053
|
+
body: body ? JSON.stringify(body, null, 2) : undefined,
|
|
1054
|
+
})}`,
|
|
1055
|
+
)
|
|
1056
|
+
|
|
1057
|
+
try {
|
|
1058
|
+
const response = await req.send()
|
|
1059
|
+
if (!response.ok()) {
|
|
1060
|
+
// Handle rate limit errors (429 Too Many Requests and 599 custom rate limit)
|
|
1061
|
+
if (response.statusCode === 599 || response.statusCode === 429) {
|
|
1062
|
+
throw this._createRateLimitError(response)
|
|
1063
|
+
}
|
|
1064
|
+
// If an errors array is returned, throw with the error messages.
|
|
1065
|
+
const errors = response.bodyJson?.errors
|
|
1066
|
+
if (errors?.length > 0) {
|
|
1067
|
+
let errorMessage = Array.isArray(errors)
|
|
1068
|
+
? errors.join(", ")
|
|
1069
|
+
: String(errors)
|
|
1070
|
+
if (errorMessage === "[object Object]") {
|
|
1071
|
+
errorMessage = JSON.stringify(errors)
|
|
1072
|
+
}
|
|
1073
|
+
throw new Error(`Server Error: ${errorMessage}`)
|
|
1074
|
+
} else {
|
|
1075
|
+
// Otherwise, let ethers throw a SERVER_ERROR since it will include
|
|
1076
|
+
// more context about the request and response.
|
|
1077
|
+
response.assertOk()
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
return response.bodyJson
|
|
1081
|
+
} finally {
|
|
1082
|
+
// Clean up abort handler
|
|
1083
|
+
if (abortHandler && options?.signal) {
|
|
1084
|
+
options.signal.removeEventListener("abort", abortHandler)
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Maximum retry-after value in seconds (5 minutes).
|
|
1091
|
+
* Prevents excessively long waits from buggy or malicious servers.
|
|
1092
|
+
*/
|
|
1093
|
+
private static readonly MAX_RETRY_AFTER_SECONDS = 300
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* Parses the retry-after header from the response with robust error handling.
|
|
1097
|
+
* @param response The HTTP response object from the API
|
|
1098
|
+
* @returns The retry-after value in seconds (capped at 5 minutes), or undefined if not present or invalid
|
|
1099
|
+
*/
|
|
1100
|
+
private _parseRetryAfter(response: ethers.FetchResponse): number | undefined {
|
|
1101
|
+
const retryAfterHeader =
|
|
1102
|
+
response.headers["retry-after"] || response.headers["Retry-After"]
|
|
1103
|
+
if (retryAfterHeader) {
|
|
1104
|
+
const trimmed = retryAfterHeader.trim()
|
|
1105
|
+
|
|
1106
|
+
// If it starts with a digit or minus sign, treat as numeric
|
|
1107
|
+
if (/^-?\d/.test(trimmed)) {
|
|
1108
|
+
// Only accept fully numeric integer values, reject malformed inputs like "5s" or "1.5"
|
|
1109
|
+
if (!/^-?\d+$/.test(trimmed)) {
|
|
1110
|
+
return undefined
|
|
1111
|
+
}
|
|
1112
|
+
const parsedSeconds = Number(trimmed)
|
|
1113
|
+
if (!Number.isSafeInteger(parsedSeconds) || parsedSeconds <= 0) {
|
|
1114
|
+
return undefined
|
|
1115
|
+
}
|
|
1116
|
+
return Math.min(parsedSeconds, OpenSeaAPI.MAX_RETRY_AFTER_SECONDS)
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// Otherwise, try to parse as HTTP-date
|
|
1120
|
+
const parsedDateMs = Date.parse(trimmed)
|
|
1121
|
+
if (Number.isNaN(parsedDateMs)) {
|
|
1122
|
+
return undefined
|
|
1123
|
+
}
|
|
1124
|
+
const diffSeconds = Math.ceil((parsedDateMs - Date.now()) / 1000)
|
|
1125
|
+
if (diffSeconds <= 0) {
|
|
1126
|
+
return undefined
|
|
1127
|
+
}
|
|
1128
|
+
return Math.min(diffSeconds, OpenSeaAPI.MAX_RETRY_AFTER_SECONDS)
|
|
1129
|
+
}
|
|
1130
|
+
return undefined
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Creates a rate limit error with status code and retry-after information.
|
|
1135
|
+
* @param response The HTTP response object from the API
|
|
1136
|
+
* @returns An enhanced Error object with statusCode, retryAfter and responseBody properties
|
|
1137
|
+
*/
|
|
1138
|
+
private _createRateLimitError(
|
|
1139
|
+
response: ethers.FetchResponse,
|
|
1140
|
+
): OpenSeaRateLimitError {
|
|
1141
|
+
const retryAfter = this._parseRetryAfter(response)
|
|
1142
|
+
const error = new Error(
|
|
1143
|
+
`${response.statusCode} ${response.statusMessage}`,
|
|
1144
|
+
) as OpenSeaRateLimitError
|
|
1145
|
+
|
|
1146
|
+
// Add status code and retry-after information to the error object
|
|
1147
|
+
error.statusCode = response.statusCode
|
|
1148
|
+
error.retryAfter = retryAfter
|
|
1149
|
+
error.responseBody = response.bodyJson
|
|
1150
|
+
return error
|
|
1151
|
+
}
|
|
1152
|
+
}
|