@opensea/sdk 9.0.0 → 10.1.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 (311) hide show
  1. package/README.md +35 -6
  2. package/lib/abi/abis.d.ts +301 -0
  3. package/lib/abi/abis.js +231 -0
  4. package/lib/abi/abis.js.map +1 -0
  5. package/lib/api/api.d.ts +26 -2
  6. package/lib/api/api.js +83 -51
  7. package/lib/api/api.js.map +1 -1
  8. package/lib/api/apiPaths.d.ts +2 -0
  9. package/lib/api/apiPaths.js +9 -1
  10. package/lib/api/apiPaths.js.map +1 -1
  11. package/lib/api/nfts.d.ts +13 -2
  12. package/lib/api/nfts.js +18 -0
  13. package/lib/api/nfts.js.map +1 -1
  14. package/lib/api/orders.js +2 -2
  15. package/lib/api/orders.js.map +1 -1
  16. package/lib/api/types.d.ts +7 -0
  17. package/lib/api/types.js.map +1 -1
  18. package/lib/constants.d.ts +2 -2
  19. package/lib/constants.js +7 -4
  20. package/lib/constants.js.map +1 -1
  21. package/lib/index.d.ts +2 -0
  22. package/lib/index.js +1 -0
  23. package/lib/index.js.map +1 -1
  24. package/lib/orders/privateListings.js +2 -2
  25. package/lib/orders/privateListings.js.map +1 -1
  26. package/lib/orders/utils.js +9 -1
  27. package/lib/orders/utils.js.map +1 -1
  28. package/lib/provider/ethers-adapter.d.ts +17 -0
  29. package/lib/provider/ethers-adapter.js +135 -0
  30. package/lib/provider/ethers-adapter.js.map +1 -0
  31. package/lib/provider/seaport-bridge.d.ts +11 -0
  32. package/lib/provider/seaport-bridge.js +130 -0
  33. package/lib/provider/seaport-bridge.js.map +1 -0
  34. package/lib/provider/types.d.ts +62 -0
  35. package/lib/provider/types.js +7 -0
  36. package/lib/provider/types.js.map +1 -0
  37. package/lib/provider/viem-adapter.d.ts +27 -0
  38. package/lib/provider/viem-adapter.js +122 -0
  39. package/lib/provider/viem-adapter.js.map +1 -0
  40. package/lib/sdk/assets.d.ts +7 -23
  41. package/lib/sdk/assets.js +101 -77
  42. package/lib/sdk/assets.js.map +1 -1
  43. package/lib/sdk/base.d.ts +350 -0
  44. package/lib/sdk/base.js +325 -0
  45. package/lib/sdk/base.js.map +1 -0
  46. package/lib/sdk/cancellation.d.ts +1 -2
  47. package/lib/sdk/cancellation.js +4 -4
  48. package/lib/sdk/cancellation.js.map +1 -1
  49. package/lib/sdk/context.d.ts +5 -5
  50. package/lib/sdk/fulfillment.d.ts +20 -59
  51. package/lib/sdk/fulfillment.js +18 -58
  52. package/lib/sdk/fulfillment.js.map +1 -1
  53. package/lib/sdk/orders.d.ts +25 -26
  54. package/lib/sdk/orders.js +8 -9
  55. package/lib/sdk/orders.js.map +1 -1
  56. package/lib/sdk/tokens.d.ts +3 -3
  57. package/lib/sdk/tokens.js +17 -7
  58. package/lib/sdk/tokens.js.map +1 -1
  59. package/lib/sdk.d.ts +16 -550
  60. package/lib/sdk.js +35 -663
  61. package/lib/sdk.js.map +1 -1
  62. package/lib/types.d.ts +11 -6
  63. package/lib/types.js +3 -3
  64. package/lib/types.js.map +1 -1
  65. package/lib/utils/address.d.ts +12 -0
  66. package/lib/utils/address.js +39 -0
  67. package/lib/utils/address.js.map +1 -0
  68. package/lib/utils/chain.d.ts +1 -1
  69. package/lib/utils/fees.d.ts +5 -0
  70. package/lib/utils/fees.js +24 -6
  71. package/lib/utils/fees.js.map +1 -1
  72. package/lib/utils/protocol.js +5 -5
  73. package/lib/utils/protocol.js.map +1 -1
  74. package/lib/utils/units.d.ts +12 -0
  75. package/lib/utils/units.js +43 -0
  76. package/lib/utils/units.js.map +1 -0
  77. package/lib/utils/utils.d.ts +2 -10
  78. package/lib/utils/utils.js +2 -17
  79. package/lib/utils/utils.js.map +1 -1
  80. package/lib/viem.d.ts +44 -0
  81. package/lib/viem.js +114 -0
  82. package/lib/viem.js.map +1 -0
  83. package/package.json +31 -13
  84. package/src/abi/abis.ts +236 -0
  85. package/src/api/api.ts +100 -59
  86. package/src/api/apiPaths.ts +16 -0
  87. package/src/api/nfts.ts +37 -1
  88. package/src/api/orders.ts +2 -2
  89. package/src/api/types.ts +8 -0
  90. package/src/constants.ts +7 -3
  91. package/src/index.ts +8 -0
  92. package/src/orders/privateListings.ts +2 -2
  93. package/src/orders/utils.ts +8 -1
  94. package/src/provider/ethers-adapter.ts +182 -0
  95. package/src/provider/seaport-bridge.ts +163 -0
  96. package/src/provider/types.ts +67 -0
  97. package/src/provider/viem-adapter.ts +165 -0
  98. package/src/sdk/assets.ts +128 -158
  99. package/src/sdk/base.ts +577 -0
  100. package/src/sdk/cancellation.ts +6 -9
  101. package/src/sdk/context.ts +5 -5
  102. package/src/sdk/fulfillment.ts +34 -73
  103. package/src/sdk/orders.ts +44 -44
  104. package/src/sdk/tokens.ts +18 -18
  105. package/src/sdk.ts +40 -1011
  106. package/src/types.ts +12 -6
  107. package/src/utils/address.ts +40 -0
  108. package/src/utils/fees.ts +28 -8
  109. package/src/utils/protocol.ts +5 -5
  110. package/src/utils/units.ts +47 -0
  111. package/src/utils/utils.ts +2 -22
  112. package/src/viem.ts +125 -0
  113. package/lib/src/api/accounts.d.ts +0 -18
  114. package/lib/src/api/accounts.js +0 -30
  115. package/lib/src/api/accounts.js.map +0 -1
  116. package/lib/src/api/api.d.ts +0 -429
  117. package/lib/src/api/api.js +0 -652
  118. package/lib/src/api/api.js.map +0 -1
  119. package/lib/src/api/apiPaths.d.ts +0 -37
  120. package/lib/src/api/apiPaths.js +0 -140
  121. package/lib/src/api/apiPaths.js.map +0 -1
  122. package/lib/src/api/collections.d.ts +0 -26
  123. package/lib/src/api/collections.js +0 -57
  124. package/lib/src/api/collections.js.map +0 -1
  125. package/lib/src/api/events.d.ts +0 -26
  126. package/lib/src/api/events.js +0 -42
  127. package/lib/src/api/events.js.map +0 -1
  128. package/lib/src/api/fetcher.d.ts +0 -24
  129. package/lib/src/api/fetcher.js +0 -3
  130. package/lib/src/api/fetcher.js.map +0 -1
  131. package/lib/src/api/index.d.ts +0 -2
  132. package/lib/src/api/index.js +0 -19
  133. package/lib/src/api/index.js.map +0 -1
  134. package/lib/src/api/listings.d.ts +0 -44
  135. package/lib/src/api/listings.js +0 -86
  136. package/lib/src/api/listings.js.map +0 -1
  137. package/lib/src/api/nfts.d.ts +0 -35
  138. package/lib/src/api/nfts.js +0 -66
  139. package/lib/src/api/nfts.js.map +0 -1
  140. package/lib/src/api/offers.d.ts +0 -54
  141. package/lib/src/api/offers.js +0 -122
  142. package/lib/src/api/offers.js.map +0 -1
  143. package/lib/src/api/orders.d.ts +0 -50
  144. package/lib/src/api/orders.js +0 -151
  145. package/lib/src/api/orders.js.map +0 -1
  146. package/lib/src/api/search.d.ts +0 -13
  147. package/lib/src/api/search.js +0 -21
  148. package/lib/src/api/search.js.map +0 -1
  149. package/lib/src/api/tokens.d.ts +0 -25
  150. package/lib/src/api/tokens.js +0 -42
  151. package/lib/src/api/tokens.js.map +0 -1
  152. package/lib/src/api/types.d.ts +0 -840
  153. package/lib/src/api/types.js +0 -65
  154. package/lib/src/api/types.js.map +0 -1
  155. package/lib/src/constants.d.ts +0 -22
  156. package/lib/src/constants.js +0 -52
  157. package/lib/src/constants.js.map +0 -1
  158. package/lib/src/index.d.ts +0 -18
  159. package/lib/src/index.js +0 -24
  160. package/lib/src/index.js.map +0 -1
  161. package/lib/src/orders/privateListings.d.ts +0 -12
  162. package/lib/src/orders/privateListings.js +0 -130
  163. package/lib/src/orders/privateListings.js.map +0 -1
  164. package/lib/src/orders/types.d.ts +0 -160
  165. package/lib/src/orders/types.js +0 -10
  166. package/lib/src/orders/types.js.map +0 -1
  167. package/lib/src/orders/utils.d.ts +0 -89
  168. package/lib/src/orders/utils.js +0 -177
  169. package/lib/src/orders/utils.js.map +0 -1
  170. package/lib/src/sdk/assets.d.ts +0 -104
  171. package/lib/src/sdk/assets.js +0 -397
  172. package/lib/src/sdk/assets.js.map +0 -1
  173. package/lib/src/sdk/cancellation.d.ts +0 -97
  174. package/lib/src/sdk/cancellation.js +0 -234
  175. package/lib/src/sdk/cancellation.js.map +0 -1
  176. package/lib/src/sdk/context.d.ts +0 -28
  177. package/lib/src/sdk/context.js +0 -3
  178. package/lib/src/sdk/context.js.map +0 -1
  179. package/lib/src/sdk/fulfillment.d.ts +0 -153
  180. package/lib/src/sdk/fulfillment.js +0 -296
  181. package/lib/src/sdk/fulfillment.js.map +0 -1
  182. package/lib/src/sdk/orders.d.ts +0 -253
  183. package/lib/src/sdk/orders.js +0 -677
  184. package/lib/src/sdk/orders.js.map +0 -1
  185. package/lib/src/sdk/tokens.d.ts +0 -31
  186. package/lib/src/sdk/tokens.js +0 -64
  187. package/lib/src/sdk/tokens.js.map +0 -1
  188. package/lib/src/sdk.d.ts +0 -560
  189. package/lib/src/sdk.js +0 -675
  190. package/lib/src/sdk.js.map +0 -1
  191. package/lib/src/typechain/contracts/ERC1155.d.ts +0 -236
  192. package/lib/src/typechain/contracts/ERC1155.js +0 -3
  193. package/lib/src/typechain/contracts/ERC1155.js.map +0 -1
  194. package/lib/src/typechain/contracts/ERC20.d.ts +0 -141
  195. package/lib/src/typechain/contracts/ERC20.js +0 -3
  196. package/lib/src/typechain/contracts/ERC20.js.map +0 -1
  197. package/lib/src/typechain/contracts/ERC721.d.ts +0 -213
  198. package/lib/src/typechain/contracts/ERC721.js +0 -3
  199. package/lib/src/typechain/contracts/ERC721.js.map +0 -1
  200. package/lib/src/typechain/contracts/Multicall3.d.ts +0 -57
  201. package/lib/src/typechain/contracts/Multicall3.js +0 -3
  202. package/lib/src/typechain/contracts/Multicall3.js.map +0 -1
  203. package/lib/src/typechain/contracts/TransferHelper.d.ts +0 -55
  204. package/lib/src/typechain/contracts/TransferHelper.js +0 -3
  205. package/lib/src/typechain/contracts/TransferHelper.js.map +0 -1
  206. package/lib/src/typechain/contracts/common.d.ts +0 -50
  207. package/lib/src/typechain/contracts/common.js +0 -3
  208. package/lib/src/typechain/contracts/common.js.map +0 -1
  209. package/lib/src/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  210. package/lib/src/typechain/contracts/factories/ERC1155__factory.js +0 -332
  211. package/lib/src/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  212. package/lib/src/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  213. package/lib/src/typechain/contracts/factories/ERC20__factory.js +0 -240
  214. package/lib/src/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  215. package/lib/src/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  216. package/lib/src/typechain/contracts/factories/ERC721__factory.js +0 -351
  217. package/lib/src/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  218. package/lib/src/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  219. package/lib/src/typechain/contracts/factories/Multicall3__factory.js +0 -68
  220. package/lib/src/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  221. package/lib/src/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  222. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  223. package/lib/src/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  224. package/lib/src/typechain/contracts/factories/index.d.ts +0 -5
  225. package/lib/src/typechain/contracts/factories/index.js +0 -17
  226. package/lib/src/typechain/contracts/factories/index.js.map +0 -1
  227. package/lib/src/typechain/contracts/index.d.ts +0 -11
  228. package/lib/src/typechain/contracts/index.js +0 -48
  229. package/lib/src/typechain/contracts/index.js.map +0 -1
  230. package/lib/src/types.d.ts +0 -387
  231. package/lib/src/types.js +0 -127
  232. package/lib/src/types.js.map +0 -1
  233. package/lib/src/utils/chain.d.ts +0 -60
  234. package/lib/src/utils/chain.js +0 -248
  235. package/lib/src/utils/chain.js.map +0 -1
  236. package/lib/src/utils/converters.d.ts +0 -37
  237. package/lib/src/utils/converters.js +0 -137
  238. package/lib/src/utils/converters.js.map +0 -1
  239. package/lib/src/utils/dateHelper.d.ts +0 -38
  240. package/lib/src/utils/dateHelper.js +0 -52
  241. package/lib/src/utils/dateHelper.js.map +0 -1
  242. package/lib/src/utils/fees.d.ts +0 -13
  243. package/lib/src/utils/fees.js +0 -29
  244. package/lib/src/utils/fees.js.map +0 -1
  245. package/lib/src/utils/index.d.ts +0 -2
  246. package/lib/src/utils/index.js +0 -19
  247. package/lib/src/utils/index.js.map +0 -1
  248. package/lib/src/utils/protocol.d.ts +0 -75
  249. package/lib/src/utils/protocol.js +0 -161
  250. package/lib/src/utils/protocol.js.map +0 -1
  251. package/lib/src/utils/rateLimit.d.ts +0 -34
  252. package/lib/src/utils/rateLimit.js +0 -97
  253. package/lib/src/utils/rateLimit.js.map +0 -1
  254. package/lib/src/utils/stringHelper.d.ts +0 -18
  255. package/lib/src/utils/stringHelper.js +0 -24
  256. package/lib/src/utils/stringHelper.js.map +0 -1
  257. package/lib/src/utils/utils.d.ts +0 -18
  258. package/lib/src/utils/utils.js +0 -45
  259. package/lib/src/utils/utils.js.map +0 -1
  260. package/lib/typechain/contracts/ERC1155.d.ts +0 -236
  261. package/lib/typechain/contracts/ERC1155.js +0 -3
  262. package/lib/typechain/contracts/ERC1155.js.map +0 -1
  263. package/lib/typechain/contracts/ERC20.d.ts +0 -141
  264. package/lib/typechain/contracts/ERC20.js +0 -3
  265. package/lib/typechain/contracts/ERC20.js.map +0 -1
  266. package/lib/typechain/contracts/ERC721.d.ts +0 -213
  267. package/lib/typechain/contracts/ERC721.js +0 -3
  268. package/lib/typechain/contracts/ERC721.js.map +0 -1
  269. package/lib/typechain/contracts/Multicall3.d.ts +0 -57
  270. package/lib/typechain/contracts/Multicall3.js +0 -3
  271. package/lib/typechain/contracts/Multicall3.js.map +0 -1
  272. package/lib/typechain/contracts/TransferHelper.d.ts +0 -55
  273. package/lib/typechain/contracts/TransferHelper.js +0 -3
  274. package/lib/typechain/contracts/TransferHelper.js.map +0 -1
  275. package/lib/typechain/contracts/common.d.ts +0 -50
  276. package/lib/typechain/contracts/common.js +0 -3
  277. package/lib/typechain/contracts/common.js.map +0 -1
  278. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +0 -250
  279. package/lib/typechain/contracts/factories/ERC1155__factory.js +0 -332
  280. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +0 -1
  281. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +0 -174
  282. package/lib/typechain/contracts/factories/ERC20__factory.js +0 -240
  283. package/lib/typechain/contracts/factories/ERC20__factory.js.map +0 -1
  284. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +0 -268
  285. package/lib/typechain/contracts/factories/ERC721__factory.js +0 -351
  286. package/lib/typechain/contracts/factories/ERC721__factory.js.map +0 -1
  287. package/lib/typechain/contracts/factories/Multicall3__factory.d.ts +0 -43
  288. package/lib/typechain/contracts/factories/Multicall3__factory.js +0 -68
  289. package/lib/typechain/contracts/factories/Multicall3__factory.js.map +0 -1
  290. package/lib/typechain/contracts/factories/TransferHelper__factory.d.ts +0 -46
  291. package/lib/typechain/contracts/factories/TransferHelper__factory.js +0 -71
  292. package/lib/typechain/contracts/factories/TransferHelper__factory.js.map +0 -1
  293. package/lib/typechain/contracts/factories/index.d.ts +0 -5
  294. package/lib/typechain/contracts/factories/index.js +0 -17
  295. package/lib/typechain/contracts/factories/index.js.map +0 -1
  296. package/lib/typechain/contracts/index.d.ts +0 -11
  297. package/lib/typechain/contracts/index.js +0 -48
  298. package/lib/typechain/contracts/index.js.map +0 -1
  299. package/src/typechain/contracts/ERC1155.ts +0 -440
  300. package/src/typechain/contracts/ERC20.ts +0 -286
  301. package/src/typechain/contracts/ERC721.ts +0 -412
  302. package/src/typechain/contracts/Multicall3.ts +0 -117
  303. package/src/typechain/contracts/TransferHelper.ts +0 -122
  304. package/src/typechain/contracts/common.ts +0 -131
  305. package/src/typechain/contracts/factories/ERC1155__factory.ts +0 -331
  306. package/src/typechain/contracts/factories/ERC20__factory.ts +0 -239
  307. package/src/typechain/contracts/factories/ERC721__factory.ts +0 -350
  308. package/src/typechain/contracts/factories/Multicall3__factory.ts +0 -67
  309. package/src/typechain/contracts/factories/TransferHelper__factory.ts +0 -76
  310. package/src/typechain/contracts/factories/index.ts +0 -8
  311. package/src/typechain/contracts/index.ts +0 -14
