@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.
Files changed (363) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +70 -0
  3. package/lib/api/accounts.d.ts +27 -0
  4. package/lib/api/accounts.js +46 -0
  5. package/lib/api/accounts.js.map +1 -0
  6. package/lib/api/api.d.ts +489 -0
  7. package/lib/api/api.js +754 -0
  8. package/lib/api/api.js.map +1 -0
  9. package/lib/api/apiPaths.d.ts +46 -0
  10. package/lib/api/apiPaths.js +176 -0
  11. package/lib/api/apiPaths.js.map +1 -0
  12. package/lib/api/chains.d.ts +13 -0
  13. package/lib/api/chains.js +22 -0
  14. package/lib/api/chains.js.map +1 -0
  15. package/lib/api/collections.d.ts +34 -0
  16. package/lib/api/collections.js +80 -0
  17. package/lib/api/collections.js.map +1 -0
  18. package/lib/api/drops.d.ts +21 -0
  19. package/lib/api/drops.js +39 -0
  20. package/lib/api/drops.js.map +1 -0
  21. package/lib/api/events.d.ts +26 -0
  22. package/lib/api/events.js +43 -0
  23. package/lib/api/events.js.map +1 -0
  24. package/lib/api/fetcher.d.ts +24 -0
  25. package/lib/api/fetcher.js +3 -0
  26. package/lib/api/fetcher.js.map +1 -0
  27. package/lib/api/index.d.ts +2 -0
  28. package/lib/api/index.js +19 -0
  29. package/lib/api/index.js.map +1 -0
  30. package/lib/api/listings.d.ts +44 -0
  31. package/lib/api/listings.js +88 -0
  32. package/lib/api/listings.js.map +1 -0
  33. package/lib/api/nfts.d.ts +39 -0
  34. package/lib/api/nfts.js +79 -0
  35. package/lib/api/nfts.js.map +1 -0
  36. package/lib/api/offers.d.ts +54 -0
  37. package/lib/api/offers.js +124 -0
  38. package/lib/api/offers.js.map +1 -0
  39. package/lib/api/orders.d.ts +50 -0
  40. package/lib/api/orders.js +153 -0
  41. package/lib/api/orders.js.map +1 -0
  42. package/lib/api/search.d.ts +13 -0
  43. package/lib/api/search.js +22 -0
  44. package/lib/api/search.js.map +1 -0
  45. package/lib/api/tokens.d.ts +25 -0
  46. package/lib/api/tokens.js +43 -0
  47. package/lib/api/tokens.js.map +1 -0
  48. package/lib/api/types.d.ts +1113 -0
  49. package/lib/api/types.js +65 -0
  50. package/lib/api/types.js.map +1 -0
  51. package/lib/constants.d.ts +22 -0
  52. package/lib/constants.js +52 -0
  53. package/lib/constants.js.map +1 -0
  54. package/lib/index.d.ts +18 -0
  55. package/lib/index.js +24 -0
  56. package/lib/index.js.map +1 -0
  57. package/lib/orders/privateListings.d.ts +12 -0
  58. package/lib/orders/privateListings.js +130 -0
  59. package/lib/orders/privateListings.js.map +1 -0
  60. package/lib/orders/types.d.ts +160 -0
  61. package/lib/orders/types.js +10 -0
  62. package/lib/orders/types.js.map +1 -0
  63. package/lib/orders/utils.d.ts +89 -0
  64. package/lib/orders/utils.js +177 -0
  65. package/lib/orders/utils.js.map +1 -0
  66. package/lib/sdk/assets.d.ts +104 -0
  67. package/lib/sdk/assets.js +398 -0
  68. package/lib/sdk/assets.js.map +1 -0
  69. package/lib/sdk/cancellation.d.ts +97 -0
  70. package/lib/sdk/cancellation.js +235 -0
  71. package/lib/sdk/cancellation.js.map +1 -0
  72. package/lib/sdk/context.d.ts +28 -0
  73. package/lib/sdk/context.js +3 -0
  74. package/lib/sdk/context.js.map +1 -0
  75. package/lib/sdk/fulfillment.d.ts +153 -0
  76. package/lib/sdk/fulfillment.js +298 -0
  77. package/lib/sdk/fulfillment.js.map +1 -0
  78. package/lib/sdk/orders.d.ts +253 -0
  79. package/lib/sdk/orders.js +679 -0
  80. package/lib/sdk/orders.js.map +1 -0
  81. package/lib/sdk/tokens.d.ts +31 -0
  82. package/lib/sdk/tokens.js +65 -0
  83. package/lib/sdk/tokens.js.map +1 -0
  84. package/lib/sdk.d.ts +560 -0
  85. package/lib/sdk.js +693 -0
  86. package/lib/sdk.js.map +1 -0
  87. package/lib/src/api/accounts.d.ts +18 -0
  88. package/lib/src/api/accounts.js +30 -0
  89. package/lib/src/api/accounts.js.map +1 -0
  90. package/lib/src/api/api.d.ts +429 -0
  91. package/lib/src/api/api.js +652 -0
  92. package/lib/src/api/api.js.map +1 -0
  93. package/lib/src/api/apiPaths.d.ts +37 -0
  94. package/lib/src/api/apiPaths.js +140 -0
  95. package/lib/src/api/apiPaths.js.map +1 -0
  96. package/lib/src/api/collections.d.ts +26 -0
  97. package/lib/src/api/collections.js +57 -0
  98. package/lib/src/api/collections.js.map +1 -0
  99. package/lib/src/api/events.d.ts +26 -0
  100. package/lib/src/api/events.js +42 -0
  101. package/lib/src/api/events.js.map +1 -0
  102. package/lib/src/api/fetcher.d.ts +24 -0
  103. package/lib/src/api/fetcher.js +3 -0
  104. package/lib/src/api/fetcher.js.map +1 -0
  105. package/lib/src/api/index.d.ts +2 -0
  106. package/lib/src/api/index.js +19 -0
  107. package/lib/src/api/index.js.map +1 -0
  108. package/lib/src/api/listings.d.ts +44 -0
  109. package/lib/src/api/listings.js +86 -0
  110. package/lib/src/api/listings.js.map +1 -0
  111. package/lib/src/api/nfts.d.ts +35 -0
  112. package/lib/src/api/nfts.js +66 -0
  113. package/lib/src/api/nfts.js.map +1 -0
  114. package/lib/src/api/offers.d.ts +54 -0
  115. package/lib/src/api/offers.js +122 -0
  116. package/lib/src/api/offers.js.map +1 -0
  117. package/lib/src/api/orders.d.ts +50 -0
  118. package/lib/src/api/orders.js +151 -0
  119. package/lib/src/api/orders.js.map +1 -0
  120. package/lib/src/api/search.d.ts +13 -0
  121. package/lib/src/api/search.js +21 -0
  122. package/lib/src/api/search.js.map +1 -0
  123. package/lib/src/api/tokens.d.ts +25 -0
  124. package/lib/src/api/tokens.js +42 -0
  125. package/lib/src/api/tokens.js.map +1 -0
  126. package/lib/src/api/types.d.ts +840 -0
  127. package/lib/src/api/types.js +65 -0
  128. package/lib/src/api/types.js.map +1 -0
  129. package/lib/src/constants.d.ts +22 -0
  130. package/lib/src/constants.js +52 -0
  131. package/lib/src/constants.js.map +1 -0
  132. package/lib/src/index.d.ts +18 -0
  133. package/lib/src/index.js +24 -0
  134. package/lib/src/index.js.map +1 -0
  135. package/lib/src/orders/privateListings.d.ts +12 -0
  136. package/lib/src/orders/privateListings.js +130 -0
  137. package/lib/src/orders/privateListings.js.map +1 -0
  138. package/lib/src/orders/types.d.ts +160 -0
  139. package/lib/src/orders/types.js +10 -0
  140. package/lib/src/orders/types.js.map +1 -0
  141. package/lib/src/orders/utils.d.ts +89 -0
  142. package/lib/src/orders/utils.js +177 -0
  143. package/lib/src/orders/utils.js.map +1 -0
  144. package/lib/src/sdk/assets.d.ts +104 -0
  145. package/lib/src/sdk/assets.js +397 -0
  146. package/lib/src/sdk/assets.js.map +1 -0
  147. package/lib/src/sdk/cancellation.d.ts +97 -0
  148. package/lib/src/sdk/cancellation.js +234 -0
  149. package/lib/src/sdk/cancellation.js.map +1 -0
  150. package/lib/src/sdk/context.d.ts +28 -0
  151. package/lib/src/sdk/context.js +3 -0
  152. package/lib/src/sdk/context.js.map +1 -0
  153. package/lib/src/sdk/fulfillment.d.ts +153 -0
  154. package/lib/src/sdk/fulfillment.js +296 -0
  155. package/lib/src/sdk/fulfillment.js.map +1 -0
  156. package/lib/src/sdk/orders.d.ts +253 -0
  157. package/lib/src/sdk/orders.js +677 -0
  158. package/lib/src/sdk/orders.js.map +1 -0
  159. package/lib/src/sdk/tokens.d.ts +31 -0
  160. package/lib/src/sdk/tokens.js +64 -0
  161. package/lib/src/sdk/tokens.js.map +1 -0
  162. package/lib/src/sdk.d.ts +560 -0
  163. package/lib/src/sdk.js +675 -0
  164. package/lib/src/sdk.js.map +1 -0
  165. package/lib/src/typechain/contracts/ERC1155.d.ts +236 -0
  166. package/lib/src/typechain/contracts/ERC1155.js +3 -0
  167. package/lib/src/typechain/contracts/ERC1155.js.map +1 -0
  168. package/lib/src/typechain/contracts/ERC20.d.ts +141 -0
  169. package/lib/src/typechain/contracts/ERC20.js +3 -0
  170. package/lib/src/typechain/contracts/ERC20.js.map +1 -0
  171. package/lib/src/typechain/contracts/ERC721.d.ts +213 -0
  172. package/lib/src/typechain/contracts/ERC721.js +3 -0
  173. package/lib/src/typechain/contracts/ERC721.js.map +1 -0
  174. package/lib/src/typechain/contracts/Multicall3.d.ts +57 -0
  175. package/lib/src/typechain/contracts/Multicall3.js +3 -0
  176. package/lib/src/typechain/contracts/Multicall3.js.map +1 -0
  177. package/lib/src/typechain/contracts/TransferHelper.d.ts +55 -0
  178. package/lib/src/typechain/contracts/TransferHelper.js +3 -0
  179. package/lib/src/typechain/contracts/TransferHelper.js.map +1 -0
  180. package/lib/src/typechain/contracts/common.d.ts +50 -0
  181. package/lib/src/typechain/contracts/common.js +3 -0
  182. package/lib/src/typechain/contracts/common.js.map +1 -0
  183. package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
  184. package/lib/src/typechain/contracts/factories/ERC1155__factory.js +332 -0
  185. package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
  186. package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
  187. package/lib/src/typechain/contracts/factories/ERC20__factory.js +240 -0
  188. package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +1 -0
  189. package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
  190. package/lib/src/typechain/contracts/factories/ERC721__factory.js +351 -0
  191. package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +1 -0
  192. package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
  193. package/lib/src/typechain/contracts/factories/Multicall3__factory.js +68 -0
  194. package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
  195. package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
  196. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +71 -0
  197. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
  198. package/lib/src/typechain/contracts/factories/index.d.ts +5 -0
  199. package/lib/src/typechain/contracts/factories/index.js +17 -0
  200. package/lib/src/typechain/contracts/factories/index.js.map +1 -0
  201. package/lib/src/typechain/contracts/index.d.ts +11 -0
  202. package/lib/src/typechain/contracts/index.js +48 -0
  203. package/lib/src/typechain/contracts/index.js.map +1 -0
  204. package/lib/src/types.d.ts +387 -0
  205. package/lib/src/types.js +127 -0
  206. package/lib/src/types.js.map +1 -0
  207. package/lib/src/utils/chain.d.ts +60 -0
  208. package/lib/src/utils/chain.js +248 -0
  209. package/lib/src/utils/chain.js.map +1 -0
  210. package/lib/src/utils/converters.d.ts +37 -0
  211. package/lib/src/utils/converters.js +137 -0
  212. package/lib/src/utils/converters.js.map +1 -0
  213. package/lib/src/utils/dateHelper.d.ts +38 -0
  214. package/lib/src/utils/dateHelper.js +52 -0
  215. package/lib/src/utils/dateHelper.js.map +1 -0
  216. package/lib/src/utils/fees.d.ts +13 -0
  217. package/lib/src/utils/fees.js +29 -0
  218. package/lib/src/utils/fees.js.map +1 -0
  219. package/lib/src/utils/index.d.ts +2 -0
  220. package/lib/src/utils/index.js +19 -0
  221. package/lib/src/utils/index.js.map +1 -0
  222. package/lib/src/utils/protocol.d.ts +75 -0
  223. package/lib/src/utils/protocol.js +161 -0
  224. package/lib/src/utils/protocol.js.map +1 -0
  225. package/lib/src/utils/rateLimit.d.ts +34 -0
  226. package/lib/src/utils/rateLimit.js +97 -0
  227. package/lib/src/utils/rateLimit.js.map +1 -0
  228. package/lib/src/utils/stringHelper.d.ts +18 -0
  229. package/lib/src/utils/stringHelper.js +24 -0
  230. package/lib/src/utils/stringHelper.js.map +1 -0
  231. package/lib/src/utils/utils.d.ts +18 -0
  232. package/lib/src/utils/utils.js +45 -0
  233. package/lib/src/utils/utils.js.map +1 -0
  234. package/lib/typechain/contracts/ERC1155.d.ts +236 -0
  235. package/lib/typechain/contracts/ERC1155.js +3 -0
  236. package/lib/typechain/contracts/ERC1155.js.map +1 -0
  237. package/lib/typechain/contracts/ERC20.d.ts +141 -0
  238. package/lib/typechain/contracts/ERC20.js +3 -0
  239. package/lib/typechain/contracts/ERC20.js.map +1 -0
  240. package/lib/typechain/contracts/ERC721.d.ts +213 -0
  241. package/lib/typechain/contracts/ERC721.js +3 -0
  242. package/lib/typechain/contracts/ERC721.js.map +1 -0
  243. package/lib/typechain/contracts/Multicall3.d.ts +57 -0
  244. package/lib/typechain/contracts/Multicall3.js +3 -0
  245. package/lib/typechain/contracts/Multicall3.js.map +1 -0
  246. package/lib/typechain/contracts/TransferHelper.d.ts +55 -0
  247. package/lib/typechain/contracts/TransferHelper.js +3 -0
  248. package/lib/typechain/contracts/TransferHelper.js.map +1 -0
  249. package/lib/typechain/contracts/common.d.ts +50 -0
  250. package/lib/typechain/contracts/common.js +3 -0
  251. package/lib/typechain/contracts/common.js.map +1 -0
  252. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +250 -0
  253. package/lib/typechain/contracts/factories/ERC1155__factory.js +332 -0
  254. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
  255. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +174 -0
  256. package/lib/typechain/contracts/factories/ERC20__factory.js +240 -0
  257. package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -0
  258. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +268 -0
  259. package/lib/typechain/contracts/factories/ERC721__factory.js +351 -0
  260. package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -0
  261. package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +43 -0
  262. package/lib/typechain/contracts/factories/Multicall3__factory.js +68 -0
  263. package/lib/typechain/contracts/factories/Multicall3__factory.js.map +1 -0
  264. package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +46 -0
  265. package/lib/typechain/contracts/factories/TransferHelper__factory.js +71 -0
  266. package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +1 -0
  267. package/lib/typechain/contracts/factories/index.d.ts +5 -0
  268. package/lib/typechain/contracts/factories/index.js +17 -0
  269. package/lib/typechain/contracts/factories/index.js.map +1 -0
  270. package/lib/typechain/contracts/index.d.ts +11 -0
  271. package/lib/typechain/contracts/index.js +48 -0
  272. package/lib/typechain/contracts/index.js.map +1 -0
  273. package/lib/types.d.ts +389 -0
  274. package/lib/types.js +129 -0
  275. package/lib/types.js.map +1 -0
  276. package/lib/utils/chain.d.ts +64 -0
  277. package/lib/utils/chain.js +211 -0
  278. package/lib/utils/chain.js.map +1 -0
  279. package/lib/utils/chainIds.generated.d.ts +7 -0
  280. package/lib/utils/chainIds.generated.js +37 -0
  281. package/lib/utils/chainIds.generated.js.map +1 -0
  282. package/lib/utils/converters.d.ts +37 -0
  283. package/lib/utils/converters.js +137 -0
  284. package/lib/utils/converters.js.map +1 -0
  285. package/lib/utils/dateHelper.d.ts +38 -0
  286. package/lib/utils/dateHelper.js +52 -0
  287. package/lib/utils/dateHelper.js.map +1 -0
  288. package/lib/utils/fees.d.ts +13 -0
  289. package/lib/utils/fees.js +29 -0
  290. package/lib/utils/fees.js.map +1 -0
  291. package/lib/utils/index.d.ts +2 -0
  292. package/lib/utils/index.js +19 -0
  293. package/lib/utils/index.js.map +1 -0
  294. package/lib/utils/protocol.d.ts +75 -0
  295. package/lib/utils/protocol.js +161 -0
  296. package/lib/utils/protocol.js.map +1 -0
  297. package/lib/utils/rateLimit.d.ts +34 -0
  298. package/lib/utils/rateLimit.js +97 -0
  299. package/lib/utils/rateLimit.js.map +1 -0
  300. package/lib/utils/stringHelper.d.ts +18 -0
  301. package/lib/utils/stringHelper.js +24 -0
  302. package/lib/utils/stringHelper.js.map +1 -0
  303. package/lib/utils/utils.d.ts +18 -0
  304. package/lib/utils/utils.js +45 -0
  305. package/lib/utils/utils.js.map +1 -0
  306. package/package.json +72 -0
  307. package/src/abi/ERC1155.json +314 -0
  308. package/src/abi/ERC20.json +222 -0
  309. package/src/abi/ERC721.json +333 -0
  310. package/src/abi/Multicall3.json +50 -0
  311. package/src/abi/TransferHelper.json +53 -0
  312. package/src/api/accounts.ts +69 -0
  313. package/src/api/api.ts +1152 -0
  314. package/src/api/apiPaths.ts +208 -0
  315. package/src/api/chains.ts +18 -0
  316. package/src/api/collections.ts +120 -0
  317. package/src/api/drops.ts +49 -0
  318. package/src/api/events.ts +71 -0
  319. package/src/api/fetcher.ts +31 -0
  320. package/src/api/index.ts +2 -0
  321. package/src/api/listings.ts +126 -0
  322. package/src/api/nfts.ts +144 -0
  323. package/src/api/offers.ts +242 -0
  324. package/src/api/orders.ts +283 -0
  325. package/src/api/search.ts +21 -0
  326. package/src/api/tokens.ts +67 -0
  327. package/src/api/types.ts +1210 -0
  328. package/src/constants.ts +90 -0
  329. package/src/index.ts +22 -0
  330. package/src/orders/privateListings.ts +173 -0
  331. package/src/orders/types.ts +191 -0
  332. package/src/orders/utils.ts +253 -0
  333. package/src/sdk/assets.ts +591 -0
  334. package/src/sdk/cancellation.ts +346 -0
  335. package/src/sdk/context.ts +33 -0
  336. package/src/sdk/fulfillment.ts +478 -0
  337. package/src/sdk/orders.ts +1149 -0
  338. package/src/sdk/tokens.ts +95 -0
  339. package/src/sdk.ts +1051 -0
  340. package/src/typechain/contracts/ERC1155.ts +440 -0
  341. package/src/typechain/contracts/ERC20.ts +286 -0
  342. package/src/typechain/contracts/ERC721.ts +412 -0
  343. package/src/typechain/contracts/Multicall3.ts +117 -0
  344. package/src/typechain/contracts/TransferHelper.ts +122 -0
  345. package/src/typechain/contracts/common.ts +131 -0
  346. package/src/typechain/contracts/factories/ERC1155__factory.ts +331 -0
  347. package/src/typechain/contracts/factories/ERC20__factory.ts +239 -0
  348. package/src/typechain/contracts/factories/ERC721__factory.ts +350 -0
  349. package/src/typechain/contracts/factories/Multicall3__factory.ts +67 -0
  350. package/src/typechain/contracts/factories/TransferHelper__factory.ts +76 -0
  351. package/src/typechain/contracts/factories/index.ts +8 -0
  352. package/src/typechain/contracts/index.ts +14 -0
  353. package/src/types.ts +413 -0
  354. package/src/utils/chain.ts +224 -0
  355. package/src/utils/chainIds.generated.ts +34 -0
  356. package/src/utils/converters.ts +145 -0
  357. package/src/utils/dateHelper.ts +48 -0
  358. package/src/utils/fees.ts +31 -0
  359. package/src/utils/index.ts +2 -0
  360. package/src/utils/protocol.ts +185 -0
  361. package/src/utils/rateLimit.ts +147 -0
  362. package/src/utils/stringHelper.ts +25 -0
  363. package/src/utils/utils.ts +36 -0
