@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
package/src/sdk.ts ADDED
@@ -0,0 +1,1051 @@
1
+ import EventEmitter = require("node:events")
2
+
3
+ import { Seaport } from "@opensea/seaport-js"
4
+ import type { OrderComponents } from "@opensea/seaport-js/lib/types"
5
+ import {
6
+ type BigNumberish,
7
+ ethers,
8
+ type JsonRpcProvider,
9
+ type Overrides,
10
+ type Signer,
11
+ } from "ethers"
12
+ import { OpenSeaAPI } from "./api/api"
13
+ import type { CollectionOffer, Listing, Offer, Order } from "./api/types"
14
+ import type { OrderV2 } from "./orders/types"
15
+ import { AssetsManager } from "./sdk/assets"
16
+ import { CancellationManager } from "./sdk/cancellation"
17
+ import { FulfillmentManager } from "./sdk/fulfillment"
18
+ import { type BulkOrderResult, OrdersManager } from "./sdk/orders"
19
+ import { TokensManager } from "./sdk/tokens"
20
+ import {
21
+ type AssetWithTokenId,
22
+ type AssetWithTokenStandard,
23
+ Chain,
24
+ type EventData,
25
+ EventType,
26
+ type OpenSeaAPIConfig,
27
+ OrderSide,
28
+ } from "./types"
29
+ import {
30
+ getDefaultConduit,
31
+ getListingPaymentToken,
32
+ getOfferPaymentToken,
33
+ getSeaportAddress,
34
+ } from "./utils/utils"
35
+
36
+ /**
37
+ * The OpenSea SDK main class.
38
+ * @category Main Classes
39
+ */
40
+ export class OpenSeaSDK {
41
+ /** Provider to use for transactions. */
42
+ public provider: JsonRpcProvider
43
+ /** Seaport client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
44
+ public seaport: Seaport
45
+ /** Logger function to use when debugging */
46
+ public logger: (arg: string) => void
47
+ /** API instance */
48
+ public readonly api: OpenSeaAPI
49
+ /** The configured chain */
50
+ public readonly chain: Chain
51
+ /** Internal cache of decimals for payment tokens to save network requests */
52
+ private _cachedPaymentTokenDecimals: { [address: string]: number } = {}
53
+
54
+ private _emitter: EventEmitter
55
+ private _signerOrProvider: Signer | JsonRpcProvider
56
+
57
+ // Manager instances
58
+ private _tokensManager: TokensManager
59
+ private _assetsManager: AssetsManager
60
+ private _cancellationManager: CancellationManager
61
+ private _ordersManager: OrdersManager
62
+ private _fulfillmentManager: FulfillmentManager
63
+
64
+ /**
65
+ * Create a new instance of OpenSeaSDK.
66
+ * @param signerOrProvider Signer or provider to use for transactions. For example:
67
+ * `new ethers.providers.JsonRpcProvider('https://mainnet.infura.io')` or
68
+ * `new ethers.Wallet(privKey, provider)`
69
+ * @param apiConfig configuration options, including `chain`
70
+ * @param logger optional function for logging debug strings. defaults to no logging
71
+ */
72
+ constructor(
73
+ signerOrProvider: Signer | JsonRpcProvider,
74
+ apiConfig: OpenSeaAPIConfig = {},
75
+ logger?: (arg: string) => void,
76
+ ) {
77
+ // API config
78
+ apiConfig.chain ??= Chain.Mainnet
79
+ this.chain = apiConfig.chain
80
+ this.api = new OpenSeaAPI(apiConfig)
81
+
82
+ this.provider = ((signerOrProvider as Signer).provider ??
83
+ signerOrProvider) as JsonRpcProvider
84
+ this._signerOrProvider = signerOrProvider ?? this.provider
85
+
86
+ const defaultConduit = getDefaultConduit(this.chain)
87
+ const seaportAddress = getSeaportAddress(this.chain)
88
+ this.seaport = new Seaport(this._signerOrProvider, {
89
+ conduitKeyToConduit: {
90
+ [defaultConduit.key]: defaultConduit.address,
91
+ },
92
+ overrides: {
93
+ defaultConduitKey: defaultConduit.key,
94
+ contractAddress: seaportAddress,
95
+ },
96
+ })
97
+
98
+ // Emit events
99
+ this._emitter = new EventEmitter()
100
+
101
+ // Logger: default to no logging if fn not provided
102
+ this.logger = logger ?? ((arg: string) => arg)
103
+
104
+ // Cache decimals for offer and listing payment tokens to skip network request
105
+ const offerPaymentToken = getOfferPaymentToken(this.chain).toLowerCase()
106
+ const listingPaymentToken = getListingPaymentToken(this.chain).toLowerCase()
107
+ this._cachedPaymentTokenDecimals[offerPaymentToken] = 18
108
+ this._cachedPaymentTokenDecimals[listingPaymentToken] = 18
109
+
110
+ // Create shared context for all managers
111
+ const context = {
112
+ chain: this.chain,
113
+ signerOrProvider: this._signerOrProvider,
114
+ provider: this.provider,
115
+ api: this.api,
116
+ seaport: this.seaport,
117
+ logger: this.logger,
118
+ dispatch: this._dispatch.bind(this),
119
+ confirmTransaction: this._confirmTransaction.bind(this),
120
+ requireAccountIsAvailable: this._requireAccountIsAvailable.bind(this),
121
+ }
122
+
123
+ // Initialize manager instances
124
+ this._tokensManager = new TokensManager(context)
125
+ this._assetsManager = new AssetsManager(context)
126
+ this._cancellationManager = new CancellationManager(context)
127
+ this._ordersManager = new OrdersManager(
128
+ context,
129
+ this._getPriceParameters.bind(this),
130
+ )
131
+ this._fulfillmentManager = new FulfillmentManager(
132
+ context,
133
+ this._ordersManager,
134
+ )
135
+ }
136
+
137
+ /**
138
+ * Add a listener for events emitted by the SDK.
139
+ * @param event The {@link EventType} to listen to.
140
+ * @param listener A callback that will accept an object with {@link EventData}\
141
+ * @param once Whether the listener should only be called once, or continue listening until removed.
142
+ */
143
+ public addListener(
144
+ event: EventType,
145
+ listener: (data: EventData) => void,
146
+ once = false,
147
+ ) {
148
+ if (once) {
149
+ this._emitter.once(event, listener)
150
+ } else {
151
+ this._emitter.addListener(event, listener)
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Remove an event listener by calling `.removeListener()` on an event and listener.
157
+ * @param event The {@link EventType} to remove a listener for\
158
+ * @param listener The listener to remove
159
+ */
160
+ public removeListener(event: EventType, listener: (data: EventData) => void) {
161
+ this._emitter.removeListener(event, listener)
162
+ }
163
+
164
+ /**
165
+ * Remove all event listeners. This should be called when you're unmounting
166
+ * a component that listens to events to make UI updates.
167
+ * @param event Optional EventType to remove listeners for
168
+ */
169
+ public removeAllListeners(event?: EventType) {
170
+ this._emitter.removeAllListeners(event)
171
+ }
172
+
173
+ /**
174
+ * Wrap native asset into wrapped native asset (e.g. ETH into WETH, POL into WPOL).
175
+ * Wrapped native assets are needed for making offers.
176
+ * @param options
177
+ * @param options.amountInEth Amount of native asset to wrap
178
+ * @param options.accountAddress Address of the user's wallet containing the native asset
179
+ */
180
+ public async wrapEth({
181
+ amountInEth,
182
+ accountAddress,
183
+ }: {
184
+ amountInEth: BigNumberish
185
+ accountAddress: string
186
+ }) {
187
+ return this._tokensManager.wrapEth({ amountInEth, accountAddress })
188
+ }
189
+
190
+ /**
191
+ * Unwrap wrapped native asset into native asset (e.g. WETH into ETH, WPOL into POL).
192
+ * Emits the `UnwrapWeth` event when the transaction is prompted.
193
+ * @param options
194
+ * @param options.amountInEth How much wrapped native asset to unwrap
195
+ * @param options.accountAddress Address of the user's wallet containing the wrapped native asset
196
+ */
197
+ public async unwrapWeth({
198
+ amountInEth,
199
+ accountAddress,
200
+ }: {
201
+ amountInEth: BigNumberish
202
+ accountAddress: string
203
+ }) {
204
+ return this._tokensManager.unwrapWeth({ amountInEth, accountAddress })
205
+ }
206
+
207
+ /**
208
+ * Create and submit an offer on an asset.
209
+ * @param options
210
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
211
+ * @param options.accountAddress Address of the wallet making the offer.
212
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
213
+ * @param options.quantity Number of assets to bid for. Defaults to 1.
214
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
215
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
216
+ * @param options.expirationTime Expiration time for the order, in UTC seconds
217
+ * @param options.zone Zone for order protection. Defaults to chain's signed zone.
218
+ *
219
+ * @returns The {@link OrderV2} that was created.
220
+ *
221
+ * @throws Error if the asset does not contain a token id.
222
+ * @throws Error if the accountAddress is not available through wallet or provider.
223
+ * @throws Error if the amount is not greater than 0.
224
+ */
225
+ public async createOffer({
226
+ asset,
227
+ accountAddress,
228
+ amount,
229
+ quantity = 1,
230
+ domain,
231
+ salt,
232
+ expirationTime,
233
+ zone,
234
+ }: {
235
+ asset: AssetWithTokenId
236
+ accountAddress: string
237
+ amount: BigNumberish
238
+ quantity?: BigNumberish
239
+ domain?: string
240
+ salt?: BigNumberish
241
+ expirationTime?: BigNumberish
242
+ zone?: string
243
+ }): Promise<OrderV2> {
244
+ return this._ordersManager.createOffer({
245
+ asset,
246
+ accountAddress,
247
+ amount,
248
+ quantity,
249
+ domain,
250
+ salt,
251
+ expirationTime,
252
+ zone,
253
+ })
254
+ }
255
+
256
+ /**
257
+ * Create and submit a listing for an asset.
258
+ * @param options
259
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
260
+ * @param options.accountAddress Address of the wallet making the listing
261
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
262
+ * @param options.quantity Number of assets to list. Defaults to 1.
263
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
264
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
265
+ * @param options.listingTime Optional time when the order will become fulfillable, in UTC seconds. Undefined means it will start now.
266
+ * @param options.expirationTime Expiration time for the order, in UTC seconds.
267
+ * @param options.buyerAddress Optional address that's allowed to purchase this item. If specified, no other address will be able to take the order, unless its value is the null address.
268
+ * @param options.includeOptionalCreatorFees If true, optional creator fees will be included in the listing. Default: false.
269
+ * @param options.zone Zone for order protection. Defaults to no zone.
270
+ * @returns The {@link OrderV2} that was created.
271
+ *
272
+ * @throws Error if the asset does not contain a token id.
273
+ * @throws Error if the accountAddress is not available through wallet or provider.
274
+ * @throws Error if the amount is not greater than 0.
275
+ */
276
+ public async createListing({
277
+ asset,
278
+ accountAddress,
279
+ amount,
280
+ quantity = 1,
281
+ domain,
282
+ salt,
283
+ listingTime,
284
+ expirationTime,
285
+ buyerAddress,
286
+ includeOptionalCreatorFees = false,
287
+ zone,
288
+ }: {
289
+ asset: AssetWithTokenId
290
+ accountAddress: string
291
+ amount: BigNumberish
292
+ quantity?: BigNumberish
293
+ domain?: string
294
+ salt?: BigNumberish
295
+ listingTime?: number
296
+ expirationTime?: number
297
+ buyerAddress?: string
298
+ includeOptionalCreatorFees?: boolean
299
+ zone?: string
300
+ }): Promise<OrderV2> {
301
+ return this._ordersManager.createListing({
302
+ asset,
303
+ accountAddress,
304
+ amount,
305
+ quantity,
306
+ domain,
307
+ salt,
308
+ listingTime,
309
+ expirationTime,
310
+ buyerAddress,
311
+ includeOptionalCreatorFees,
312
+ zone,
313
+ })
314
+ }
315
+
316
+ /**
317
+ * Create and submit multiple listings using Seaport's bulk order creation.
318
+ * This method uses a single signature for all listings and submits them individually to the OpenSea API with rate limit handling.
319
+ * All listings must be from the same account address.
320
+ *
321
+ * Note: If only one listing is provided, this method will use a normal order signature instead of a bulk signature,
322
+ * as bulk signatures are more expensive to decode onchain due to the merkle proof verification.
323
+ *
324
+ * @param options
325
+ * @param options.listings Array of listing parameters. Each listing requires asset, amount, and optionally other listing parameters.
326
+ * @param options.accountAddress Address of the wallet making the listings
327
+ * @param options.continueOnError If true, continue submitting remaining listings even if some fail. Default: false (throw on first error).
328
+ * @param options.onProgress Optional callback for progress updates. Called after each listing is submitted (successfully or not).
329
+ * @returns {@link BulkOrderResult} containing successful orders and any failures.
330
+ *
331
+ * @throws Error if listings array is empty
332
+ * @throws Error if the accountAddress is not available through wallet or provider.
333
+ * @throws Error if any asset does not contain a token id.
334
+ * @throws Error if continueOnError is false and any submission fails.
335
+ */
336
+ public async createBulkListings({
337
+ listings,
338
+ accountAddress,
339
+ continueOnError,
340
+ onProgress,
341
+ }: {
342
+ listings: Array<{
343
+ asset: AssetWithTokenId
344
+ amount: BigNumberish
345
+ quantity?: BigNumberish
346
+ domain?: string
347
+ salt?: BigNumberish
348
+ listingTime?: number
349
+ expirationTime?: number
350
+ buyerAddress?: string
351
+ includeOptionalCreatorFees?: boolean
352
+ zone?: string
353
+ }>
354
+ accountAddress: string
355
+ continueOnError?: boolean
356
+ onProgress?: (completed: number, total: number) => void
357
+ }): Promise<BulkOrderResult> {
358
+ return this._ordersManager.createBulkListings({
359
+ listings,
360
+ accountAddress,
361
+ continueOnError,
362
+ onProgress,
363
+ })
364
+ }
365
+
366
+ /**
367
+ * Create and submit multiple offers using Seaport's bulk order creation.
368
+ * This method uses a single signature for all offers and submits them individually to the OpenSea API with rate limit handling.
369
+ * All offers must be from the same account address.
370
+ *
371
+ * Note: If only one offer is provided, this method will use a normal order signature instead of a bulk signature,
372
+ * as bulk signatures are more expensive to decode onchain due to the merkle proof verification.
373
+ *
374
+ * @param options
375
+ * @param options.offers Array of offer parameters. Each offer requires asset, amount, and optionally other offer parameters.
376
+ * @param options.accountAddress Address of the wallet making the offers
377
+ * @param options.continueOnError If true, continue submitting remaining offers even if some fail. Default: false (throw on first error).
378
+ * @param options.onProgress Optional callback for progress updates. Called after each offer is submitted (successfully or not).
379
+ * @returns {@link BulkOrderResult} containing successful orders and any failures.
380
+ *
381
+ * @throws Error if offers array is empty
382
+ * @throws Error if the accountAddress is not available through wallet or provider.
383
+ * @throws Error if any asset does not contain a token id.
384
+ * @throws Error if continueOnError is false and any submission fails.
385
+ */
386
+ public async createBulkOffers({
387
+ offers,
388
+ accountAddress,
389
+ continueOnError,
390
+ onProgress,
391
+ }: {
392
+ offers: Array<{
393
+ asset: AssetWithTokenId
394
+ amount: BigNumberish
395
+ quantity?: BigNumberish
396
+ domain?: string
397
+ salt?: BigNumberish
398
+ expirationTime?: BigNumberish
399
+ zone?: string
400
+ }>
401
+ accountAddress: string
402
+ continueOnError?: boolean
403
+ onProgress?: (completed: number, total: number) => void
404
+ }): Promise<BulkOrderResult> {
405
+ return this._ordersManager.createBulkOffers({
406
+ offers,
407
+ accountAddress,
408
+ continueOnError,
409
+ onProgress,
410
+ })
411
+ }
412
+
413
+ /**
414
+ * Create and submit a collection offer.
415
+ * @param options
416
+ * @param options.collectionSlug Identifier for the collection.
417
+ * @param options.accountAddress Address of the wallet making the offer.
418
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
419
+ * @param options.quantity Number of assets to bid for.
420
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
421
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
422
+ * @param options.expirationTime Expiration time (UTC seconds).
423
+ * @param options.offerProtectionEnabled Use signed zone for protection against disabled items. Default: true.
424
+ * @param options.traitType If defined, the trait name to create the collection offer for.
425
+ * @param options.traitValue If defined, the trait value to create the collection offer for.
426
+ * @param options.traits If defined, an array of traits to create the multi-trait collection offer for.
427
+ * @param options.numericTraits If defined, an array of numeric trait criteria with min/max ranges.
428
+ * @returns The {@link CollectionOffer} that was created.
429
+ */
430
+ public async createCollectionOffer({
431
+ collectionSlug,
432
+ accountAddress,
433
+ amount,
434
+ quantity,
435
+ domain,
436
+ salt,
437
+ expirationTime,
438
+ offerProtectionEnabled = true,
439
+ traitType,
440
+ traitValue,
441
+ traits,
442
+ numericTraits,
443
+ }: {
444
+ collectionSlug: string
445
+ accountAddress: string
446
+ amount: BigNumberish
447
+ quantity: number
448
+ domain?: string
449
+ salt?: BigNumberish
450
+ expirationTime?: number | string
451
+ offerProtectionEnabled?: boolean
452
+ traitType?: string
453
+ traitValue?: string
454
+ traits?: Array<{ type: string; value: string }>
455
+ numericTraits?: Array<{ type: string; min?: number; max?: number }>
456
+ }): Promise<CollectionOffer | null> {
457
+ return this._ordersManager.createCollectionOffer({
458
+ collectionSlug,
459
+ accountAddress,
460
+ amount,
461
+ quantity,
462
+ domain,
463
+ salt,
464
+ expirationTime,
465
+ offerProtectionEnabled,
466
+ traitType,
467
+ traitValue,
468
+ traits,
469
+ numericTraits,
470
+ })
471
+ }
472
+
473
+ /**
474
+ * Fulfill an order for an asset. The order can be either a listing or an offer.
475
+ * Uses the OpenSea API to generate fulfillment transaction data and executes it directly.
476
+ * @param options
477
+ * @param options.order The order to fulfill, a.k.a. "take"
478
+ * @param options.accountAddress Address of the wallet taking the offer.
479
+ * @param options.assetContractAddress Optional address of the NFT contract for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
480
+ * @param options.tokenId Optional token ID for criteria offers (e.g., collection offers). Required when fulfilling collection offers.
481
+ * @param options.unitsToFill Optional number of units to fill. Defaults to 1 for both listings and offers.
482
+ * @param options.recipientAddress Optional recipient address for the NFT when fulfilling a listing. Not applicable for offers.
483
+ * @param options.includeOptionalCreatorFees Whether to include optional creator fees in the fulfillment. If creator fees are already required, this is a no-op. Defaults to false.
484
+ * @param options.overrides Transaction overrides, ignored if not set.
485
+ * @returns Transaction hash of the order.
486
+ *
487
+ * @throws Error if the accountAddress is not available through wallet or provider.
488
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
489
+ * @throws Error if a signer is not provided (read-only providers cannot fulfill orders).
490
+ * @throws Error if the order hash is not available.
491
+ */
492
+ public async fulfillOrder({
493
+ order,
494
+ accountAddress,
495
+ assetContractAddress,
496
+ tokenId,
497
+ unitsToFill,
498
+ recipientAddress,
499
+ includeOptionalCreatorFees = false,
500
+ overrides,
501
+ }: {
502
+ order: OrderV2 | Order | Listing | Offer
503
+ accountAddress: string
504
+ assetContractAddress?: string
505
+ tokenId?: string
506
+ unitsToFill?: BigNumberish
507
+ recipientAddress?: string
508
+ includeOptionalCreatorFees?: boolean
509
+ overrides?: Overrides
510
+ }): Promise<string> {
511
+ return this._fulfillmentManager.fulfillOrder({
512
+ order,
513
+ accountAddress,
514
+ assetContractAddress,
515
+ tokenId,
516
+ unitsToFill,
517
+ recipientAddress,
518
+ includeOptionalCreatorFees,
519
+ overrides,
520
+ })
521
+ }
522
+
523
+ /**
524
+ * Cancel multiple orders onchain, preventing them from being fulfilled.
525
+ * This method accepts either full OrderV2 objects, OrderComponents, or order hashes with protocol address.
526
+ *
527
+ * **Event Behavior**: For backwards compatibility with the singular `cancelOrder` method,
528
+ * this method dispatches a `CancelOrder` event for the first order only, and only when
529
+ * an OrderV2 object is available (either provided directly or fetched via orderHashes).
530
+ * No event is dispatched when using OrderComponents directly, as they lack the full order data.
531
+ *
532
+ * @param options
533
+ * @param options.orders Array of orders to cancel. Can be OrderV2 objects or OrderComponents.
534
+ * @param options.orderHashes Optional array of order hashes to cancel. Must provide protocolAddress if using this.
535
+ * @param options.accountAddress The account address cancelling the orders.
536
+ * @param options.protocolAddress Required when using orderHashes. The Seaport protocol address for the orders.
537
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in calldata.
538
+ * @param options.overrides Transaction overrides, ignored if not set.
539
+ * @returns Transaction hash of the cancellation.
540
+ *
541
+ * @throws Error if orderHashes is provided without protocolAddress.
542
+ * @throws Error if neither orders nor orderHashes is provided.
543
+ * @throws Error if the accountAddress is not available through wallet or provider.
544
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
545
+ */
546
+ public async cancelOrders({
547
+ orders,
548
+ orderHashes,
549
+ accountAddress,
550
+ protocolAddress,
551
+ domain,
552
+ overrides,
553
+ }: {
554
+ orders?: Array<OrderV2 | OrderComponents>
555
+ orderHashes?: string[]
556
+ accountAddress: string
557
+ protocolAddress?: string
558
+ domain?: string
559
+ overrides?: Overrides
560
+ }): Promise<string> {
561
+ return this._cancellationManager.cancelOrders({
562
+ orders,
563
+ orderHashes,
564
+ accountAddress,
565
+ protocolAddress,
566
+ domain,
567
+ overrides,
568
+ })
569
+ }
570
+
571
+ /**
572
+ * Cancel an order onchain, preventing it from ever being fulfilled.
573
+ * This method accepts either a full OrderV2 object or an order hash with protocol address.
574
+ *
575
+ * @param options
576
+ * @param options.order The order to cancel (OrderV2 object)
577
+ * @param options.orderHash Optional order hash to cancel. Must provide protocolAddress if using this.
578
+ * @param options.accountAddress The account address that will be cancelling the order.
579
+ * @param options.protocolAddress Required when using orderHash. The Seaport protocol address for the order.
580
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in calldata.
581
+ *
582
+ * @throws Error if neither order nor orderHash is provided.
583
+ * @throws Error if the accountAddress is not available through wallet or provider.
584
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
585
+ *
586
+ * @example
587
+ * // Cancel using OrderV2 object
588
+ * await sdk.cancelOrder({
589
+ * order: orderV2Object,
590
+ * accountAddress: "0x..."
591
+ * });
592
+ *
593
+ * @example
594
+ * // Cancel using order hash
595
+ * await sdk.cancelOrder({
596
+ * orderHash: "0x123...",
597
+ * protocolAddress: "0xabc...",
598
+ * accountAddress: "0x..."
599
+ * });
600
+ */
601
+ public async cancelOrder({
602
+ order,
603
+ orderHash,
604
+ accountAddress,
605
+ protocolAddress,
606
+ domain,
607
+ }: {
608
+ order?: OrderV2
609
+ orderHash?: string
610
+ accountAddress: string
611
+ protocolAddress?: string
612
+ domain?: string
613
+ }) {
614
+ return this._cancellationManager.cancelOrder({
615
+ order,
616
+ orderHash,
617
+ accountAddress,
618
+ protocolAddress,
619
+ domain,
620
+ })
621
+ }
622
+
623
+ /**
624
+ * Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
625
+ * Protocol and Chain are required to prevent hash collisions.
626
+ * Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
627
+ * @param protocolAddress The Seaport address for the order.
628
+ * @param orderHash The order hash, or external identifier, of the order.
629
+ * @param chain The chain where the order is located.
630
+ * @param offererSignature An EIP-712 signature from the offerer of the order.
631
+ * If this is not provided, the API key used to initialize the SDK must belong to the order's offerer.
632
+ * The signature must be a EIP-712 signature consisting of the order's Seaport contract's
633
+ * name, version, address, and chain. The struct to sign is `OrderHash` containing a
634
+ * single bytes32 field.
635
+ * @param useSignerToDeriveOffererSignature Derive the offererSignature from the Ethers signer passed into this sdk.
636
+ * @returns The response from the API.
637
+ */
638
+ public async offchainCancelOrder(
639
+ protocolAddress: string,
640
+ orderHash: string,
641
+ chain: Chain = this.chain,
642
+ offererSignature?: string,
643
+ useSignerToDeriveOffererSignature?: boolean,
644
+ ) {
645
+ return this._cancellationManager.offchainCancelOrder(
646
+ protocolAddress,
647
+ orderHash,
648
+ chain,
649
+ offererSignature,
650
+ useSignerToDeriveOffererSignature,
651
+ )
652
+ }
653
+
654
+ /**
655
+ * Returns whether an order is fulfillable.
656
+ * An order may not be fulfillable if a target item's transfer function
657
+ * is locked for some reason, e.g. an item is being rented within a game
658
+ * or trading has been locked for an item type.
659
+ * @param options
660
+ * @param options.order Order to check
661
+ * @param options.accountAddress The account address that will be fulfilling the order
662
+ * @returns True if the order is fulfillable, else False.
663
+ *
664
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
665
+ */
666
+ public async isOrderFulfillable({
667
+ order,
668
+ accountAddress,
669
+ }: {
670
+ order: OrderV2
671
+ accountAddress: string
672
+ }): Promise<boolean> {
673
+ return this._fulfillmentManager.isOrderFulfillable({
674
+ order,
675
+ accountAddress,
676
+ })
677
+ }
678
+
679
+ /**
680
+ * Get an account's balance of any Asset. This asset can be an ERC20, ERC1155, or ERC721.
681
+ * @param options
682
+ * @param options.accountAddress Account address to check
683
+ * @param options.asset The Asset to check balance for. tokenStandard must be set.
684
+ * @returns The balance of the asset for the account.
685
+ *
686
+ * @throws Error if the token standard does not support balanceOf.
687
+ */
688
+ public async getBalance({
689
+ accountAddress,
690
+ asset,
691
+ }: {
692
+ accountAddress: string
693
+ asset: AssetWithTokenStandard
694
+ }): Promise<bigint> {
695
+ return this._assetsManager.getBalance({ accountAddress, asset })
696
+ }
697
+
698
+ /**
699
+ * Transfer an asset. This asset can be an ERC20, ERC1155, or ERC721.
700
+ * @param options
701
+ * @param options.asset The Asset to transfer. tokenStandard must be set.
702
+ * @param options.amount Amount of asset to transfer. Not used for ERC721.
703
+ * @param options.fromAddress The address to transfer from
704
+ * @param options.toAddress The address to transfer to
705
+ * @param options.overrides Transaction overrides, ignored if not set.
706
+ */
707
+ public async transfer({
708
+ asset,
709
+ amount,
710
+ fromAddress,
711
+ toAddress,
712
+ overrides,
713
+ }: {
714
+ asset: AssetWithTokenStandard
715
+ amount?: BigNumberish
716
+ fromAddress: string
717
+ toAddress: string
718
+ overrides?: Overrides
719
+ }): Promise<void> {
720
+ return this._assetsManager.transfer({
721
+ asset,
722
+ amount,
723
+ fromAddress,
724
+ toAddress,
725
+ overrides,
726
+ })
727
+ }
728
+
729
+ /**
730
+ * Bulk transfer multiple assets using OpenSea's TransferHelper contract.
731
+ * This method is more gas-efficient than calling transfer() multiple times.
732
+ * Note: All assets must be approved for transfer to the OpenSea conduit before calling this method.
733
+ * @param options
734
+ * @param options.assets Array of assets to transfer. Each asset must have tokenStandard set.
735
+ * @param options.fromAddress The address to transfer from
736
+ * @param options.overrides Transaction overrides, ignored if not set.
737
+ * @returns Transaction hash of the bulk transfer
738
+ *
739
+ * @throws Error if any asset is missing required fields (tokenId for NFTs, amount for ERC20/ERC1155).
740
+ * @throws Error if any asset is not approved for transfer to the OpenSea conduit.
741
+ * @throws Error if the fromAddress is not available through wallet or provider.
742
+ */
743
+ public async bulkTransfer({
744
+ assets,
745
+ fromAddress,
746
+ overrides,
747
+ }: {
748
+ assets: Array<{
749
+ asset: AssetWithTokenStandard
750
+ toAddress: string
751
+ amount?: BigNumberish
752
+ }>
753
+ fromAddress: string
754
+ overrides?: Overrides
755
+ }): Promise<string> {
756
+ return this._assetsManager.bulkTransfer({
757
+ assets,
758
+ fromAddress,
759
+ overrides,
760
+ })
761
+ }
762
+
763
+ /**
764
+ * Batch approve multiple assets for transfer to the OpenSea conduit.
765
+ * This method checks which assets need approval and batches them efficiently:
766
+ * - 0 approvals needed: Returns early
767
+ * - 1 approval needed: Sends single transaction
768
+ * - 2+ approvals needed: Uses Multicall3 to batch all approvals in one transaction
769
+ *
770
+ * @param options
771
+ * @param options.assets Array of assets to approve for transfer
772
+ * @param options.fromAddress The address that owns the assets
773
+ * @param options.overrides Transaction overrides, ignored if not set.
774
+ * @returns Transaction hash of the approval transaction, or undefined if no approvals needed
775
+ *
776
+ * @throws Error if the fromAddress is not available through wallet or provider.
777
+ */
778
+ public async batchApproveAssets({
779
+ assets,
780
+ fromAddress,
781
+ overrides,
782
+ }: {
783
+ assets: Array<{
784
+ asset: AssetWithTokenStandard
785
+ amount?: BigNumberish
786
+ }>
787
+ fromAddress: string
788
+ overrides?: Overrides
789
+ }): Promise<string | undefined> {
790
+ return this._assetsManager.batchApproveAssets({
791
+ assets,
792
+ fromAddress,
793
+ overrides,
794
+ })
795
+ }
796
+
797
+ /**
798
+ * Instead of signing an off-chain order, this method allows you to approve an order
799
+ * with an onchain transaction.
800
+ * @param order Order to approve
801
+ * @param domain An optional domain to be hashed and included at the end of fulfillment calldata. This can be used for onchain order attribution to assist with analytics.
802
+ * @returns Transaction hash of the approval transaction
803
+ *
804
+ * @throws Error if the accountAddress is not available through wallet or provider.
805
+ * @throws Error if the order's protocol address is not supported by OpenSea. See {@link isValidProtocol}.
806
+ */
807
+ public async approveOrder(order: OrderV2, domain?: string) {
808
+ return this._fulfillmentManager.approveOrder(order, domain)
809
+ }
810
+
811
+ /**
812
+ * Validates an order onchain using Seaport's validate() method. This submits the order onchain
813
+ * and pre-validates the order using Seaport, which makes it cheaper to fulfill since a signature
814
+ * is not needed to be verified during fulfillment for the order, but is not strictly required
815
+ * and the alternative is orders can be submitted to the API for free instead of sent onchain.
816
+ * @param orderComponents Order components to validate onchain
817
+ * @param accountAddress Address of the wallet that will pay the gas to validate the order
818
+ * @returns Transaction hash of the validation transaction
819
+ *
820
+ * @throws Error if the accountAddress is not available through wallet or provider.
821
+ */
822
+ public async validateOrderOnchain(
823
+ orderComponents: OrderComponents,
824
+ accountAddress: string,
825
+ ) {
826
+ return this._fulfillmentManager.validateOrderOnchain(
827
+ orderComponents,
828
+ accountAddress,
829
+ )
830
+ }
831
+
832
+ /**
833
+ * Create and validate a listing onchain. Combines order building with onchain validation.
834
+ * Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
835
+ * @param options
836
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
837
+ * @param options.accountAddress Address of the wallet making the listing
838
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
839
+ * @param options.quantity Number of assets to list. Defaults to 1.
840
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
841
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
842
+ * @param options.listingTime When order becomes fulfillable (UTC seconds). Defaults to now.
843
+ * @param options.expirationTime Expiration time (UTC seconds).
844
+ * @param options.buyerAddress Optional buyer restriction. Only this address can purchase.
845
+ * @param options.includeOptionalCreatorFees Include optional creator fees. Default: false.
846
+ * @param options.zone Zone for order protection. Defaults to no zone.
847
+ * @returns Transaction hash
848
+ *
849
+ * @throws Error if asset missing token id or accountAddress unavailable.
850
+ */
851
+ public async createListingAndValidateOnchain({
852
+ asset,
853
+ accountAddress,
854
+ amount,
855
+ quantity = 1,
856
+ domain,
857
+ salt,
858
+ listingTime,
859
+ expirationTime,
860
+ buyerAddress,
861
+ includeOptionalCreatorFees = false,
862
+ zone,
863
+ }: {
864
+ asset: AssetWithTokenId
865
+ accountAddress: string
866
+ amount: BigNumberish
867
+ quantity?: BigNumberish
868
+ domain?: string
869
+ salt?: BigNumberish
870
+ listingTime?: number
871
+ expirationTime?: number
872
+ buyerAddress?: string
873
+ includeOptionalCreatorFees?: boolean
874
+ zone?: string
875
+ }): Promise<string> {
876
+ return this._fulfillmentManager.createListingAndValidateOnchain({
877
+ asset,
878
+ accountAddress,
879
+ amount,
880
+ quantity,
881
+ domain,
882
+ salt,
883
+ listingTime,
884
+ expirationTime,
885
+ buyerAddress,
886
+ includeOptionalCreatorFees,
887
+ zone,
888
+ })
889
+ }
890
+
891
+ /**
892
+ * Create and validate an offer onchain. Combines order building with onchain validation.
893
+ * Validation costs gas upfront but makes fulfillment cheaper (no signature verification needed).
894
+ * @param options
895
+ * @param options.asset The asset to trade. tokenAddress and tokenId must be defined.
896
+ * @param options.accountAddress Address of the wallet making the offer.
897
+ * @param options.amount Amount in decimal format (e.g., "1.5" for 1.5 ETH, not wei). Automatically converted to base units.
898
+ * @param options.quantity Number of assets to bid for. Defaults to 1.
899
+ * @param options.domain Optional domain for onchain attribution. Hashed and included in salt.
900
+ * @param options.salt Arbitrary salt. Auto-generated if not provided.
901
+ * @param options.expirationTime Expiration time (UTC seconds).
902
+ * @param options.zone Zone for order protection. Defaults to chain's signed zone.
903
+ * @returns Transaction hash
904
+ *
905
+ * @throws Error if asset missing token id or accountAddress unavailable.
906
+ */
907
+ public async createOfferAndValidateOnchain({
908
+ asset,
909
+ accountAddress,
910
+ amount,
911
+ quantity = 1,
912
+ domain,
913
+ salt,
914
+ expirationTime,
915
+ zone,
916
+ }: {
917
+ asset: AssetWithTokenId
918
+ accountAddress: string
919
+ amount: BigNumberish
920
+ quantity?: BigNumberish
921
+ domain?: string
922
+ salt?: BigNumberish
923
+ expirationTime?: BigNumberish
924
+ zone?: string
925
+ }): Promise<string> {
926
+ return this._fulfillmentManager.createOfferAndValidateOnchain({
927
+ asset,
928
+ accountAddress,
929
+ amount,
930
+ quantity,
931
+ domain,
932
+ salt,
933
+ expirationTime,
934
+ zone,
935
+ })
936
+ }
937
+
938
+ /**
939
+ * Compute the `basePrice` parameter to be used to price an order.
940
+ * Also validates the price and token address.
941
+ * @param tokenAddress Address of the ERC-20 token to use for trading. Use the null address for ETH.
942
+ * @param amount The value for the order, in the token's main units (e.g. ETH instead of wei)
943
+ */
944
+ private async _getPriceParameters(
945
+ orderSide: OrderSide,
946
+ tokenAddress: string,
947
+ amount: BigNumberish,
948
+ ) {
949
+ tokenAddress = tokenAddress.toLowerCase()
950
+ const isEther = tokenAddress === ethers.ZeroAddress
951
+ let decimals = 18
952
+ if (!isEther) {
953
+ if (tokenAddress in this._cachedPaymentTokenDecimals) {
954
+ decimals = this._cachedPaymentTokenDecimals[tokenAddress]
955
+ } else {
956
+ const paymentToken = await this.api.getPaymentToken(tokenAddress)
957
+ this._cachedPaymentTokenDecimals[tokenAddress] = paymentToken.decimals
958
+ decimals = paymentToken.decimals
959
+ }
960
+ }
961
+
962
+ const amountWei = ethers.parseUnits(amount.toString(), decimals)
963
+ const basePrice = amountWei
964
+
965
+ // Validation
966
+ if (amount == null || amountWei < 0) {
967
+ throw new Error("Starting price must be a number >= 0")
968
+ }
969
+ if (isEther && orderSide === OrderSide.OFFER) {
970
+ throw new Error("Offers must use wrapped ETH or an ERC-20 token.")
971
+ }
972
+ return { basePrice }
973
+ }
974
+
975
+ private _dispatch(event: EventType, data: EventData) {
976
+ this._emitter.emit(event, data)
977
+ }
978
+
979
+ /** Get the accounts available from the signer or provider. */
980
+ private async _getAvailableAccounts() {
981
+ const availableAccounts: string[] = []
982
+
983
+ try {
984
+ if ("address" in this._signerOrProvider) {
985
+ availableAccounts.push(this._signerOrProvider.address as string)
986
+ } else if ("listAccounts" in this._signerOrProvider) {
987
+ const addresses = (await this._signerOrProvider.listAccounts()).map(
988
+ acct => acct.address,
989
+ )
990
+ availableAccounts.push(...addresses)
991
+ } else if ("getAddress" in this._signerOrProvider) {
992
+ availableAccounts.push(await this._signerOrProvider.getAddress())
993
+ }
994
+ } catch (error) {
995
+ // If we can't get accounts (e.g., RPC error), treat as no accounts available
996
+ this.logger(
997
+ `Failed to get available accounts: ${error instanceof Error ? error.message : error}`,
998
+ )
999
+ }
1000
+
1001
+ return availableAccounts
1002
+ }
1003
+
1004
+ /**
1005
+ * Throws an error if an account is not available through the provider.
1006
+ * @param accountAddress The account address to check is available.
1007
+ */
1008
+ private async _requireAccountIsAvailable(accountAddress: string) {
1009
+ const accountAddressChecksummed = ethers.getAddress(accountAddress)
1010
+ const availableAccounts = await this._getAvailableAccounts()
1011
+
1012
+ if (availableAccounts.includes(accountAddressChecksummed)) {
1013
+ return
1014
+ }
1015
+
1016
+ throw new Error(
1017
+ `Specified accountAddress is not available through wallet or provider: ${accountAddressChecksummed}. Accounts available: ${
1018
+ availableAccounts.length > 0 ? availableAccounts.join(", ") : "none"
1019
+ }`,
1020
+ )
1021
+ }
1022
+
1023
+ /**
1024
+ * Wait for a transaction to confirm and log the success or failure.
1025
+ * @param transactionHash The transaction hash to wait for.
1026
+ * @param event The event type to log.
1027
+ * @param description The description of the transaction.
1028
+ */
1029
+ private async _confirmTransaction(
1030
+ transactionHash: string,
1031
+ event: EventType,
1032
+ description: string,
1033
+ ): Promise<void> {
1034
+ const transactionEventData = { transactionHash, event }
1035
+ this.logger(`Transaction started: ${description}`)
1036
+
1037
+ try {
1038
+ this._dispatch(EventType.TransactionCreated, transactionEventData)
1039
+ await this.provider.waitForTransaction(transactionHash)
1040
+ this.logger(`Transaction succeeded: ${description}`)
1041
+ this._dispatch(EventType.TransactionConfirmed, transactionEventData)
1042
+ } catch (error) {
1043
+ this.logger(`Transaction failed: ${description}`)
1044
+ this._dispatch(EventType.TransactionFailed, {
1045
+ ...transactionEventData,
1046
+ error,
1047
+ })
1048
+ throw error
1049
+ }
1050
+ }
1051
+ }