package/src/index.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { OpenSeaSDK } from "./sdk"
2
2
 
3
3
  export * from "./api/types"
4
+ export * from "./constants"
4
5
  export * from "./orders/types"
6
+ export type {
7
+ ContractCaller,
8
+ OpenSeaProvider,
9
+ OpenSeaSigner,
10
+ OpenSeaWallet,
11
+ TransactionResponse,
12
+ } from "./provider/types"
5
13
  export * from "./types"
6
14
  export * from "./utils"
7
15
  /**
@@ -8,7 +8,7 @@ import type {
8
8
  } from "@opensea/seaport-js/lib/types"
9
9
  import { isCurrencyItem } from "@opensea/seaport-js/lib/utils/item"
10
10
  import { generateRandomSalt } from "@opensea/seaport-js/lib/utils/order"
11
- import { ZeroAddress } from "ethers"
11
+ import { ZERO_ADDRESS } from "../constants"
12
12
 
13
13
  /**
14
14
  * Compute the native currency (ETH) value required to fulfill a private listing.
@@ -25,7 +25,7 @@ export const computePrivateListingValue = (
25
25
  .filter(
26
26
  item =>
27
27
  item.recipient.toLowerCase() !== takerAddress.toLowerCase() &&
28
- item.token.toLowerCase() === ZeroAddress.toLowerCase() &&
28
+ item.token.toLowerCase() === ZERO_ADDRESS.toLowerCase() &&
29
29
  item.itemType === ItemType.NATIVE,
30
30
  )
31
31
  .reduce((sum, item) => sum + BigInt(item.startAmount), 0n)
@@ -222,6 +222,13 @@ export const serializeOrdersQueryOptions = (
222
222
  }
223
223
  }
224
224
 
225
+ /** Map API side values ("ask"/"bid") to SDK OrderSide enum values */
226
+ const mapApiSide = (side: string): OrderSide => {
227
+ if (side === "ask" || side === OrderSide.LISTING) return OrderSide.LISTING
228
+ if (side === "bid" || side === OrderSide.OFFER) return OrderSide.OFFER
229
+ return side as OrderSide
230
+ }
231
+
225
232
  export const deserializeOrder = (order: SerializedOrderV2): OrderV2 => {
226
233
  return {
227
234
  createdDate: order.created_date,
@@ -242,7 +249,7 @@ export const deserializeOrder = (order: SerializedOrderV2): OrderV2 => {
242
249
  account: accountFromJSON(account),
243
250
  basisPoints: basis_points,
244
251
  })),
