opensea-js 3.0.4 → 4.0.0-beta.2

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 (43) hide show
  1. package/README.md +53 -95
  2. package/lib/api.d.ts +24 -4
  3. package/lib/api.js +114 -31
  4. package/lib/api.js.map +1 -1
  5. package/lib/constants.d.ts +9 -0
  6. package/lib/constants.js +14 -2
  7. package/lib/constants.js.map +1 -1
  8. package/lib/index.d.ts +2 -2
  9. package/lib/index.js +4 -3
  10. package/lib/index.js.map +1 -1
  11. package/lib/orders/constants.d.ts +2 -0
  12. package/lib/orders/constants.js +6 -0
  13. package/lib/orders/constants.js.map +1 -0
  14. package/lib/orders/privateListings.d.ts +4 -0
  15. package/lib/orders/privateListings.js +129 -0
  16. package/lib/orders/privateListings.js.map +1 -0
  17. package/lib/orders/schemas.d.ts +3 -0
  18. package/lib/orders/schemas.js +78 -0
  19. package/lib/orders/schemas.js.map +1 -0
  20. package/lib/orders/types.d.ts +97 -0
  21. package/lib/orders/types.js +3 -0
  22. package/lib/orders/types.js.map +1 -0
  23. package/lib/orders/utils.d.ts +23 -0
  24. package/lib/orders/utils.js +74 -0
  25. package/lib/orders/utils.js.map +1 -0
  26. package/lib/orders/validators.d.ts +0 -0
  27. package/lib/orders/validators.js +2 -0
  28. package/lib/orders/validators.js.map +1 -0
  29. package/lib/schemas.d.ts +9 -0
  30. package/lib/schemas.js +50 -0
  31. package/lib/schemas.js.map +1 -0
  32. package/lib/sdk.d.ts +928 -0
  33. package/lib/sdk.js +4204 -0
  34. package/lib/sdk.js.map +1 -0
  35. package/lib/seaport.d.ts +111 -8
  36. package/lib/seaport.js +518 -134
  37. package/lib/seaport.js.map +1 -1
  38. package/lib/types.d.ts +4 -3
  39. package/lib/types.js.map +1 -1
  40. package/lib/utils/utils.d.ts +9 -2
  41. package/lib/utils/utils.js +31 -12
  42. package/lib/utils/utils.js.map +1 -1
  43. package/package.json +7 -2
