opensea-js 5.0.2 → 6.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 (111) hide show
  1. package/README.md +104 -140
  2. package/lib/__integration_tests__/getAsset.d.ts +1 -0
  3. package/lib/__integration_tests__/getAsset.js +64 -0
  4. package/lib/__integration_tests__/getAsset.js.map +1 -0
  5. package/lib/__integration_tests__/getCollection.d.ts +1 -0
  6. package/lib/__integration_tests__/getCollection.js +63 -0
  7. package/lib/__integration_tests__/getCollection.js.map +1 -0
  8. package/lib/__integration_tests__/init.d.ts +6 -0
  9. package/lib/__integration_tests__/init.js +23 -0
  10. package/lib/__integration_tests__/init.js.map +1 -0
  11. package/lib/__integration_tests__/postOrder.js +31 -23
  12. package/lib/__integration_tests__/postOrder.js.map +1 -1
  13. package/lib/__integration_tests__/wrapEth.d.ts +1 -0
  14. package/lib/__integration_tests__/wrapEth.js +57 -0
  15. package/lib/__integration_tests__/wrapEth.js.map +1 -0
  16. package/lib/__tests__/constants.d.ts +0 -1
  17. package/lib/__tests__/constants.js +1 -2
  18. package/lib/__tests__/constants.js.map +1 -1
  19. package/lib/api.d.ts +3 -20
  20. package/lib/api.js +216 -447
  21. package/lib/api.js.map +1 -1
  22. package/lib/bundle.js +61128 -0
  23. package/lib/constants.d.ts +3 -31
  24. package/lib/constants.js +15 -48
  25. package/lib/constants.js.map +1 -1
  26. package/lib/index.d.ts +6 -8
  27. package/lib/index.js +5 -10
  28. package/lib/index.js.map +1 -1
  29. package/lib/orders/privateListings.js +27 -54
  30. package/lib/orders/privateListings.js.map +1 -1
  31. package/lib/orders/types.d.ts +3 -2
  32. package/lib/orders/utils.d.ts +4 -4
  33. package/lib/orders/utils.js +42 -49
  34. package/lib/orders/utils.js.map +1 -1
  35. package/lib/sdk.d.ts +39 -412
  36. package/lib/sdk.js +495 -2259
  37. package/lib/sdk.js.map +1 -1
  38. package/lib/typechain/contracts/ERC1155.d.ts +1602 -0
  39. package/lib/typechain/contracts/ERC1155.js +3 -0
  40. package/lib/typechain/contracts/ERC1155.js.map +1 -0
  41. package/lib/typechain/contracts/ERC1155Abi.d.ts +5 -5
  42. package/lib/typechain/contracts/ERC20.d.ts +164 -0
  43. package/lib/typechain/contracts/ERC20.js +3 -0
  44. package/lib/typechain/contracts/ERC20.js.map +1 -0
  45. package/lib/typechain/contracts/ERC721.d.ts +289 -0
  46. package/lib/typechain/contracts/ERC721.js +3 -0
  47. package/lib/typechain/contracts/ERC721.js.map +1 -0
  48. package/lib/typechain/contracts/ERC721v3Abi.d.ts +5 -5
  49. package/lib/typechain/contracts/UniswapExchangeAbi.d.ts +5 -5
  50. package/lib/typechain/contracts/UniswapFactoryAbi.d.ts +5 -5
  51. package/lib/typechain/contracts/WrappedNFTAbi.d.ts +5 -5
  52. package/lib/typechain/contracts/WrappedNFTFactoryAbi.d.ts +5 -5
  53. package/lib/typechain/contracts/common.d.ts +21 -0
  54. package/lib/typechain/contracts/common.js +3 -0
  55. package/lib/typechain/contracts/common.js.map +1 -0
  56. package/lib/typechain/contracts/factories/ERC1155__factory.d.ts +1792 -0
  57. package/lib/typechain/contracts/factories/ERC1155__factory.js +2364 -0
  58. package/lib/typechain/contracts/factories/ERC1155__factory.js.map +1 -0
  59. package/lib/typechain/contracts/factories/ERC20__factory.d.ts +175 -0
  60. package/lib/typechain/contracts/factories/ERC20__factory.js +240 -0
  61. package/lib/typechain/contracts/factories/ERC20__factory.js.map +1 -0
  62. package/lib/typechain/contracts/factories/ERC721__factory.d.ts +362 -0
  63. package/lib/typechain/contracts/factories/ERC721__factory.js +488 -0
  64. package/lib/typechain/contracts/factories/ERC721__factory.js.map +1 -0
  65. package/lib/typechain/contracts/factories/index.d.ts +3 -0
  66. package/lib/typechain/contracts/factories/index.js +13 -0
  67. package/lib/typechain/contracts/factories/index.js.map +1 -0
  68. package/lib/typechain/contracts/index.d.ts +7 -0
  69. package/lib/typechain/contracts/index.js +11 -0
  70. package/lib/typechain/contracts/index.js.map +1 -0
  71. package/lib/typechain/contracts/types.d.ts +4 -4
  72. package/lib/types.d.ts +119 -182
  73. package/lib/types.js +31 -81
  74. package/lib/types.js.map +1 -1
  75. package/lib/utils/index.d.ts +0 -1
  76. package/lib/utils/index.js +0 -1
  77. package/lib/utils/index.js.map +1 -1
  78. package/lib/utils/tokens/index.d.ts +2 -3
  79. package/lib/utils/tokens/index.js +9 -24
  80. package/lib/utils/tokens/index.js.map +1 -1
  81. package/lib/utils/tokens/main.js +1 -5300
  82. package/lib/utils/tokens/main.js.map +1 -1
  83. package/lib/utils/utils.d.ts +14 -147
  84. package/lib/utils/utils.js +87 -960
  85. package/lib/utils/utils.js.map +1 -1
  86. package/package.json +27 -41
  87. package/src/abi/ERC1155.json +2346 -0
  88. package/src/abi/ERC20.json +222 -0
  89. package/src/abi/ERC721.json +470 -0
  90. package/src/api.ts +525 -0
  91. package/src/constants.ts +29 -0
  92. package/src/index.ts +30 -0
  93. package/src/orders/privateListings.ts +145 -0
  94. package/src/orders/types.ts +168 -0
  95. package/src/orders/utils.ts +170 -0
  96. package/src/sdk.ts +1036 -0
  97. package/src/typechain/contracts/ERC1155.ts +3976 -0
  98. package/src/typechain/contracts/ERC20.ts +367 -0
  99. package/src/typechain/contracts/ERC721.ts +811 -0
  100. package/src/typechain/contracts/common.ts +44 -0
  101. package/src/typechain/contracts/factories/ERC1155__factory.ts +2367 -0
  102. package/src/typechain/contracts/factories/ERC20__factory.ts +240 -0
  103. package/src/typechain/contracts/factories/ERC721__factory.ts +488 -0
  104. package/src/typechain/contracts/factories/index.ts +6 -0
  105. package/src/typechain/contracts/index.ts +10 -0
  106. package/src/types.ts +742 -0
  107. package/src/utils/index.ts +1 -0
  108. package/src/utils/tokens/goerli.ts +11 -0
  109. package/src/utils/tokens/index.ts +29 -0
  110. package/src/utils/tokens/main.ts +11 -0
  111. package/src/utils/utils.ts +379 -0