245
- side: order.side,
252
+ side: mapApiSide(order.side as string),
246
253
  orderType: order.order_type,
247
254
  cancelled: order.cancelled,
248
255
  finalized: order.finalized,
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Ethers v6 adapter — wraps ethers Signer/Provider into the SDK's abstract interfaces.
3
+ */
4
+ import {
5
+ Contract,
6
+ ethers as ethersLib,
7
+ type JsonRpcProvider,
8
+ type Signer,
9
+ } from "ethers"
10
+ import type {
11
+ ContractCaller,
12
+ OpenSeaProvider,
13
+ OpenSeaSigner,
14
+ OpenSeaWallet,
15
+ TransactionResponse,
16
+ } from "./types"
17
+
18
+ /**
19
+ * Creates an OpenSeaWallet from an ethers Signer or JsonRpcProvider.
20
+ */
21
+ export function createEthersWallet(
22
+ signerOrProvider: Signer | JsonRpcProvider,
23
+ ): OpenSeaWallet {
24
+ const provider = createEthersProvider(signerOrProvider)
25
+
26
+ if (isEthersSigner(signerOrProvider)) {
27
+ return {
28
+ signer: createEthersSigner(signerOrProvider),
29
+ provider,
30
+ }
31
+ }
32
+
33
+ return { provider }
34
+ }
35
+
36
+ /**
37
+ * Creates an OpenSeaSigner from an ethers Signer.
38
+ */
39
+ function createEthersSigner(signer: Signer): OpenSeaSigner {
40
+ return {
41
+ async getAddress(): Promise<string> {
42
+ if ("address" in signer) {
43
+ return signer.address as string
44
+ }
45
+ return signer.getAddress()
46
+ },
47
+
48
+ async sendTransaction(tx) {
49
+ const ethTx = await signer.sendTransaction({
50
+ to: tx.to,
51
+ data: tx.data,
52
+ value: tx.value,
53
+ from: tx.from,
54
+ ...tx.overrides,
55
+ })
56
+ return {
57
+ hash: ethTx.hash,
58
+ async wait() {
59
+ await ethTx.wait()
60
+ },
61
+ }
62
+ },
63
+
64
+ async signTypedData(domain, types, value) {
65
+ if (typeof (signer as any).signTypedData !== "function") {
66
+ throw new Error(
67
+ "The provided signer does not support signTypedData. Please use an ethers Signer that supports EIP-712 signing.",
68
+ )
69
+ }
70
+ return (signer as any).signTypedData(domain, types, value)
71
+ },
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Creates an OpenSeaProvider from an ethers Signer or JsonRpcProvider.
77
+ */
78
+ function createEthersProvider(
79
+ signerOrProvider: Signer | JsonRpcProvider,
80
+ ): OpenSeaProvider {
81
+ const provider = isEthersSigner(signerOrProvider)
82
+ ? (signerOrProvider.provider as JsonRpcProvider)
83
+ : signerOrProvider
84
+
85
+ if (!provider) {
86
+ throw new Error(
87
+ "Signer must be connected to a provider. " +
88
+ "Use `signer.connect(provider)` or pass a JsonRpcProvider directly.",
89
+ )
90
+ }
91
+
92
+ return {
93
+ async waitForTransaction(hash: string) {
94
+ await provider.waitForTransaction(hash)
95
+ },
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Creates a ContractCaller using ethers Contract.
101
+ */
102
+ export function createEthersContractCaller(
103
+ signerOrProvider: Signer | JsonRpcProvider,
104
+ ): ContractCaller {
105
+ const readProvider = isEthersSigner(signerOrProvider)
106
+ ? (signerOrProvider.provider as JsonRpcProvider)
107
+ : signerOrProvider
108
+
109
+ if (!readProvider) {
110
+ throw new Error(
111
+ "Signer must be connected to a provider. " +
112
+ "Use `signer.connect(provider)` or pass a JsonRpcProvider directly.",
113
+ )
114
+ }
115
+
116
+ return {
117
+ async readContract({ address, abi, functionName, args }) {
118
+ const contract = new Contract(address, abi as any[], readProvider)
119
+ return contract[functionName].staticCall(...args)
120
+ },
121
+
122
+ async writeContract({
123
+ address,
124
+ abi,
125
+ functionName,
126
+ args,
127
+ value,
128
+ overrides,
129
+ }): Promise<TransactionResponse> {
130
+ const contract = new Contract(address, abi as any[], signerOrProvider)
131
+ const txArgs = [...args]
132
+ if (value !== undefined || overrides) {
133
+ txArgs.push({ ...overrides, value })
134
+ }
135
+ const tx = await contract[functionName](...txArgs)
136
+ return {
137
+ hash: tx.hash,
138
+ async wait() {
139
+ await tx.wait()
140
+ },
141
+ }
142
+ },
143
+
144
+ encodeFunctionData({ abi, functionName, args }) {
145
+ const iface = new ethersLib.Interface(abi as any[])
146
+ return iface.encodeFunctionData(functionName, args)
147
+ },
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Get available accounts from an ethers Signer or JsonRpcProvider.
153
+ */
154
+ export async function getEthersAccounts(
155
+ signerOrProvider: Signer | JsonRpcProvider,
156
+ logger: (msg: string) => void,
157
+ ): Promise<string[]> {
158
+ const accounts: string[] = []
159
+ try {
160
+ if ("address" in signerOrProvider) {
161
+ accounts.push(signerOrProvider.address as string)
162
+ } else if ("listAccounts" in signerOrProvider) {
163
+ const listed = (
164
+ await (signerOrProvider as JsonRpcProvider).listAccounts()
165
+ ).map(acct => acct.address)
166
+ accounts.push(...listed)
167
+ } else if ("getAddress" in signerOrProvider) {
168
+ accounts.push(await (signerOrProvider as Signer).getAddress())
169
+ }
170
+ } catch (error) {
171
+ logger(
172
+ `Failed to get available accounts: ${error instanceof Error ? error.message : error}`,
173
+ )
174
+ }
175
+ return accounts
176
+ }
177
+
178
+ function isEthersSigner(
179
+ signerOrProvider: Signer | JsonRpcProvider,
180
+ ): signerOrProvider is Signer {
181
+ return "signTransaction" in signerOrProvider
182
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Bridge that wraps viem clients as an ethers-compatible Signer for seaport-js.
3
+ * seaport-js only accepts ethers Signer | JsonRpcProvider, so we need this shim.
4
+ */
5
+ import {
6
+ AbstractSigner,
7
+ JsonRpcProvider,
8
+ type TransactionRequest,
9
+ type TransactionResponse,
10
+ } from "ethers"
11
+ import type { ViemAdapterParams } from "./viem-adapter"
12
+
13
+ /**
14
+ * Creates an ethers-compatible Signer from viem clients, for use with seaport-js.
15
+ * If only a publicClient is provided (no walletClient), returns a read-only JsonRpcProvider.
16
+ */
17
+ export function createSeaportBridge(
18
+ params: ViemAdapterParams,
19
+ logger?: (msg: string) => void,
20
+ ): AbstractSigner | JsonRpcProvider {
21
+ const { publicClient, walletClient, rpcUrl: explicitRpcUrl } = params
22
+
23
+ // We need the chain's RPC URL to create an ethers provider for seaport-js.
24
+ // Prefer an explicit rpcUrl if provided (needed for non-HTTP transports).
25
+ // Otherwise, extract it from the viem transport's internal properties.
26
+ // NOTE: transport.url / transport.value.url are viem internals that may
27
+ // change across viem versions.
28
+ const transport = (publicClient as any).transport
29
+ const detectedUrl = transport?.url ?? transport?.value?.url
30
+ const rpcUrl = explicitRpcUrl ?? detectedUrl
31
+ if (!rpcUrl) {
32
+ throw new Error(
33
+ "OpenSeaSDK viem entry point requires an HTTP RPC URL. " +
34
+ "Either use `http(url)` when creating your publicClient, or pass " +
35
+ "`rpcUrl` explicitly in the constructor params.",
36
+ )
37
+ }
38
+ if (!explicitRpcUrl && detectedUrl && logger) {
39
+ logger(
40
+ "Seaport bridge: auto-detected RPC URL from viem transport internals. " +
41
+ "Pass `rpcUrl` explicitly for stability across viem versions.",
42
+ )
43
+ }
44
+
45
+ const ethersProvider = new JsonRpcProvider(rpcUrl)
46
+
47
+ if (!walletClient) {
48
+ return ethersProvider
49
+ }
50
+
51
+ return new ViemEthersSigner(walletClient, ethersProvider)
52
+ }
53
+
54
+ /**
55
+ * Minimal ethers AbstractSigner implementation backed by a viem WalletClient.
56
+ * Implements the methods that seaport-js calls: getAddress, sendTransaction,
57
+ * signMessage, and signTypedData.
58
+ *
59
+ * sendTransaction is overridden to use viem's walletClient.sendTransaction directly,
60
+ * bypassing ethers' default signTransaction + broadcastTransaction flow (similar to
61
+ * how ethers' own JsonRpcSigner overrides it to use eth_sendTransaction).
62
+ */
63
+ class ViemEthersSigner extends AbstractSigner {
64
+ private _walletClient: any
65
+
66
+ constructor(walletClient: any, provider: JsonRpcProvider) {
67
+ super(provider)
68
+ this._walletClient = walletClient
69
+ }
70
+
71
+ async getAddress(): Promise<string> {
72
+ if (!this._walletClient.account) {
73
+ throw new Error("WalletClient must have an account")
74
+ }
75
+ return this._walletClient.account.address
76
+ }
77
+
78
+ // seaport-js checks `.address` property directly on the signer.
79
+ // Throw if no account is set rather than returning empty string,
80
+ // which could cause subtle bugs in truthy checks.
81
+ get address(): string {
82
+ if (!this._walletClient.account?.address) {
83
+ throw new Error(
84
+ "WalletClient must have an account. Use `createWalletClient` with an `account` parameter.",
85
+ )
86
+ }
87
+ return this._walletClient.account.address
88
+ }
89
+
90
+ /**
91
+ * Override sendTransaction to delegate to viem's walletClient.sendTransaction.
92
+ * This bypasses AbstractSigner's default flow (signTransaction → broadcastTransaction)
93
+ * since viem handles signing internally via the wallet.
94
+ */
95
+ async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
96
+ const hash = await this._walletClient.sendTransaction({
97
+ to: tx.to as `0x${string}`,
98
+ data: tx.data as `0x${string}` | undefined,
99
+ value: tx.value != null ? BigInt(tx.value.toString()) : undefined,
100
+ // Forward gas parameters when provided by seaport-js or callers
101
+ gas: tx.gasLimit != null ? BigInt(tx.gasLimit.toString()) : undefined,
102
+ gasPrice:
103
+ tx.gasPrice != null ? BigInt(tx.gasPrice.toString()) : undefined,
104
+ maxFeePerGas:
105
+ tx.maxFeePerGas != null
106
+ ? BigInt(tx.maxFeePerGas.toString())
107
+ : undefined,
108
+ maxPriorityFeePerGas:
109
+ tx.maxPriorityFeePerGas != null
110
+ ? BigInt(tx.maxPriorityFeePerGas.toString())
111
+ : undefined,
112
+ nonce: tx.nonce != null ? Number(tx.nonce) : undefined,
113
+ account: this._walletClient.account,
114
+ chain: this._walletClient.chain,
115
+ })
116
+
117
+ // Return an ethers-compatible TransactionResponse by fetching from the provider
118
+ const response = await this.provider!.getTransaction(hash)
119
+ if (!response) {
120
+ // Fallback: construct minimal response if the tx isn't indexed yet
121
+ return {
122
+ hash,
123
+ wait: () => this.provider!.waitForTransaction(hash),
124
+ } as unknown as TransactionResponse
125
+ }
126
+ return response
127
+ }
128
+
129
+ async signTransaction(): Promise<string> {
130
+ throw new Error(
131
+ "signTransaction is not supported via the viem bridge. " +
132
+ "sendTransaction is overridden to delegate to viem directly.",
133
+ )
134
+ }
135
+
136
+ async signMessage(message: string | Uint8Array): Promise<string> {
137
+ return this._walletClient.signMessage({
138
+ message: typeof message === "string" ? message : { raw: message as any },
139
+ account: this._walletClient.account,
140
+ })
141
+ }
142
+
143
+ async signTypedData(domain: any, types: any, value: any): Promise<string> {
144
+ const primaryType =
145
+ Object.keys(types).find(key => key !== "EIP712Domain") ||
146
+ Object.keys(types)[0]
147
+
148
+ return this._walletClient.signTypedData({
149
+ domain: {
150
+ ...domain,
151
+ chainId: domain.chainId ? Number(domain.chainId) : undefined,
152
+ },
153
+ types,
154
+ primaryType,
155
+ message: value,
156
+ account: this._walletClient.account,
157
+ })
158
+ }
159
+
160
+ connect(): ViemEthersSigner {
161
+ return this
162
+ }
163
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Abstract provider interfaces for the OpenSea SDK.
3
+ * These allow the SDK to work with both ethers and viem (or any other library).
4
+ */
5
+
6
+ /** Transaction receipt returned after sending a transaction. */
7
+ export interface TransactionResponse {
8
+ hash: string
9
+ wait(): Promise<void>
10
+ }
11
+
12
+ /** Minimal signer interface for the OpenSea SDK. */
13
+ export interface OpenSeaSigner {
14
+ getAddress(): Promise<string>
15
+ sendTransaction(tx: {
16
+ to: string
17
+ data?: string
18
+ value?: bigint
19
+ from?: string
20
+ overrides?: Record<string, unknown>
21
+ }): Promise<TransactionResponse>
22
+ signTypedData(
23
+ domain: {
24
+ chainId: string | number
25
+ name: string
26
+ version: string
27
+ verifyingContract: string
28
+ },
29
+ types: Record<string, Array<{ name: string; type: string }>>,
30
+ value: Record<string, unknown>,
31
+ ): Promise<string>
32
+ }
33
+
34
+ /** Minimal provider interface for the OpenSea SDK. */
35
+ export interface OpenSeaProvider {
36
+ waitForTransaction(hash: string): Promise<void>
37
+ }
38
+
39
+ /** Combined wallet: either signer+provider or provider-only. */
40
+ export type OpenSeaWallet =
41
+ | { signer: OpenSeaSigner; provider: OpenSeaProvider }
42
+ | { provider: OpenSeaProvider }
43
+
44
+ /** Contract read/write interface. */
45
+ export interface ContractCaller {
46
+ readContract(params: {
47
+ address: string
48
+ abi: readonly unknown[]
49
+ functionName: string
50
+ args: unknown[]
51
+ }): Promise<unknown>
52
+
53
+ writeContract(params: {
54
+ address: string
55
+ abi: readonly unknown[]
56
+ functionName: string
57
+ args: unknown[]
58
+ value?: bigint
59
+ overrides?: Record<string, unknown>
60
+ }): Promise<TransactionResponse>
61
+
62
+ encodeFunctionData(params: {
63
+ abi: readonly unknown[]
64
+ functionName: string
65
+ args: unknown[]
66
+ }): string
67
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Viem adapter — wraps viem WalletClient/PublicClient into the SDK's abstract interfaces.
3
+ *
4
+ * viem is an optional peerDependency and a devDependency (for type-checking).
5
+ * This module is only executed at runtime by code importing from "@opensea/sdk/viem",
6
+ * which requires viem to be installed.
7
+ */
8
+ import {
9
+ type PublicClient,
10
+ encodeFunctionData as viemEncodeFunctionData,
11
+ type WalletClient,
12
+ } from "viem"
13
+ import type {
14
+ ContractCaller,
15
+ OpenSeaProvider,
16
+ OpenSeaSigner,
17
+ OpenSeaWallet,
18
+ TransactionResponse,
19
+ } from "./types"
20
+
21
+ export interface ViemAdapterParams {
22
+ publicClient: PublicClient
23
+ walletClient?: WalletClient
24
+ /**
25
+ * Explicit RPC URL for seaport-js (which requires an ethers provider internally).
26
+ * If not provided, the SDK attempts to extract the URL from the publicClient's
27
+ * HTTP transport. Required when using non-HTTP transports (WebSocket, custom).
28
+ */
29
+ rpcUrl?: string
30
+ }
31
+
32
+ /**
33
+ * Creates an OpenSeaWallet from viem clients.
34
+ */
35
+ export function createViemWallet(params: ViemAdapterParams): OpenSeaWallet {
36
+ const provider = createViemProvider(params.publicClient)
37
+
38
+ if (params.walletClient) {
39
+ return {
40
+ signer: createViemSigner(params.walletClient, params.publicClient),
41
+ provider,
42
+ }
43
+ }
44
+
45
+ return { provider }
46
+ }
47
+
48
+ function createViemSigner(
49
+ walletClient: WalletClient,
50
+ publicClient: PublicClient,
51
+ ): OpenSeaSigner {
52
+ return {
53
+ async getAddress() {
54
+ if (!walletClient.account) {
55
+ throw new Error(
56
+ "WalletClient must have an account. Use `createWalletClient` with an `account` parameter.",
57
+ )
58
+ }
59
+ return walletClient.account.address
60
+ },
61
+
62
+ async sendTransaction(tx) {
63
+ const hash = await walletClient.sendTransaction({
64
+ to: tx.to as `0x${string}`,
65
+ data: tx.data as `0x${string}` | undefined,
66
+ value: tx.value,
67
+ account: walletClient.account!,
68
+ chain: walletClient.chain,
69
+ ...(tx.overrides as any),
70
+ })
71
+ return {
72
+ hash,
73
+ async wait() {
74
+ await publicClient.waitForTransactionReceipt({ hash })
75
+ },
76
+ }
77
+ },
78
+
79
+ async signTypedData(domain, types, value) {
80
+ return walletClient.signTypedData({
81
+ domain: {
82
+ chainId: Number(domain.chainId),
83
+ name: domain.name,
84
+ version: domain.version,
85
+ verifyingContract: domain.verifyingContract as `0x${string}`,
86
+ },
87
+ types,
88
+ primaryType:
89
+ Object.keys(types).find(key => key !== "EIP712Domain") ||
90
+ Object.keys(types)[0],
91
+ message: value,
92
+ account: walletClient.account!,
93
+ })
94
+ },
95
+ }
96
+ }
97
+
98
+ function createViemProvider(publicClient: PublicClient): OpenSeaProvider {
99
+ return {
100
+ async waitForTransaction(hash: string) {
101
+ await publicClient.waitForTransactionReceipt({
102
+ hash: hash as `0x${string}`,
103
+ })
104
+ },
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Creates a ContractCaller using viem clients.
110
+ */
111
+ export function createViemContractCaller(
112
+ params: ViemAdapterParams,
113
+ ): ContractCaller {
114
+ const { publicClient, walletClient } = params
115
+
116
+ return {
117
+ async readContract({ address, abi, functionName, args }) {
118
+ return publicClient.readContract({
119
+ address: address as `0x${string}`,
120
+ abi: abi as any,
121
+ functionName,
122
+ args: args as any,
123
+ })
124
+ },
125
+
126
+ async writeContract({
127
+ address,
128
+ abi,
129
+ functionName,
130
+ args,
131
+ value,
132
+ overrides,
133
+ }): Promise<TransactionResponse> {
134
+ if (!walletClient) {
135
+ throw new Error("A WalletClient is required for write operations")
136
+ }
137
+ const hash = await walletClient.writeContract({
138
+ address: address as `0x${string}`,
139
+ abi: abi as any,
140
+ functionName,
141
+ args: args as any,
142
+ value,
143
+ account: walletClient.account!,
144
+ chain: walletClient.chain,
145
+ ...(overrides as any),
146
+ })
147
+ return {
148
+ hash,
149
+ async wait() {
150
+ await publicClient.waitForTransactionReceipt({
151
+ hash: hash as `0x${string}`,
152
+ })
153
+ },
154
+ }
155
+ },
156
+
157
+ encodeFunctionData({ abi, functionName, args }) {
158
+ return viemEncodeFunctionData({
159
+ abi: abi as any,
160
+ functionName,
161
+ args: args as any,
162
+ })
163
+ },
164
+ }
165
+ }