package/README.md CHANGED
@@ -20,11 +20,9 @@ Published on [GitHub](https://github.com/ProjectOpenSea/opensea-js) and [npm](ht
20
20
  - [Fetching Assets](#fetching-assets)
21
21
  - [Checking Balances and Ownerships](#checking-balances-and-ownerships)
22
22
  - [Making Offers](#making-offers)
23
- - [Bidding on Multiple Assets](#bidding-on-multiple-assets)
24
23
  - [Bidding on ENS Short Name Auctions](#bidding-on-ens-short-name-auctions)
25
24
  - [Offer Limits](#offer-limits)
26
25
  - [Making Listings / Selling Items](#making-listings--selling-items)
27
- - [Creating English Auctions](#creating-english-auctions)
28
26
  - [Running Crowdsales](#running-crowdsales)
29
27
  - [Fetching Orders](#fetching-orders)
30
28
  - [Buying Items](#buying-items)
@@ -34,7 +32,6 @@ Published on [GitHub](https://github.com/ProjectOpenSea/opensea-js) and [npm](ht
34
32
  - [Scheduling Future Listings](#scheduling-future-listings)
35
33
  - [Purchasing Items for Other Users](#purchasing-items-for-other-users)
36
34
  - [Bulk Transfers](#bulk-transfers)
37
- - [Creating Bundles](#creating-bundles)
38
35
  - [Using ERC-20 Tokens Instead of Ether](#using-erc-20-tokens-instead-of-ether)
39
36
  - [Private Auctions](#private-auctions)
40
37
  - [Sharing Sale Fees with OpenSea](#sharing-sale-fees-with-opensea)
@@ -50,9 +47,9 @@ Published on [GitHub](https://github.com/ProjectOpenSea/opensea-js) and [npm](ht
50
47
 
51
48
  This is the JavaScript SDK for [OpenSea](https://opensea.io), the largest marketplace for NFTs.
52
49
 
53
- It allows developers to access the official orderbook, filter it, create buy orders (**offers**), create sell orders (**auctions**), create collections of assets to sell at once (**bundles**), and complete trades programmatically.
50
+ It allows developers to access the official orderbook, filter it, create buy orders (**offers**), create sell orders (**auctions**), and complete trades programmatically.
54
51
 
55
- You get started by [requesting an API key](https://docs.opensea.io/reference) and instantiating your own seaport. Then you can create orders off-chain or fulfill orders on-chain, and listen to events (like `ApproveAllAssets` or `WrapEth`) in the process.
52
+ Get started by [requesting an API key](https://docs.opensea.io/reference) and instantiating your own OpenSea SDK instance. Then you can create orders off-chain or fulfill orders on-chain, and listen to events (like `ApproveAllAssets` or `WrapEth`) in the process.
56
53
 
57
54
  Happy seafaring! ⛵️
58
55
 
@@ -63,7 +60,7 @@ We recommend switching to Node.js version 16 to make sure common crypto dependen
63
60
  Then, in your project, run:
64
61
 
65
62
  ```bash
66
- npm install --save opensea-js
63
+ npm install --save opensea-js@beta
67
64
  ```
68
65
 
69
66
  Install [web3](https://github.com/ethereum/web3.js) too if you haven't already.
@@ -80,16 +77,16 @@ sudo npm explore npm -g -- npm install node-gyp@latest # (Optional) update node-
80
77
 
81
78
  To get started, first request an API key [here](https://docs.opensea.io/reference). Note the terms of use for using API data.
82
79
 
83
- Then, create a new OpenSeaJS client, called an OpenSeaPort 🚢, using your Web3 provider:
80
+ Then, create a new OpenSeaJS client, called an OpenSeaSDK 🚢, using your Web3 provider:
84
81
 
85
82
  ```JavaScript
86
83
  import * as Web3 from 'web3'
87
- import { OpenSeaPort, Network } from 'opensea-js'
84
+ import { OpenSeaSDK, Network } from 'opensea-js'
88
85
 
89
86
  // This example provider won't let you make transactions, only read-only calls:
90
87
  const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')
91
88
 
92
- const seaport = new OpenSeaPort(provider, {
89
+ const openseaSDK = new OpenSeaSDK(provider, {
93
90
  networkName: Network.Main,
94
91
  apiKey: YOUR_API_KEY
95
92
  })
@@ -128,7 +125,7 @@ The `Asset` type is the minimal type you need for most marketplace actions. `Wyv
128
125
  You can fetch an asset using the `OpenSeaAPI`, which will return an `OpenSeaAsset` for you (`OpenSeaAsset` extends `Asset`):
129
126
 
130
127
  ```TypeScript
131
- const asset: OpenSeaAsset = await seaport.api.getAsset({
128
+ const asset: OpenSeaAsset = await openseaSDK.api.getAsset({
132
129
  tokenAddress, // string
133
130
  tokenId, // string | number | null
134
131
  })
@@ -149,7 +146,7 @@ const asset = {
149
146
  tokenId: "1", // Token ID
150
147
  }
151
148
 
152
- const balance = await seaport.getAssetBalance({
149
+ const balance = await openseaSDK.getAssetBalance({
153
150
  accountAddress, // string
154
151
  asset, // Asset
155
152
  })
@@ -160,7 +157,7 @@ const ownsKitty = balance.greaterThan(0)
160
157
  You can use this same method for fungible ERC-20 tokens like wrapped ETH (WETH). As a convenience, you can use this fungible wrapper for checking fungible balances:
161
158
 
162
159
  ```JavaScript
163
- const balanceOfWETH = await seaport.getTokenBalance({
160
+ const balanceOfWETH = await openseaSDK.getTokenBalance({
164
161
  accountAddress, // string
165
162
  tokenAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
166
163
  })
@@ -176,7 +173,7 @@ const { tokenId, tokenAddress } = YOUR_ASSET
176
173
  // The offerer's wallet address:
177
174
  const accountAddress = "0x1234..."
178
175
 
179
- const offer = await seaport.createBuyOrder({
176
+ const offer = await openseaSDK.createBuyOrder({
180
177
  asset: {
181
178
  tokenId,
182
179
  tokenAddress,
@@ -190,23 +187,6 @@ const offer = await seaport.createBuyOrder({
190
187
 
191
188
  When you make an offer on an item owned by an OpenSea user, **that user will automatically get an email notifying them with the offer amount**, if it's above their desired threshold.
192
189
 
193
- #### Bidding on Multiple Assets
194
-
195
- You can also make an offer on a bundle of assets. This could also be used for creating a bounty for whoever can acquire a list of items. Here's how you do it:
196
-
197
- ```JavaScript
198
- const assets = YOUR_ASSETS
199
- const offer = await seaport.createBundleBuyOrder({
200
- assets,
201
- accountAddress,
202
- startAmount: 2.4,
203
- // Optional expiration time for the order, in Unix time (seconds):
204
- expirationTime: Math.round(Date.now() / 1000 + 60 * 60 * 24) // One day from now
205
- })
206
- ```
207
-
208
- When you bid on multiple assets, an email will be sent to the owner if a bundle exists on OpenSea that contains the assets. In the future, OpenSea will send emails to multiple owners if the assets aren't all owned by the same wallet.
209
-
210
190
  #### Bidding on ENS Short Name Auctions
211
191
 
212
192
  The Ethereum Name Service (ENS) is auctioning short (3-6 character) names that can be used for labeling wallet addresses and more. Learn more on the [ENS FAQ](https://opensea.io/ens).
@@ -220,9 +200,9 @@ const {
220
200
  tokenAddress,
221
201
  // Name must have `.eth` at the end and correspond with the tokenId
222
202
  name
223
- } = ENS_ASSET // You can get an ENS asset from `seaport.api.getAsset(...)`
203
+ } = ENS_ASSET // You can get an ENS asset from `openseaSDK.api.getAsset(...)`
224
204
 
225
- const offer = await seaport.createBuyOrder({
205
+ const offer = await openseaSDK.createBuyOrder({
226
206
  asset: {
227
207
  tokenId,
228
208
  tokenAddress,
@@ -251,7 +231,7 @@ To sell an asset, call `createSellOrder`. You can do a fixed-price listing, wher
251
231
  // Note that we convert from the JavaScript timestamp (milliseconds):
252
232
  const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
253
233
 
254
- const listing = await seaport.createSellOrder({
234
+ const listing = await openseaSDK.createSellOrder({
255
235
  asset: {
256
236
  tokenId,
257
237
  tokenAddress,
@@ -281,7 +261,7 @@ const paymentTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
281
261
 
282
262
  const startAmount = 0 // The minimum amount to sell for, in normal units (e.g. ETH)
283
263
 
284
- const auction = await seaport.createSellOrder({
264
+ const auction = await openseaSDK.createSellOrder({
285
265
  asset: {
286
266
  tokenId,
287
267
  tokenAddress,
@@ -308,7 +288,7 @@ Then call `createFactorySellOrders` with your factory contract address and asset
308
288
  // Expire these auctions one day from now
309
289
  const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
310
290
 
311
- const sellOrders = await seaport.createFactorySellOrders({
291
+ const sellOrders = await openseaSDK.createFactorySellOrders({
312
292
  assetId: ASSET_OPTION_ID,
313
293
  factoryAddress: FACTORY_CONTRACT_ADDRESS,
314
294
  accountAddress,
@@ -322,7 +302,7 @@ const sellOrders = await seaport.createFactorySellOrders({
322
302
 
323
303
  Here's an [example script](https://github.com/ProjectOpenSea/opensea-creatures/blob/master/scripts/sell.js) you can use to mint items.
324
304
 
325
- **NOTE:** If `numberOfOrders` is greater than 5, we will automatically batch them in groups of 5 so you can post orders in parallel. Requires an `apiKey` to be set during seaport initialization in order to not be throttled by the API.
305
+ **NOTE:** If `numberOfOrders` is greater than 5, we will automatically batch them in groups of 5 so you can post orders in parallel. Requires an `apiKey` to be set during SDK initialization in order to not be throttled by the API.
326
306
 
327
307
  Games using this method include [Coins & Steel](https://opensea.io/assets/coins&steelfounderssale) and a couple in stealth :) If you have questions or want support, contact us at contact@opensea.io (or in [Discord](https://discord.gg/ga8EJbv)).
328
308
 
@@ -334,14 +314,14 @@ To retrieve a list of offers and auction on an asset, you can use an instance of
334
314
  import { OrderSide } from 'opensea-js/lib/types'
335
315
 
336
316
  // Get offers (bids), a.k.a. orders where `side == 0`
337
- const { orders, count } = await seaport.api.getOrders({
317
+ const { orders, count } = await openseaSDK.api.getOrders({
338
318
  asset_contract_address: tokenAddress,
339
319
  token_id: token_id,
340
320
  side: OrderSide.Buy
341
321
  })
342
322
 
343
323
  // Get page 2 of all auctions, a.k.a. orders where `side == 1`
344
- const { orders, count } = await seaport.api.getOrders({
324
+ const { orders, count } = await openseaSDK.api.getOrders({
345
325
  asset_contract_address: tokenAddress,
346
326
  token_id: token_id,
347
327
  side: OrderSide.Sell
@@ -380,9 +360,9 @@ The available API filters for the orders endpoint is documented in the `OrderJSO
380
360
  To buy an item , you need to **fulfill a sell order**. To do that, it's just one call:
381
361
 
382
362
  ```JavaScript
383
- const order = await seaport.api.getOrder({ side: OrderSide.Sell, ... })
363
+ const order = await openseaSDK.api.getOrder({ side: OrderSide.Sell, ... })
384
364
  const accountAddress = "0x..." // The buyer's wallet address, also the taker
385
- const transactionHash = await this.props.seaport.fulfillOrder({ order, accountAddress })
365
+ const transactionHash = await this.props.openseaSDK.fulfillOrder({ order, accountAddress })
386
366
  ```
387
367
 
388
368
  Note that the `fulfillOrder` promise resolves when the transaction has been confirmed and mined to the blockchain. To get the transaction hash before this happens, add an event listener (see [Listening to Events](#listening-to-events)) for the `TransactionCreated` event.
@@ -394,9 +374,9 @@ If the order is a sell order (`order.side === OrderSide.Sell`), the taker is the
394
374
  Similar to fulfilling sell orders above, you need to fulfill a buy order on an item you own to receive the tokens in the offer.
395
375
 
396
376
  ```JavaScript
397
- const order = await seaport.api.getOrder({ side: OrderSide.Buy, ... })
377
+ const order = await openseaSDK.api.getOrder({ side: OrderSide.Buy, ... })
398
378
  const accountAddress = "0x..." // The owner's wallet address, also the taker
399
- await this.props.seaport.fulfillOrder({ order, accountAddress })
379
+ await this.props.openseaSDK.fulfillOrder({ order, accountAddress })
400
380
  ```
401
381
 
402
382
  If the order is a buy order (`order.side === OrderSide.Buy`), then the taker is the _owner_ and this will prompt the owner to exchange their item(s) for whatever is being offered in return. See [Listening to Events](#listening-to-events) below to respond to the setup transactions that occur the first time a user accepts a bid.
@@ -409,7 +389,7 @@ To transfer an ERC-721 asset or an ERC-1155 asset, it's just one call:
409
389
 
410
390
  ```JavaScript
411
391
 
412
- const transactionHash = await seaport.transfer({
392
+ const transactionHash = await openseaSDK.transfer({
413
393
  asset: { tokenId, tokenAddress },
414
394
  fromAddress, // Must own the asset
415
395
  toAddress
@@ -420,7 +400,7 @@ For fungible ERC-1155 assets, you can set `schemaName` to "ERC1155" and pass a `
420
400
 
421
401
  ```JavaScript
422
402
 
423
- const transactionHash = await seaport.transfer({
403
+ const transactionHash = await openseaSDK.transfer({
424
404
  asset: {
425
405
  tokenId,
426
406
  tokenAddress,
@@ -437,9 +417,9 @@ To transfer fungible assets without token IDs, like ERC20 tokens, you can pass i
437
417
  Example for transfering 2 DAI ($2) to another address:
438
418
 
439
419
  ```JavaScript
440
- const paymentToken = (await seaport.api.getPaymentTokens({ symbol: 'DAI'})).tokens[0]
420
+ const paymentToken = (await openseaSDK.api.getPaymentTokens({ symbol: 'DAI'})).tokens[0]
441
421
  const quantity = new BigNumber(Math.pow(10, paymentToken.decimals)).times(2)
442
- const transactionHash = await seaport.transfer({
422
+ const transactionHash = await openseaSDK.transfer({
443
423
  asset: {
444
424
  tokenId: null,
445
425
  tokenAddress: paymentToken.address,
@@ -455,14 +435,14 @@ For more information, check out the documentation for WyvernSchemas on https://p
455
435
 
456
436
  ## Advanced
457
437
 
458
- Interested in purchasing for users server-side or with a bot, making bundling items together, scheduling future orders, or making bids in different ERC-20 tokens? OpenSea.js can help with that.
438
+ Interested in purchasing for users server-side or with a bot, scheduling future orders, or making bids in different ERC-20 tokens? OpenSea.js can help with that.
459
439
 
460
440
  ### Scheduling Future Listings
461
441
 
462
- You can create sell orders that aren't fulfillable until a future date. Just pass in a `listingTime` (a UTC timestamp in seconds) to your seaport instance:
442
+ You can create sell orders that aren't fulfillable until a future date. Just pass in a `listingTime` (a UTC timestamp in seconds) to your SDK instance:
463
443
 
464
444
  ```JavaScript
465
- const auction = await seaport.createSellOrder({
445
+ const auction = await openseaSDK.createSellOrder({
466
446
  tokenAddress,
467
447
  tokenId,
468
448
  accountAddress,
@@ -476,8 +456,8 @@ const auction = await seaport.createSellOrder({
476
456
  You can buy and transfer an item to someone else in one step! Just pass the `recipientAddress` parameter:
477
457
 
478
458
  ```JavaScript
479
- const order = await seaport.api.getOrder({ side: OrderSide.Sell, ... })
480
- await this.props.seaport.fulfillOrder({
459
+ const order = await openseaSDK.api.getOrder({ side: OrderSide.Sell, ... })
460
+ await this.props.openseaSDK.fulfillOrder({
481
461
  order,
482
462
  accountAddress, // The address of your wallet, which will sign the transaction
483
463
  recipientAddress // The address of the recipient, i.e. the wallet you're purchasing on behalf of
@@ -495,7 +475,7 @@ To make a bulk transfer, it's just one call:
495
475
  ```JavaScript
496
476
  const assets: Array<{tokenId: string; tokenAddress: string}> = [...]
497
477
 
498
- const transactionHash = await seaport.transferAll({
478
+ const transactionHash = await openseaSDK.transferAll({
499
479
  assets,
500
480
  fromAddress, // Must own all the assets
501
481
  toAddress
@@ -504,28 +484,6 @@ const transactionHash = await seaport.transferAll({
504
484
 
505
485
  This will automatically approve the assets for trading and confirm the transaction for sending them.
506
486
 
507
- ### Creating Bundles
508
-
509
- You can also create bundles of assets to sell at the same time! If the owner has approved all the assets in the bundle already, only a signature is needed to create it.
510
-
511
- To make a bundle, it's just one call:
512
-
513
- ```JavaScript
514
- const assets: Array<{tokenId: string; tokenAddress: string}> = [...]
515
-
516
- const bundle = await seaport.createBundleSellOrder({
517
- bundleName, bundleDescription, bundleExternalLink,
518
- assets, accountAddress, startAmount, endAmount,
519
- expirationTime, paymentTokenAddress
520
- })
521
- ```
522
-
523
- The parameters `bundleDescription`, `bundleExternalLink`, and `expirationTime` are optional, and `endAmount` can equal `startAmount`, similar to the normal `createSellOrder` functionality.
524
-
525
- The parameter `paymentTokenAddress` is the address of the ERC-20 token to accept in return. If it's `undefined` or `null`, the amount is assumed to be in Ether.
526
-
527
- Wait what, you can use other currencies than ETH?
528
-
529
487
  ### Using ERC-20 Tokens Instead of Ether
530
488
 
531
489
  Here's an example of listing the Genesis CryptoKitty for $100! No more needing to worry about the exchange rate:
@@ -535,7 +493,7 @@ Here's an example of listing the Genesis CryptoKitty for $100! No more needing t
535
493
  const paymentTokenAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359"
536
494
 
537
495
  // The units for `startAmount` and `endAmount` are now in DAI, so $100 USD
538
- const auction = await seaport.createSellOrder({
496
+ const auction = await openseaSDK.createSellOrder({
539
497
  tokenAddress: "0x06012c8cf97bead5deae237070f9587f8e7a266d", // CryptoKitties
540
498
  tokenId: "1", // Token ID
541
499
  accountAddress: OWNERS_WALLET_ADDRESS,
@@ -547,9 +505,9 @@ const auction = await seaport.createSellOrder({
547
505
  You can use `getPaymentTokens` to search for tokens by symbol name. And you can even list all orders for a specific ERC-20 token by querying the API:
548
506
 
549
507
  ```JavaScript
550
- const token = (await seaport.api.getPaymentTokens({ symbol: 'MANA'})).tokens[0]
508
+ const token = (await openseaSDK.api.getPaymentTokens({ symbol: 'MANA'})).tokens[0]
551
509
 
552
- const order = await seaport.api.getOrders({
510
+ const order = await openseaSDK.api.getOrders({
553
511
  side: OrderSide.Sell,
554
512
  payment_token_address: token.address
555
513
  })
@@ -571,7 +529,7 @@ Here's an example of listing a Decentraland parcel for 10 ETH with a specific bu
571
529
  // Address allowed to buy from you
572
530
  const buyerAddress = "0x123..."
573
531
 
574
- const listing = await seaport.createSellOrder({
532
+ const listing = await openseaSDK.createSellOrder({
575
533
  tokenAddress: "0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d", // Decentraland
576
534
  tokenId: "115792089237316195423570985008687907832853042650384256231655107562007036952461", // Token ID
577
535
  accountAddress: OWNERS_WALLET_ADDRESS,
@@ -597,68 +555,68 @@ Our recommendation is that you "forward" OpenSea events to your own store or sta
597
555
  ```JavaScript
598
556
  import { EventType } from 'opensea-js'
599
557
  import * as ActionTypes from './index'
600
- import { openSeaPort } from '../globalSingletons'
558
+ import { openSeaSDK } from '../globalSingletons'
601
559
 
602
560
  // ...
603
561
 
604
- handleSeaportEvents() {
562
+ handleSDKEvents() {
605
563
  return async function(dispatch, getState) {
606
- openSeaPort.addListener(EventType.TransactionCreated, ({ transactionHash, event }) => {
564
+ openSeaSDK.addListener(EventType.TransactionCreated, ({ transactionHash, event }) => {
607
565
  console.info({ transactionHash, event })
608
566
  dispatch({ type: ActionTypes.SET_PENDING_TRANSACTION_HASH, hash: transactionHash })
609
567
  })
610
- openSeaPort.addListener(EventType.TransactionConfirmed, ({ transactionHash, event }) => {
568
+ openSeaSDK.addListener(EventType.TransactionConfirmed, ({ transactionHash, event }) => {
611
569
  console.info({ transactionHash, event })
612
570
  // Only reset your exchange UI if we're finishing an order fulfillment or cancellation
613
571
  if (event == EventType.MatchOrders || event == EventType.CancelOrder) {
614
572
  dispatch({ type: ActionTypes.RESET_EXCHANGE })
615
573
  }
616
574
  })
617
- openSeaPort.addListener(EventType.TransactionDenied, ({ transactionHash, event }) => {
575
+ openSeaSDK.addListener(EventType.TransactionDenied, ({ transactionHash, event }) => {
618
576
  console.info({ transactionHash, event })
619
577
  dispatch({ type: ActionTypes.RESET_EXCHANGE })
620
578
  })
621
- openSeaPort.addListener(EventType.TransactionFailed, ({ transactionHash, event }) => {
579
+ openSeaSDK.addListener(EventType.TransactionFailed, ({ transactionHash, event }) => {
622
580
  console.info({ transactionHash, event })
623
581
  dispatch({ type: ActionTypes.RESET_EXCHANGE })
624
582
  })
625
- openSeaPort.addListener(EventType.InitializeAccount, ({ accountAddress }) => {
583
+ openSeaSDK.addListener(EventType.InitializeAccount, ({ accountAddress }) => {
626
584
  console.info({ accountAddress })
627
585
  dispatch({ type: ActionTypes.INITIALIZE_PROXY })
628
586
  })
629
- openSeaPort.addListener(EventType.WrapEth, ({ accountAddress, amount }) => {
587
+ openSeaSDK.addListener(EventType.WrapEth, ({ accountAddress, amount }) => {
630
588
  console.info({ accountAddress, amount })
631
589
  dispatch({ type: ActionTypes.WRAP_ETH })
632
590
  })
633
- openSeaPort.addListener(EventType.UnwrapWeth, ({ accountAddress, amount }) => {
591
+ openSeaSDK.addListener(EventType.UnwrapWeth, ({ accountAddress, amount }) => {
634
592
  console.info({ accountAddress, amount })
635
593
  dispatch({ type: ActionTypes.UNWRAP_WETH })
636
594
  })
637
- openSeaPort.addListener(EventType.ApproveCurrency, ({ accountAddress, tokenAddress }) => {
595
+ openSeaSDK.addListener(EventType.ApproveCurrency, ({ accountAddress, tokenAddress }) => {
638
596
  console.info({ accountAddress, tokenAddress })
639
597
  dispatch({ type: ActionTypes.APPROVE_WETH })
640
598
  })
641
- openSeaPort.addListener(EventType.ApproveAllAssets, ({ accountAddress, proxyAddress, tokenAddress }) => {
599
+ openSeaSDK.addListener(EventType.ApproveAllAssets, ({ accountAddress, proxyAddress, tokenAddress }) => {
642
600
  console.info({ accountAddress, proxyAddress, tokenAddress })
643
601
  dispatch({ type: ActionTypes.APPROVE_ALL_ASSETS })
644
602
  })
645
- openSeaPort.addListener(EventType.ApproveAsset, ({ accountAddress, proxyAddress, tokenAddress, tokenId }) => {
603
+ openSeaSDK.addListener(EventType.ApproveAsset, ({ accountAddress, proxyAddress, tokenAddress, tokenId }) => {
646
604
  console.info({ accountAddress, proxyAddress, tokenAddress, tokenId })
647
605
  dispatch({ type: ActionTypes.APPROVE_ASSET })
648
606
  })
649
- openSeaPort.addListener(EventType.CreateOrder, ({ order, accountAddress }) => {
607
+ openSeaSDK.addListener(EventType.CreateOrder, ({ order, accountAddress }) => {
650
608
  console.info({ order, accountAddress })
651
609
  dispatch({ type: ActionTypes.CREATE_ORDER })
652
610
  })
653
- openSeaPort.addListener(EventType.OrderDenied, ({ order, accountAddress }) => {
611
+ openSeaSDK.addListener(EventType.OrderDenied, ({ order, accountAddress }) => {
654
612
  console.info({ order, accountAddress })
655
613
  dispatch({ type: ActionTypes.RESET_EXCHANGE })
656
614
  })
657
- openSeaPort.addListener(EventType.MatchOrders, ({ buy, sell, accountAddress }) => {
615
+ openSeaSDK.addListener(EventType.MatchOrders, ({ buy, sell, accountAddress }) => {
658
616
  console.info({ buy, sell, accountAddress })
659
617
  dispatch({ type: ActionTypes.FULFILL_ORDER })
660
618
  })
661
- openSeaPort.addListener(EventType.CancelOrder, ({ order, accountAddress }) => {
619
+ openSeaSDK.addListener(EventType.CancelOrder, ({ order, accountAddress }) => {
662
620
  console.info({ order, accountAddress })
663
621
  dispatch({ type: ActionTypes.CANCEL_ORDER })
664
622
  })
@@ -666,7 +624,7 @@ handleSeaportEvents() {
666
624
  }
667
625
  ```
668
626
 
669
- To remove all listeners and start over, just call `seaport.removeAllListeners()`.
627
+ To remove all listeners and start over, just call `openseaSDK.removeAllListeners()`.
670
628
 
671
629
  ## Learning More
672
630
 
package/lib/api.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import "isomorphic-unfetch";
2
+ import { OrderAPIOptions, OrdersQueryOptions, OrderV2, ProtocolData, QueryCursors } from "./orders/types";
2
3
  import { OpenSeaAPIConfig, OpenSeaAsset, OpenSeaAssetBundle, OpenSeaAssetBundleQuery, OpenSeaAssetQuery, OpenSeaFungibleToken, OpenSeaFungibleTokenQuery, Order, OrderJSON, OrderQuery } from "./types";
3
4
  export declare class OpenSeaAPI {
4
5
  /**
@@ -18,12 +19,31 @@ export declare class OpenSeaAPI {
18
19
  */
19
20
  logger: (arg: string) => void;
20
21
  private apiKey;
22
+ private networkName;
23
+ private retryDelay;
21
24
  /**
22
25
  * Create an instance of the OpenSea API
23
26
  * @param config OpenSeaAPIConfig for setting up the API, including an optional API key, network name, and base URL
24
27
  * @param logger Optional function for logging debug strings before and after requests are made
25
28
  */
26
29
  constructor(config: OpenSeaAPIConfig, logger?: (arg: string) => void);
30
+ /**
31
+ * Gets an order from API based on query options. Throws when no order is found.
32
+ */
33
+ getOrder({ protocol, side, orderDirection, orderBy, ...restOptions }: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2>;
34
+ /**
35
+ * Gets a list of orders from API based on query options and returns orders
36
+ * with next and previous cursors.
37
+ */
38
+ getOrders({ protocol, side, orderDirection, orderBy, ...restOptions }: Omit<OrdersQueryOptions, "limit">): Promise<QueryCursors & {
39
+ orders: OrderV2[];
40
+ }>;
41
+ /**
42
+ * Send an order to be posted. Throws when the order is invalid.
43
+ */
44
+ postOrder(order: ProtocolData, apiOptions: OrderAPIOptions, { retries }?: {
45
+ retries?: number;
46
+ }): Promise<OrderV2>;
27
47
  /**
28
48
  * Send an order to the orderbook.
29
49
  * Throws when the order is invalid.
@@ -31,7 +51,7 @@ export declare class OpenSeaAPI {
31
51
  * @param order Order JSON to post to the orderbook
32
52
  * @param retries Number of times to retry if the service is unavailable for any reason
33
53
  */
34
- postOrder(order: OrderJSON, retries?: number): Promise<Order>;
54
+ postOrderLegacyWyvern(order: OrderJSON, retries?: number): Promise<Order>;
35
55
  /**
36
56
  * Create a whitelist entry for an asset to prevent others from buying.
37
57
  * Buyers will have to have verified at least one of the emails
@@ -48,11 +68,11 @@ export declare class OpenSeaAPI {
48
68
  */
49
69
  getOrderCreateWyvernExchangeAddress(): Promise<string | null>;
50
70
  /**
51
- * Get an order from the orderbook, throwing if none is found.
71
+ * Get an order from the orderbook using the legacy wyvern API, throwing if none is found.
52
72
  * @param query Query to use for getting orders. A subset of parameters
53
73
  * on the `OrderJSON` type is supported
54
74
  */
55
- getOrder(query: OrderQuery): Promise<Order>;
75
+ getOrderLegacyWyvern(query: OrderQuery): Promise<Order>;
56
76
  /**
57
77
  * Get a list of orders from the orderbook, returning the page of orders
58
78
  * and the count of total orders found.
@@ -61,7 +81,7 @@ export declare class OpenSeaAPI {
61
81
  * @param page Page number, defaults to 1. Can be overridden by
62
82
  * `limit` and `offset` attributes from OrderQuery
63
83
  */
64
- getOrders(query?: OrderQuery, page?: number): Promise<{
84
+ getOrdersLegacyWyvern(query?: OrderQuery, page?: number): Promise<{
65
85
  orders: Order[];
66
86
  count: number;
67
87
  }>;