package/README.md CHANGED
@@ -12,9 +12,7 @@
12
12
  [![Docs][docs-badge]][docs-link]
13
13
  [![Discussions][discussions-badge]][discussions-link]
14
14
 
15
- A JavaScript library for crypto-native ecommerce: buying, selling, and bidding on any cryptogood. With OpenSea.js, you can easily build your own native marketplace for your non-fungible tokens, or NFTs. These can be ERC-721 or ERC-1155 (semi-fungible) items. You don't have to deploy your own smart contracts or backend orderbooks.
16
-
17
- Published on [GitHub](https://github.com/ProjectOpenSea/opensea-js) and [npm](https://www.npmjs.com/package/opensea-js)
15
+ A JavaScript library for crypto-native e-commerce: buying, selling, and bidding on NFTs (non-fungible tokens). With OpenSea.js, you can easily build your own native marketplace. These can be ERC-721 or ERC-1155 (semi-fungible) items. You don't have to deploy your own smart contracts or manage backend orderbooks.
18
16
 
19
17
  - [Synopsis](#synopsis)
20
18
  - [Installation](#installation)
@@ -37,7 +35,7 @@ Published on [GitHub](https://github.com/ProjectOpenSea/opensea-js) and [npm](ht
37
35
  - [Private Auctions](#private-auctions)
38
36
  - [Listening to Events](#listening-to-events)
39
37
  - [Learning More](#learning-more)
40
- - [Migrating to version 1.0](#migrating-to-version-10)
38
+ - [Changelog](#changelog)
41
39
  - [Development Information](#development-information)
42
40
  - [Diagnosing Common Issues](#diagnosing-common-issues)
43
41
  - [Testing your branch locally](#testing-your-branch-locally)
@@ -60,46 +58,36 @@ Then, in your project, run:
60
58
 
61
59
  ```bash
62
60
  npm install --save opensea-js
63
- ```
64
-
65
- > **Warning**
66
- > Due to the use of git-url dependencies, versions of `npm` below 8.5.2 are incompatible with this package due to broken integrity checksum validation.
67
- > Above version 8.5.2, `npm` will no longer validate integrity checksums for git-url dependencies.
68
-
69
- Install [web3](https://github.com/ethereum/web3.js) too if you haven't already.
70
-
71
- If you run into an error while building the dependencies and you're on a Mac, run this:
72
-
73
- ```bash
74
- xcode-select --install # Install Command Line Tools if you haven't already.
75
- sudo xcode-select --switch /Library/Developer/CommandLineTools # Enable command line tools
76
- sudo npm explore npm -g -- npm install node-gyp@latest # (Optional) update node-gyp
61
+ # or
62
+ yarn add opensea-js
77
63
  ```
78
64
 
79
65
  ## Getting Started
80
66
 
81
67
  To get started, first request an API key [here](https://docs.opensea.io/reference). Note the terms of use for using API data.
82
68
 
83
- Then, create a new OpenSeaJS client, called an OpenSeaSDK 🚢, using your Web3 provider:
69
+ Then, create a new OpenSeaJS client, called an OpenSeaSDK 🚢, using your web3 provider:
84
70
 
85
- ```JavaScript
86
- import * as Web3 from 'web3'
87
- import { OpenSeaSDK, Network } from 'opensea-js'
71
+ ```typescript
72
+ import { ethers } from "ethers";
73
+ import { OpenSeaSDK, Chain } from "opensea-js";
88
74
 
89
75
  // This example provider won't let you make transactions, only read-only calls:
90
- const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')
76
+ const provider = new ethers.providers.JsonRpcProvider(
77
+ "https://mainnet.infura.io"
78
+ );
91
79
 
92
80
  const openseaSDK = new OpenSeaSDK(provider, {
93
- networkName: Network.Main,
94
- apiKey: YOUR_API_KEY
95
- })
81
+ chain: Chain.Mainnet,
82
+ apiKey: YOUR_API_KEY,
83
+ });
96
84
  ```
97
85
 
98
- **NOTE:** for testnet, please use `Network.Goerli` as the `networkName` - Rinkeby was deprecated in 2022.
86
+ **NOTE:** For testnet, please use `Chain.Goerli` as the `chain`. Rinkeby was deprecated in 2022.
99
87
 
100
- **NOTE:** Using the sample Infura provider above won't let you authorize transactions, which are needed when approving and trading assets and currency. To make transactions, you need a provider with a private key or mnemonic set.
88
+ **NOTE:** Using the sample provider above won't let you authorize transactions, which are needed when approving and trading assets and currency. To make transactions, you need a provider with a private key or mnemonic set.
101
89
 
102
- In a browser with web3 or an extension like [MetaMask](https://metamask.io/) or [Dapper](http://www.meetdapper.com/), you can use `window.ethereum` (or `window.web3.currentProvider` for legacy mobile web3 browsers) to access the native provider. In a Node.js script, you can follow [this example](https://github.com/ProjectOpenSea/opensea-creatures/blob/master/scripts/sell.js) to use a custom mnemonic.
90
+ In a browser with web3 or an extension like [MetaMask](https://metamask.io/) or [Coinbase Wallet](https://www.coinbase.com/wallet), you can use `window.ethereum` to access the native provider.
103
91
 
104
92
  ### Fetching Assets
105
93
 
@@ -116,8 +104,8 @@ export interface Asset {
116
104
  tokenId: string | null,
117
105
  // The asset's contract address
118
106
  tokenAddress: string,
119
- // The Wyvern schema name (defaults to "ERC721") for this asset
120
- schemaName?: WyvernSchemaName,
107
+ // The schema name (defaults to "ERC721") for this asset
108
+ tokenStandard?: TokenStandard,
121
109
  // Optional for ENS names
122
110
  name?: string,
123
111
  // Optional for fungible items
@@ -125,14 +113,14 @@ export interface Asset {
125
113
  }
126
114
  ```
127
115
 
128
- The `Asset` type is the minimal type you need for most marketplace actions. `WyvernSchemaName` is optional. If omitted, most actions will assume you're referring to a non-fungible, ERC721 asset. Other options include 'ERC20' and 'ERC1155'. You can import `import { WyvernSchemaName } from "opensea-js/lib/types"` to get the full range of schemas supported.
116
+ The `Asset` type is the minimal type you need for most marketplace actions. `TokenStandard` is optional. If omitted, most actions will assume you're referring to a non-fungible, ERC721 asset. Other options include 'ERC20' and 'ERC1155'. You can import `import { TokenStandard } from "opensea-js/lib/types"` to get the full range of schemas supported.
129
117
 
130
118
  You can fetch an asset using the `OpenSeaAPI`, which will return an `OpenSeaAsset` for you (`OpenSeaAsset` extends `Asset`):
131
119
 
132
120
  ```TypeScript
133
121
  const asset: OpenSeaAsset = await openseaSDK.api.getAsset({
134
122
  tokenAddress, // string
135
- tokenId, // string | number | null
123
+ tokenId, // string | number | BigNumber | null
136
124
  })
137
125
  ```
138
126
 
@@ -144,50 +132,40 @@ The nice thing about the `Asset` type is that it unifies logic between fungibles
144
132
 
145
133
  Once you have an `Asset`, you can see how many any account owns, regardless of whether it's an ERC-20 token or a non-fungible good:
146
134
 
147
- ```JavaScript
148
-
135
+ ```typescript
149
136
  const asset = {
150
137
  tokenAddress: "0x06012c8cf97bead5deae237070f9587f8e7a266d", // CryptoKitties
151
138
  tokenId: "1", // Token ID
152
- }
139
+ };
153
140
 
154
- const balance = await openseaSDK.getAssetBalance({
141
+ const balance = await openseaSDK.getBalance({
155
142
  accountAddress, // string
156
143
  asset, // Asset
157
- })
144
+ });
158
145
 
159
- const ownsKitty = balance.greaterThan(0)
160
- ```
161
-
162
- 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:
163
-
164
- ```JavaScript
165
- const balanceOfWETH = await openseaSDK.getTokenBalance({
166
- accountAddress, // string
167
- tokenAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
168
- })
146
+ const ownsKitty = balance.greaterThan(0);
169
147
  ```
170
148
 
171
149
  ### Making Offers
172
150
 
173
151
  Once you have your asset, you can do this to make an offer on it:
174
152
 
175
- ```JavaScript
153
+ ```typescript
176
154
  // Token ID and smart contract address for a non-fungible token:
177
- const { tokenId, tokenAddress } = YOUR_ASSET
155
+ const { tokenId, tokenAddress } = YOUR_ASSET;
178
156
  // The offerer's wallet address:
179
- const accountAddress = "0x1234..."
157
+ const accountAddress = "0x1234...";
180
158
 
181
159
  const offer = await openseaSDK.createBuyOrder({
182
160
  asset: {
183
161
  tokenId,
184
162
  tokenAddress,
185
- schemaName // WyvernSchemaName. If omitted, defaults to 'ERC721'. Other options include 'ERC20' and 'ERC1155'
163
+ tokenStandard, // TokenStandard. If omitted, defaults to 'ERC721'. Other options include 'ERC20' and 'ERC1155'
186
164
  },
187
165
  accountAddress,
188
166
  // Value of the offer, in units of the payment token (or wrapped ETH if none is specified):
189
167
  startAmount: 1.2,
190
- })
168
+ });
191
169
  ```
192
170
 
193
171
  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.
@@ -198,7 +176,7 @@ The Ethereum Name Service (ENS) is auctioning short (3-6 character) names that c
198
176
 
199
177
  To bid, you must use the ENS Short Name schema:
200
178
 
201
- ```JavaScript
179
+ ```typescript
202
180
  const {
203
181
  tokenId,
204
182
  // Token address should be `0xfac7bea255a6990f749363002136af6556b31e04` on mainnet
@@ -214,7 +192,7 @@ const offer = await openseaSDK.createBuyOrder({
214
192
  name,
215
193
  // Only needed for the short-name auction, not ENS names
216
194
  // that have been sold once already:
217
- schemaName: "ENSShortNameAuction"
195
+ tokenStandard: "ENSShortNameAuction"
218
196
  },
219
197
  // Your wallet address (the bidder's address):
220
198
  accountAddress: "0x1234..."
@@ -231,10 +209,10 @@ Note: The total value of buy orders must not exceed 1000 x wallet balance.
231
209
 
232
210
  To sell an asset, call `createSellOrder`. You can do a fixed-price listing, where `startAmount` is equal to `endAmount`, or a declining [Dutch auction](https://en.wikipedia.org/wiki/Dutch_auction), where `endAmount` is lower and the price declines until `expirationTime` is hit:
233
211
 
234
- ```JavaScript
212
+ ```typescript
235
213
  // Expire this auction one day from now.
236
214
  // Note that we convert from the JavaScript timestamp (milliseconds):
237
- const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
215
+ const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24);
238
216
 
239
217
  const listing = await openseaSDK.createSellOrder({
240
218
  asset: {
@@ -245,8 +223,8 @@ const listing = await openseaSDK.createSellOrder({
245
223
  startAmount: 3,
246
224
  // If `endAmount` is specified, the order will decline in value to that amount until `expirationTime`. Otherwise, it's a fixed-price order:
247
225
  endAmount: 0.1,
248
- expirationTime
249
- })
226
+ expirationTime,
227
+ });
250
228
  ```
251
229
 
252
230
  The units for `startAmount` and `endAmount` are Ether, ETH. If you want to specify another ERC-20 token to use, see [Using ERC-20 Tokens Instead of Ether](#using-erc-20-tokens-instead-of-ether).
@@ -259,12 +237,11 @@ English Auctions are auctions that start at a small amount (we recommend even do
259
237
 
260
238
  To create an English Auction, create a listing that waits for the highest bid by setting `waitForHighestBid` to `true`:
261
239
 
262
- ```JavaScript
263
-
240
+ ```typescript
264
241
  // Create an auction to receive Wrapped Ether (WETH). See note below.
265
- const paymentTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
242
+ const paymentTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
266
243
 
267
- const startAmount = 0 // The minimum amount to sell for, in normal units (e.g. ETH)
244
+ const startAmount = 0; // The minimum amount to sell for, in normal units (e.g. ETH)
268
245
 
269
246
  const auction = await openseaSDK.createSellOrder({
270
247
  asset: {
@@ -275,8 +252,8 @@ const auction = await openseaSDK.createSellOrder({
275
252
  startAmount,
276
253
  expirationTime,
277
254
  paymentTokenAddress,
278
- waitForHighestBid: true
279
- })
255
+ waitForHighestBid: true,
256
+ });
280
257
  ```
281
258
 
282
259
  Note that auctions aren't supported with Ether directly due to limitations in Ethereum, so you have to use an ERC20 token, like Wrapped Ether (WETH), a stablecoin like DAI, etc. See [Using ERC-20 Tokens Instead of Ether](#using-erc-20-tokens-instead-of-ether) for more info.
@@ -285,20 +262,23 @@ Note that auctions aren't supported with Ether directly due to limitations in Et
285
262
 
286
263
  To retrieve a list of offers and auctions on an asset, you can use an instance of the `OpenSeaAPI` exposed on the client. Parameters passed into API filter objects are camel-cased and serialized before being sent as [OpenSea API parameters](https://docs.opensea.io/v2.0/reference):
287
264
 
288
- ```JavaScript
265
+ ```typescript
289
266
  // Get offers (bids), a.k.a. orders where `side == 0`
290
267
  const { orders, count } = await openseaSDK.api.getOrders({
291
268
  assetContractAddress: tokenAddress,
292
269
  tokenId,
293
- side: "bid"
294
- })
270
+ side: "bid",
271
+ });
295
272
 
296
273
  // Get page 2 of all auctions, a.k.a. orders where `side == 1`
297
- const { orders, count } = await openseaSDK.api.getOrders({
298
- assetContractAddress: tokenAddress,
299
- tokenId,
300
- side: "ask"
301
- }, 2)
274
+ const { orders, count } = await openseaSDK.api.getOrders(
275
+ {
276
+ assetContractAddress: tokenAddress,
277
+ tokenId,
278
+ side: "ask",
279
+ },
280
+ 2
281
+ );
302
282
  ```
303
283
 
304
284
  Note that the listing price of an asset is equal to the `currentPrice` of the **lowest valid sell order** on the asset. Users can lower their listing price without invalidating previous sell orders, so all get shipped down until they're canceled, or one is fulfilled.
@@ -337,7 +317,7 @@ The available API filters for the orders endpoint is documented in the `OrdersQu
337
317
 
338
318
  To buy an item, you need to **fulfill a sell order**. To do that, it's just one call:
339
319
 
340
- ```JavaScript
320
+ ```typescript
341
321
  const order = await openseaSDK.api.getOrder({ side: "ask", ... })
342
322
  const accountAddress = "0x..." // The buyer's wallet address, also the taker
343
323
  const transactionHash = await openseaSDK.fulfillOrder({ order, accountAddress })
@@ -351,7 +331,7 @@ If the order is a sell order (`order.side === "ask"`), the taker is the _buyer_
351
331
 
352
332
  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.
353
333
 
354
- ```JavaScript
334
+ ```typescript
355
335
  const order = await openseaSDK.api.getOrder({ side: "bid", ... })
356
336
  const accountAddress = "0x..." // The owner's wallet address, also the taker
357
337
  await openseaSDK.fulfillOrder({ order, accountAddress })
@@ -365,51 +345,50 @@ A handy feature in OpenSea.js is the ability to transfer any supported asset (fu
365
345
 
366
346
  To transfer an ERC-721 asset or an ERC-1155 asset, it's just one call:
367
347
 
368
- ```JavaScript
369
-
348
+ ```typescript
370
349
  const transactionHash = await openseaSDK.transfer({
371
350
  asset: { tokenId, tokenAddress },
372
351
  fromAddress, // Must own the asset
373
- toAddress
374
- })
352
+ toAddress,
353
+ });
375
354
  ```
376
355
 
377
- For fungible ERC-1155 assets, you can set `schemaName` to "ERC1155" and pass a `quantity` in to transfer multiple at once:
378
-
379
- ```JavaScript
356
+ For fungible ERC-1155 assets, you can set `tokenStandard` to "ERC1155" and pass a `quantity` in to transfer multiple at once:
380
357
 
358
+ ```typescript
381
359
  const transactionHash = await openseaSDK.transfer({
382
360
  asset: {
383
361
  tokenId,
384
362
  tokenAddress,
385
- schemaName: "ERC1155"
363
+ tokenStandard: "ERC1155",
386
364
  },
387
365
  fromAddress, // Must own the asset
388
366
  toAddress,
389
367
  quantity: 2,
390
- })
368
+ });
391
369
  ```
392
370
 
393
- To transfer fungible assets without token IDs, like ERC20 tokens, you can pass in an `OpenSeaFungibleToken` as the `asset`, set `schemaName` to "ERC20", and include `quantity` in base units (e.g. wei) to indicate how many.
371
+ To transfer fungible assets without token IDs, like ERC20 tokens, you can pass in an `OpenSeaFungibleToken` as the `asset`, set `tokenStandard` to "ERC20", and include `quantity` in base units (e.g. wei) to indicate how many.
394
372
 
395
373
  Example for transferring 2 DAI ($2) to another address:
396
374
 
397
- ```JavaScript
398
- const paymentToken = (await openseaSDK.api.getPaymentTokens({ symbol: 'DAI'})).tokens[0]
399
- const quantity = new BigNumber(Math.pow(10, paymentToken.decimals)).times(2)
375
+ ```typescript
376
+ const paymentToken = (await openseaSDK.api.getPaymentTokens({ symbol: "DAI" }))
377
+ .tokens[0];
378
+ const quantity = ethers.utils.parseUnits("2", paymentToken.decimals);
400
379
  const transactionHash = await openseaSDK.transfer({
401
380
  asset: {
402
381
  tokenId: null,
403
382
  tokenAddress: paymentToken.address,
404
- schemaName: "ERC20"
383
+ tokenStandard: "ERC20",
405
384
  },
406
385
  fromAddress, // Must own the tokens
407
386
  toAddress,
408
- quantity
409
- })
387
+ quantity,
388
+ });
410
389
  ```
411
390
 
412
- For more information, check out the documentation for WyvernSchemas on https://projectopensea.github.io/opensea-js/.
391
+ For more information, check out the [documentation](https://projectopensea.github.io/opensea-js/).
413
392
 
414
393
  ## Advanced
415
394
 
@@ -419,21 +398,21 @@ Interested in purchasing for users server-side or with a bot, scheduling future
419
398
 
420
399
  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:
421
400
 
422
- ```JavaScript
401
+ ```typescript
423
402
  const auction = await openseaSDK.createSellOrder({
424
403
  tokenAddress,
425
404
  tokenId,
426
405
  accountAddress,
427
406
  startAmount: 1,
428
- listingTime: Math.round(Date.now() / 1000 + 60 * 60 * 24) // One day from now
429
- })
407
+ listingTime: Math.round(Date.now() / 1000 + 60 * 60 * 24), // One day from now
408
+ });
430
409
  ```
431
410
 
432
411
  ### Purchasing Items for Other Users
433
412
 
434
413
  You can buy and transfer an item to someone else in one step! Just pass the `recipientAddress` parameter:
435
414
 
436
- ```JavaScript
415
+ ```typescript
437
416
  const order = await openseaSDK.api.getOrder({ side: "ask", ... })
438
417
  await openseaSDK.fulfillOrder({
439
418
  order,
@@ -444,31 +423,15 @@ await openseaSDK.fulfillOrder({
444
423
 
445
424
  If the order is a sell order (`order.side === "ask"`), the taker is the _buyer_ and this will prompt the buyer to pay for the item(s) but send them to the `recipientAddress`. If the order is a buy order ( `"bid"`), the taker is the _seller_ but the bid amount be sent to the `recipientAddress`.
446
425
 
447
- ### Bulk Transfers
448
-
449
- A handy feature in OpenSea.js is the ability to transfer multiple items at once in a single transaction. This works by grouping together as many `transferFrom` calls as the Ethereum gas limit allows, which is usually under 30 items, for most item contracts.
450
-
451
- To make a bulk transfer, it's just one call:
452
-
453
- ```JavaScript
454
- const assets: Array<{tokenId: string; tokenAddress: string}> = [...]
455
-
456
- const transactionHash = await openseaSDK.transferAll({
457
- assets,
458
- fromAddress, // Must own all the assets
459
- toAddress
460
- })
461
- ```
462
-
463
426
  This will automatically approve the assets for trading and confirm the transaction for sending them.
464
427
 
465
428
  ### Using ERC-20 Tokens Instead of Ether
466
429
 
467
430
  Here's an example of listing the Genesis CryptoKitty for $100! No more needing to worry about the exchange rate:
468
431
 
469
- ```JavaScript
432
+ ```typescript
470
433
  // Token address for the DAI stablecoin, which is pegged to $1 USD
471
- const paymentTokenAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359"
434
+ const paymentTokenAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";
472
435
 
473
436
  // The units for `startAmount` and `endAmount` are now in DAI, so $100 USD
474
437
  const auction = await openseaSDK.createSellOrder({
@@ -476,19 +439,20 @@ const auction = await openseaSDK.createSellOrder({
476
439
  tokenId: "1", // Token ID
477
440
  accountAddress: OWNERS_WALLET_ADDRESS,
478
441
  startAmount: 100,
479
- paymentTokenAddress
480
- })
442
+ paymentTokenAddress,
443
+ });
481
444
  ```
482
445
 
483
446
  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:
484
447
 
485
- ```JavaScript
486
- const token = (await openseaSDK.api.getPaymentTokens({ symbol: 'MANA'})).tokens[0]
448
+ ```typescript
449
+ const token = (await openseaSDK.api.getPaymentTokens({ symbol: "MANA" }))
450
+ .tokens[0];
487
451
 
488
452
  const order = await openseaSDK.api.getOrders({
489
453
  side: "ask",
490
- paymentTokenAddress: token.address
491
- })
454
+ paymentTokenAddress: token.address,
455
+ });
492
456
  ```
493
457
 
494
458
  **Fun note:** soon, all ERC-20 tokens will be allowed! This will mean you can create crazy offers on crypto collectibles **using your own ERC-20 token**. However, opensea.io will only display offers and auctions in ERC-20 tokens that it knows about, optimizing the user experience of order takers. Orders made with the following tokens will be shown on OpenSea:
@@ -502,17 +466,18 @@ Now you can make auctions and listings that can only be fulfilled by an address
502
466
 
503
467
  Here's an example of listing a Decentraland parcel for 10 ETH with a specific buyer address allowed to take it. No more needing to worry about whether they'll give you enough back!
504
468
 
505
- ```JavaScript
469
+ ```typescript
506
470
  // Address allowed to buy from you
507
- const buyerAddress = "0x123..."
471
+ const buyerAddress = "0x123...";
508
472
 
509
473
  const listing = await openseaSDK.createSellOrder({
510
474
  tokenAddress: "0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d", // Decentraland
511
- tokenId: "115792089237316195423570985008687907832853042650384256231655107562007036952461", // Token ID
475
+ tokenId:
476
+ "115792089237316195423570985008687907832853042650384256231655107562007036952461", // Token ID
512
477
  accountAddress: OWNERS_WALLET_ADDRESS,
513
478
  startAmount: 10,
514
- buyerAddress
515
- })
479
+ buyerAddress,
480
+ });
516
481
  ```
517
482
 
518
483
  ### Listening to Events
@@ -521,10 +486,9 @@ Events are fired whenever transactions or orders are being created, and when tra
521
486
 
522
487
  Our recommendation is that you "forward" OpenSea events to your own store or state management system. Here's an example of doing that with a Redux action:
523
488
 
524
- ```JavaScript
525
- import { EventType } from 'opensea-js'
489
+ ```typescript
490
+ import { openSeaSDK, EventType } from 'opensea-js'
526
491
  import * as ActionTypes from './index'
527
- import { openSeaSDK } from '../globalSingletons'
528
492
 
529
493
  // ...
530
494
 
@@ -565,12 +529,12 @@ handleSDKEvents() {
565
529
  console.info({ accountAddress, tokenAddress })
566
530
  dispatch({ type: ActionTypes.APPROVE_WETH })
567
531
  })
568
- openSeaSDK.addListener(EventType.ApproveAllAssets, ({ accountAddress, proxyAddress, tokenAddress }) => {
569
- console.info({ accountAddress, proxyAddress, tokenAddress })
532
+ openSeaSDK.addListener(EventType.ApproveAllAssets, ({ accountAddress, tokenAddress }) => {
533
+ console.info({ accountAddress, tokenAddress })
570
534
  dispatch({ type: ActionTypes.APPROVE_ALL_ASSETS })
571
535
  })
572
- openSeaSDK.addListener(EventType.ApproveAsset, ({ accountAddress, proxyAddress, tokenAddress, tokenId }) => {
573
- console.info({ accountAddress, proxyAddress, tokenAddress, tokenId })
536
+ openSeaSDK.addListener(EventType.ApproveAsset, ({ accountAddress, tokenAddress, tokenId }) => {
537
+ console.info({ accountAddress, tokenAddress, tokenId })
574
538
  dispatch({ type: ActionTypes.APPROVE_ASSET })
575
539
  })
576
540
  openSeaSDK.addListener(EventType.CreateOrder, ({ order, accountAddress }) => {
@@ -599,7 +563,7 @@ To remove all listeners and start over, just call `openseaSDK.removeAllListeners
599
563
 
600
564
  Auto-generated documentation for each export is available [here](https://projectopensea.github.io/opensea-js/).
601
565
 
602
- ## Migrating to version 1.0
566
+ ## Changelog
603
567
 
604
568
  See the [Changelog](CHANGELOG.md).
605
569
 
@@ -616,7 +580,7 @@ npm install
616
580
  And install TypeScript if you haven't already:
617
581
 
618
582
  ```bash
619
- npm install -g tslint typescript
583
+ npm install -g typescript
620
584
  ```
621
585
 
622
586
  **Build**
@@ -633,14 +597,14 @@ Or run the tests:
633
597
  npm test
634
598
  ```
635
599
 
636
- Note that the tests require access to both Infura and the OpenSea API. The timeout is adjustable via the `test` script in `package.json`.
600
+ Note that the tests require access to Alchemy and the OpenSea API. The timeout is adjustable via the `test` script in `package.json`.
637
601
 
638
602
  **Generate Documentation**
639
603
 
640
604
  Generate html docs, also available for browsing [here](https://projectopensea.github.io/opensea-js/):
641
605
 
642
606
  ```bash
643
- yarn docs-build
607
+ npm run docs-build
644
608
  ```
645
609
 
646
610
  **Contributing**
@@ -658,8 +622,8 @@ Contributions welcome! Please use GitHub issues for suggestions/concerns - if yo
658
622
  ## Testing your branch locally
659
623
 
660
624
  ```sh
661
- yarn link # in opensea-js repo
662
- yarn link opensea-js # in repo you're working on
625
+ npm link # in opensea-js repo
626
+ npm link opensea-js # in repo you're working on
663
627
  ```
664
628
 
665
629
  [version-badge]: https://img.shields.io/github/package-json/v/ProjectOpenSea/opensea-js
@@ -668,8 +632,8 @@ yarn link opensea-js # in repo you're working on
668
632
  [npm-link]: https://www.npmjs.com/package/opensea-js
669
633
  [ci-badge]: https://github.com/ProjectOpenSea/opensea-js/actions/workflows/code-quality.yml/badge.svg
670
634
  [ci-link]: https://github.com/ProjectOpenSea/opensea-js/actions/workflows/code-quality.yml
671
- [coverage-badge]: https://coveralls.io/repos/github/ProjectOpenSea/opensea-js/badge.svg?branch=master
672
- [coverage-link]: https://coveralls.io/github/ProjectOpenSea/opensea-js?branch=master
635
+ [coverage-badge]: https://coveralls.io/repos/github/ProjectOpenSea/opensea-js/badge.svg?branch=main
636
+ [coverage-link]: https://coveralls.io/github/ProjectOpenSea/opensea-js?branch=main
673
637
  [license-badge]: https://img.shields.io/github/license/ProjectOpenSea/opensea-js
674
638
  [license-link]: https://github.com/ProjectOpenSea/opensea-js/blob/main/LICENSE
675
639
  [docs-badge]: https://img.shields.io/badge/OpenSea.js-documentation-informational
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var chai_1 = require("chai");
40
+ var mocha_1 = require("mocha");
41
+ var init_1 = require("./init");
42
+ (0, mocha_1.suite)("SDK: getAsset", function () {
43
+ (0, mocha_1.test)("Get Asset", function () { return __awaiter(void 0, void 0, void 0, function () {
44
+ var tokenAddress, assetToGet, asset;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0:
48
+ tokenAddress = "0x059edd72cd353df5106d2b9cc5ab83a52287ac3a";
49
+ assetToGet = {
50
+ tokenAddress: tokenAddress,
51
+ tokenId: "1",
52
+ };
53
+ return [4 /*yield*/, init_1.sdk.api.getAsset(assetToGet)];
54
+ case 1:
55
+ asset = _a.sent();
56
+ (0, chai_1.assert)(asset, "Asset should not be null");
57
+ (0, chai_1.assert)(asset.assetContract.address === tokenAddress, "Contract address should match.");
58
+ (0, chai_1.assert)(asset.animationUrl, "Animation URL should not be null");
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ }); });
63
+ });
64
+ //# sourceMappingURL=getAsset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAsset.js","sourceRoot":"","sources":["../../src/__integration_tests__/getAsset.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAC9B,+BAAoC;AACpC,+BAA6B;AAE7B,IAAA,aAAK,EAAC,eAAe,EAAE;IACrB,IAAA,YAAI,EAAC,WAAW,EAAE;;;;;oBACV,YAAY,GAAG,4CAA4C,CAAC;oBAC5D,UAAU,GAAG;wBACjB,YAAY,cAAA;wBACZ,OAAO,EAAE,GAAG;qBACb,CAAC;oBACY,qBAAM,UAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAA;;oBAA1C,KAAK,GAAG,SAAkC;oBAChD,IAAA,aAAM,EAAC,KAAK,EAAE,0BAA0B,CAAC,CAAC;oBAC1C,IAAA,aAAM,EACJ,KAAK,CAAC,aAAa,CAAC,OAAO,KAAK,YAAY,EAC5C,gCAAgC,CACjC,CAAC;oBACF,IAAA,aAAM,EAAC,KAAK,CAAC,YAAY,EAAE,kCAAkC,CAAC,CAAC;;;;SAChE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};