@@ -0,0 +1,144 @@
1
+ import type { Chain } from "../types"
2
+ import {
3
+ getContractPath,
4
+ getListNFTsByAccountPath,
5
+ getListNFTsByCollectionPath,
6
+ getListNFTsByContractPath,
7
+ getNFTPath,
8
+ getRefreshMetadataPath,
9
+ getValidateMetadataPath,
10
+ } from "./apiPaths"
11
+ import type { Fetcher } from "./fetcher"
12
+ import type {
13
+ GetContractResponse,
14
+ GetNFTResponse,
15
+ ListNFTsResponse,
16
+ ValidateMetadataResponse,
17
+ } from "./types"
18
+
19
+ /**
20
+ * NFT-related API operations
21
+ */
22
+ export class NFTsAPI {
23
+ constructor(
24
+ private fetcher: Fetcher,
25
+ private chain: Chain,
26
+ ) {}
27
+
28
+ /**
29
+ * Fetch multiple NFTs for a collection.
30
+ */
31
+ async getNFTsByCollection(
32
+ slug: string,
33
+ limit: number | undefined = undefined,
34
+ next: string | undefined = undefined,
35
+ ): Promise<ListNFTsResponse> {
36
+ const response = await this.fetcher.get<ListNFTsResponse>(
37
+ getListNFTsByCollectionPath(slug),
38
+ {
39
+ limit,
40
+ next,
41
+ },
42
+ )
43
+ return response
44
+ }
45
+
46
+ /**
47
+ * Fetch multiple NFTs for a contract.
48
+ */
49
+ async getNFTsByContract(
50
+ address: string,
51
+ limit: number | undefined = undefined,
52
+ next: string | undefined = undefined,
53
+ chain: Chain = this.chain,
54
+ ): Promise<ListNFTsResponse> {
55
+ const response = await this.fetcher.get<ListNFTsResponse>(
56
+ getListNFTsByContractPath(chain, address),
57
+ {
58
+ limit,
59
+ next,
60
+ },
61
+ )
62
+ return response
63
+ }
64
+
65
+ /**
66
+ * Fetch NFTs owned by an account.
67
+ */
68
+ async getNFTsByAccount(
69
+ address: string,
70
+ limit: number | undefined = undefined,
71
+ next: string | undefined = undefined,
72
+ chain = this.chain,
73
+ ): Promise<ListNFTsResponse> {
74
+ const response = await this.fetcher.get<ListNFTsResponse>(
75
+ getListNFTsByAccountPath(chain, address),
76
+ {
77
+ limit,
78
+ next,
79
+ },
80
+ )
81
+
82
+ return response
83
+ }
84
+
85
+ /**
86
+ * Fetch metadata, traits, ownership information, and rarity for a single NFT.
87
+ */
88
+ async getNFT(
89
+ address: string,
90
+ identifier: string,
91
+ chain = this.chain,
92
+ ): Promise<GetNFTResponse> {
93
+ const response = await this.fetcher.get<GetNFTResponse>(
94
+ getNFTPath(chain, address, identifier),
95
+ )
96
+ return response
97
+ }
98
+
99
+ /**
100
+ * Force refresh the metadata for an NFT.
101
+ */
102
+ async refreshNFTMetadata(
103
+ address: string,
104
+ identifier: string,
105
+ chain: Chain = this.chain,
106
+ ): Promise<Response> {
107
+ const response = await this.fetcher.post<Response>(
108
+ getRefreshMetadataPath(chain, address, identifier),
109
+ {},
110
+ )
111
+
112
+ return response
113
+ }
114
+
115
+ /**
116
+ * Fetch smart contract information for a given chain and address.
117
+ */
118
+ async getContract(
119
+ address: string,
120
+ chain: Chain = this.chain,
121
+ ): Promise<GetContractResponse> {
122
+ const response = await this.fetcher.get<GetContractResponse>(
123
+ getContractPath(chain, address),
124
+ )
125
+ return response
126
+ }
127
+
128
+ /**
129
+ * Validate NFT metadata by fetching and parsing it.
130
+ */
131
+ async validateMetadata(
132
+ address: string,
133
+ identifier: string,
134
+ chain: Chain = this.chain,
135
+ ignoreCachedItemUrls?: boolean,
136
+ ): Promise<ValidateMetadataResponse> {
137
+ let path = getValidateMetadataPath(chain, address, identifier)
138
+ if (ignoreCachedItemUrls !== undefined) {
139
+ path += `?ignoreCachedItemUrls=${ignoreCachedItemUrls}`
140
+ }
141
+ const response = await this.fetcher.post<ValidateMetadataResponse>(path)
142
+ return response
143
+ }
144
+ }
@@ -0,0 +1,242 @@
1
+ import type { ProtocolData } from "../orders/types"
2
+ import {
3
+ getBuildCollectionOfferPayload,
4
+ getPostCollectionOfferPayload,
5
+ serializeOrdersQueryOptions,
6
+ } from "../orders/utils"
7
+ import { type Chain, OrderSide } from "../types"
8
+ import {
9
+ getAllOffersAPIPath,
10
+ getBestOfferAPIPath,
11
+ getBuildOfferPath,
12
+ getCollectionOffersPath,
13
+ getOrdersAPIPath,
14
+ getPostCollectionOfferPath,
15
+ getTraitOffersPath,
16
+ } from "./apiPaths"
17
+ import type { Fetcher } from "./fetcher"
18
+ import type {
19
+ BuildOfferResponse,
20
+ CollectionOffer,
21
+ GetBestOfferResponse,
22
+ GetOffersResponse,
23
+ } from "./types"
24
+
25
+ /**
26
+ * Validates trait parameters for collection offers.
27
+ * Used by both buildOffer and postCollectionOffer.
28
+ */
29
+ function validateTraitParams(
30
+ traitType?: string,
31
+ traitValue?: string,
32
+ traits?: Array<{ type: string; value: string }>,
33
+ numericTraits?: Array<{ type: string; min?: number; max?: number }>,
34
+ ) {
35
+ if (traits && traits.length > 0 && (traitType || traitValue)) {
36
+ throw new Error(
37
+ "Cannot use both 'traits' array and individual 'traitType'/'traitValue' parameters. Please use only one approach.",
38
+ )
39
+ }
40
+ if (traitType || traitValue) {
41
+ if (!traitType || !traitValue) {
42
+ throw new Error(
43
+ "Both traitType and traitValue must be defined if one is defined.",
44
+ )
45
+ }
46
+ }
47
+ if (traits && traits.length > 0) {
48
+ for (const trait of traits) {
49
+ if (!trait.type || !trait.value) {
50
+ throw new Error(
51
+ "Each trait must have both 'type' and 'value' properties.",
52
+ )
53
+ }
54
+ }
55
+ }
56
+ if (numericTraits && numericTraits.length > 0) {
57
+ for (const trait of numericTraits) {
58
+ if (!trait.type) {
59
+ throw new Error("Each numeric trait must have a 'type' property.")
60
+ }
61
+ if (trait.min === undefined && trait.max === undefined) {
62
+ throw new Error(
63
+ `Numeric trait '${trait.type}' must have at least one of 'min' or 'max'.`,
64
+ )
65
+ }
66
+ if (
67
+ trait.min !== undefined &&
68
+ trait.max !== undefined &&
69
+ trait.min > trait.max
70
+ ) {
71
+ throw new Error(
72
+ `Numeric trait '${trait.type}': 'min' (${trait.min}) must be <= 'max' (${trait.max}).`,
73
+ )
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Offer-related API operations
81
+ */
82
+ export class OffersAPI {
83
+ constructor(
84
+ private fetcher: Fetcher,
85
+ private chain: Chain,
86
+ ) {}
87
+
88
+ /**
89
+ * Gets all offers for a given collection.
90
+ */
91
+ async getAllOffers(
92
+ collectionSlug: string,
93
+ limit?: number,
94
+ next?: string,
95
+ ): Promise<GetOffersResponse> {
96
+ const response = await this.fetcher.get<GetOffersResponse>(
97
+ getAllOffersAPIPath(collectionSlug),
98
+ {
99
+ limit,
100
+ next,
101
+ },
102
+ )
103
+ return response
104
+ }
105
+
106
+ /**
107
+ * Gets trait offers for a given collection.
108
+ */
109
+ async getTraitOffers(
110
+ collectionSlug: string,
111
+ type: string,
112
+ value: string,
113
+ limit?: number,
114
+ next?: string,
115
+ floatValue?: number,
116
+ intValue?: number,
117
+ ): Promise<GetOffersResponse> {
118
+ const response = await this.fetcher.get<GetOffersResponse>(
119
+ getTraitOffersPath(collectionSlug),
120
+ {
121
+ type,
122
+ value,
123
+ limit,
124
+ next,
125
+ float_value: floatValue,
126
+ int_value: intValue,
127
+ },
128
+ )
129
+ return response
130
+ }
131
+
132
+ /**
133
+ * Gets the best offer for a given token.
134
+ */
135
+ async getBestOffer(
136
+ collectionSlug: string,
137
+ tokenId: string | number,
138
+ ): Promise<GetBestOfferResponse> {
139
+ const response = await this.fetcher.get<GetBestOfferResponse>(
140
+ getBestOfferAPIPath(collectionSlug, tokenId),
141
+ )
142
+ return response
143
+ }
144
+
145
+ /**
146
+ * Build a OpenSea collection offer.
147
+ */
148
+ async buildOffer(
149
+ offererAddress: string,
150
+ quantity: number,
151
+ collectionSlug: string,
152
+ offerProtectionEnabled = true,
153
+ traitType?: string,
154
+ traitValue?: string,
155
+ traits?: Array<{ type: string; value: string }>,
156
+ numericTraits?: Array<{ type: string; min?: number; max?: number }>,
157
+ ): Promise<BuildOfferResponse> {
158
+ validateTraitParams(traitType, traitValue, traits, numericTraits)
159
+ const payload = getBuildCollectionOfferPayload(
160
+ offererAddress,
161
+ quantity,
162
+ collectionSlug,
163
+ offerProtectionEnabled,
164
+ this.chain,
165
+ traitType,
166
+ traitValue,
167
+ traits,
168
+ numericTraits,
169
+ )
170
+ const response = await this.fetcher.post<BuildOfferResponse>(
171
+ getBuildOfferPath(),
172
+ payload,
173
+ )
174
+ return response
175
+ }
176
+
177
+ /**
178
+ * Get a list of collection offers for a given slug.
179
+ */
180
+ async getCollectionOffers(
181
+ slug: string,
182
+ limit?: number,
183
+ next?: string,
184
+ ): Promise<GetOffersResponse> {
185
+ return await this.fetcher.get<GetOffersResponse>(
186
+ getCollectionOffersPath(slug),
187
+ {
188
+ limit,
189
+ next,
190
+ },
191
+ )
192
+ }
193
+
194
+ /**
195
+ * Post a collection offer to OpenSea.
196
+ */
197
+ async postCollectionOffer(
198
+ order: ProtocolData,
199
+ slug: string,
200
+ traitType?: string,
201
+ traitValue?: string,
202
+ traits?: Array<{ type: string; value: string }>,
203
+ numericTraits?: Array<{ type: string; min?: number; max?: number }>,
204
+ ): Promise<CollectionOffer | null> {
205
+ validateTraitParams(traitType, traitValue, traits, numericTraits)
206
+ const payload = getPostCollectionOfferPayload(
207
+ slug,
208
+ order,
209
+ this.chain,
210
+ traitType,
211
+ traitValue,
212
+ traits,
213
+ numericTraits,
214
+ )
215
+ return await this.fetcher.post<CollectionOffer>(
216
+ getPostCollectionOfferPath(),
217
+ payload,
218
+ )
219
+ }
220
+
221
+ /**
222
+ * Gets all active offers for a specific NFT.
223
+ */
224
+ async getNFTOffers(
225
+ assetContractAddress: string,
226
+ tokenId: string,
227
+ limit?: number,
228
+ next?: string,
229
+ chain: Chain = this.chain,
230
+ ): 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
+ }),
239
+ )
240
+ return response
241
+ }
242
+ }
@@ -0,0 +1,283 @@
1
+ import type {
2
+ FulfillmentDataResponse,
3
+ ListingPostQueryResponse,
4
+ OfferPostQueryResponse,
5
+ OrderAPIOptions,
6
+ OrdersPostQueryResponse,
7
+ OrdersQueryOptions,
8
+ OrdersQueryResponse,
9
+ OrderV2,
10
+ ProtocolData,
11
+ } from "../orders/types"
12
+ import {
13
+ deserializeOrder,
14
+ getFulfillListingPayload,
15
+ getFulfillmentDataPath,
16
+ getFulfillOfferPayload,
17
+ serializeOrdersQueryOptions,
18
+ } from "../orders/utils"
19
+ import { type Chain, OrderSide } from "../types"
20
+ import {
21
+ getCancelOrderPath,
22
+ getOrderByHashPath,
23
+ getOrdersAPIPath,
24
+ } from "./apiPaths"
25
+ import type { Fetcher } from "./fetcher"
26
+ import type {
27
+ CancelOrderResponse,
28
+ GetOrderByHashResponse,
29
+ GetOrdersResponse,
30
+ Listing,
31
+ Offer,
32
+ } from "./types"
33
+
34
+ /**
35
+ * Order-related API operations
36
+ */
37
+ export class OrdersAPI {
38
+ constructor(
39
+ private fetcher: Fetcher,
40
+ private chain: Chain,
41
+ ) {}
42
+
43
+ /**
44
+ * Gets an order from API based on query options.
45
+ * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
46
+ */
47
+ async getOrder({
48
+ side,
49
+ protocol = "seaport",
50
+ orderDirection = "desc",
51
+ orderBy = "created_date",
52
+ ...restOptions
53
+ }: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2> {
54
+ // Validate eth_price orderBy requires additional parameters
55
+ if (orderBy === "eth_price") {
56
+ const hasTokenId =
57
+ (restOptions.tokenIds?.length ?? 0) > 0 ||
58
+ restOptions.tokenId !== undefined
59
+ if (!restOptions.assetContractAddress || !hasTokenId) {
60
+ throw new Error(
61
+ 'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
62
+ )
63
+ }
64
+ }
65
+
66
+ const { orders } = await this.fetcher.get<OrdersQueryResponse>(
67
+ getOrdersAPIPath(this.chain, protocol, side),
68
+ serializeOrdersQueryOptions({
69
+ limit: 1,
70
+ orderBy,
71
+ orderDirection,
72
+ ...restOptions,
73
+ }),
74
+ )
75
+ if (orders.length === 0) {
76
+ throw new Error("Not found: no matching order found")
77
+ }
78
+ return deserializeOrder(orders[0])
79
+ }
80
+
81
+ /**
82
+ * Gets a single order by its order hash.
83
+ * Returns the raw API response which can be either an Offer or Listing.
84
+ */
85
+ async getOrderByHash(
86
+ orderHash: string,
87
+ protocolAddress: string,
88
+ chain: Chain = this.chain,
89
+ ): Promise<GetOrderByHashResponse> {
90
+ const response = await this.fetcher.get<{
91
+ order: GetOrderByHashResponse
92
+ }>(getOrderByHashPath(chain, protocolAddress, orderHash))
93
+ return response.order
94
+ }
95
+
96
+ /**
97
+ * Gets a list of orders from API based on query options.
98
+ * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
99
+ */
100
+ async getOrders({
101
+ side,
102
+ protocol = "seaport",
103
+ orderDirection = "desc",
104
+ orderBy = "created_date",
105
+ pageSize = 20,
106
+ ...restOptions
107
+ }: Omit<OrdersQueryOptions, "limit"> & {
108
+ pageSize?: number
109
+ }): Promise<GetOrdersResponse> {
110
+ // Validate eth_price orderBy requires additional parameters
111
+ if (orderBy === "eth_price") {
112
+ const hasTokenId =
113
+ (restOptions.tokenIds?.length ?? 0) > 0 ||
114
+ restOptions.tokenId !== undefined
115
+ if (!restOptions.assetContractAddress || !hasTokenId) {
116
+ throw new Error(
117
+ 'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
118
+ )
119
+ }
120
+ }
121
+
122
+ const response = await this.fetcher.get<OrdersQueryResponse>(
123
+ getOrdersAPIPath(this.chain, protocol, side),
124
+ serializeOrdersQueryOptions({
125
+ limit: pageSize,
126
+ orderBy,
127
+ orderDirection,
128
+ ...restOptions,
129
+ }),
130
+ )
131
+ return {
132
+ ...response,
133
+ orders: response.orders.map(deserializeOrder),
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Generate the data needed to fulfill a listing or an offer onchain.
139
+ */
140
+ async generateFulfillmentData(
141
+ fulfillerAddress: string,
142
+ orderHash: string,
143
+ protocolAddress: string,
144
+ side: OrderSide,
145
+ assetContractAddress?: string,
146
+ tokenId?: string,
147
+ unitsToFill?: string,
148
+ recipientAddress?: string,
149
+ includeOptionalCreatorFees: boolean = false,
150
+ ): Promise<FulfillmentDataResponse> {
151
+ let payload: object | null = null
152
+ if (side === OrderSide.LISTING) {
153
+ payload = getFulfillListingPayload(
154
+ fulfillerAddress,
155
+ orderHash,
156
+ protocolAddress,
157
+ this.chain,
158
+ assetContractAddress,
159
+ tokenId,
160
+ unitsToFill,
161
+ recipientAddress,
162
+ includeOptionalCreatorFees,
163
+ )
164
+ } else {
165
+ payload = getFulfillOfferPayload(
166
+ fulfillerAddress,
167
+ orderHash,
168
+ protocolAddress,
169
+ this.chain,
170
+ assetContractAddress,
171
+ tokenId,
172
+ unitsToFill,
173
+ includeOptionalCreatorFees,
174
+ )
175
+ }
176
+ const response = await this.fetcher.post<FulfillmentDataResponse>(
177
+ getFulfillmentDataPath(side),
178
+ payload,
179
+ )
180
+ return response
181
+ }
182
+
183
+ /**
184
+ * Post an order to OpenSea.
185
+ * @deprecated Use postListing or postOffer instead.
186
+ */
187
+ async postOrder(
188
+ order: ProtocolData,
189
+ apiOptions: OrderAPIOptions,
190
+ ): Promise<OrderV2> {
191
+ const { protocol = "seaport", side, protocolAddress } = apiOptions
192
+
193
+ // Validate required fields
194
+ if (!side) {
195
+ throw new Error("apiOptions.side is required")
196
+ }
197
+ if (!protocolAddress) {
198
+ throw new Error("apiOptions.protocolAddress is required")
199
+ }
200
+ if (!order) {
201
+ throw new Error("order data is required")
202
+ }
203
+
204
+ // Validate protocol value
205
+ if (protocol !== "seaport") {
206
+ throw new Error("Currently only 'seaport' protocol is supported")
207
+ }
208
+
209
+ // Validate side value
210
+ if (side !== "ask" && side !== "bid") {
211
+ throw new Error("side must be either 'ask' or 'bid'")
212
+ }
213
+
214
+ // Validate protocolAddress format
215
+ if (!/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
216
+ throw new Error("Invalid protocol address format")
217
+ }
218
+
219
+ const response = await this.fetcher.post<OrdersPostQueryResponse>(
220
+ getOrdersAPIPath(this.chain, protocol, side),
221
+ { ...order, protocol_address: protocolAddress },
222
+ )
223
+ return deserializeOrder(response.order)
224
+ }
225
+
226
+ /**
227
+ * Post a listing to OpenSea. Returns the new Listing response format.
228
+ */
229
+ async postListing(
230
+ order: ProtocolData,
231
+ protocolAddress: string,
232
+ ): Promise<Listing> {
233
+ if (!order) {
234
+ throw new Error("order data is required")
235
+ }
236
+ if (!protocolAddress || !/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
237
+ throw new Error("Invalid protocol address format")
238
+ }
239
+
240
+ const response = await this.fetcher.post<ListingPostQueryResponse>(
241
+ getOrdersAPIPath(this.chain, "seaport", OrderSide.LISTING),
242
+ { ...order, protocol_address: protocolAddress },
243
+ )
244
+ return response.listing
245
+ }
246
+
247
+ /**
248
+ * Post an offer to OpenSea. Returns the new Offer response format.
249
+ */
250
+ async postOffer(
251
+ order: ProtocolData,
252
+ protocolAddress: string,
253
+ ): Promise<Offer> {
254
+ if (!order) {
255
+ throw new Error("order data is required")
256
+ }
257
+ if (!protocolAddress || !/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
258
+ throw new Error("Invalid protocol address format")
259
+ }
260
+
261
+ const response = await this.fetcher.post<OfferPostQueryResponse>(
262
+ getOrdersAPIPath(this.chain, "seaport", OrderSide.OFFER),
263
+ { ...order, protocol_address: protocolAddress },
264
+ )
265
+ return response.offer
266
+ }
267
+
268
+ /**
269
+ * Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
270
+ */
271
+ async offchainCancelOrder(
272
+ protocolAddress: string,
273
+ orderHash: string,
274
+ chain: Chain = this.chain,
275
+ offererSignature?: string,
276
+ ): Promise<CancelOrderResponse> {
277
+ const response = await this.fetcher.post<CancelOrderResponse>(
278
+ getCancelOrderPath(chain, protocolAddress, orderHash),
279
+ { offererSignature },
280
+ )
281
+ return response
282
+ }
283
+ }
@@ -0,0 +1,21 @@
1
+ import { getSearchPath } from "./apiPaths"
2
+ import type { Fetcher } from "./fetcher"
3
+ import type { SearchArgs, SearchResponse } from "./types"
4
+
5
+ /**
6
+ * Search-related API operations
7
+ */
8
+ export class SearchAPI {
9
+ constructor(private fetcher: Fetcher) {}
10
+
11
+ /**
12
+ * Search across collections, tokens, NFTs, and accounts.
13
+ */
14
+ async search(args: SearchArgs): Promise<SearchResponse> {
15
+ const response = await this.fetcher.get<SearchResponse>(
16
+ getSearchPath(),
17
+ args,
18
+ )
19
+ return response
20
+ }
21
+ }