Skip to content

Commit 893866a

Browse files
Add folder of documentation to be pushed to our Documentation Platform (#1137)
* Add folder of documentation to be pushed to our Documentation Platform * Add developer docs folder copy to docs workflow --------- Co-authored-by: Ryan Ghods <ryan@ryanio.com>
1 parent 2a0b52c commit 893866a

10 files changed

Lines changed: 559 additions & 147 deletions

File tree

.github/workflows/docs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ jobs:
2828
with:
2929
branch: gh-pages
3030
folder: docs
31+
32+
- name: Copy developer docs to repository
33+
if: github.ref == 'refs/heads/main'
34+
uses: nkoppel/push-files-to-another-repository@v1.1.1
35+
env:
36+
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
37+
with:
38+
source-files: "developerDocs/"
39+
destination-username: "ProjectOpenSea"
40+
destination-repository: "developer-docs"
41+
destination-directory: "opensea-js"
42+
destination-branch: "main"
43+
commit-username: "ProjectOpenSea-opensea-js"
44+
commit-message: "Latest docs from opensea-js"

README.md

Lines changed: 15 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ A JavaScript library for crypto-native e-commerce: buying, selling, and bidding
2020
- [Fetching Assets](#fetching-assets)
2121
- [Checking Balances and Ownerships](#checking-balances-and-ownerships)
2222
- [Making Offers](#making-offers)
23-
- [Bidding on ENS Short Name Auctions](#bidding-on-ens-short-name-auctions)
2423
- [Offer Limits](#offer-limits)
2524
- [Making Listings / Selling Items](#making-listings--selling-items)
2625
- [Fetching Orders](#fetching-orders)
2726
- [Buying Items](#buying-items)
2827
- [Accepting Offers](#accepting-offers)
29-
- [Transferring Items or Coins (Gifting)](#transferring-items-or-coins-gifting)
3028
- [Advanced](#advanced)
3129
- [Scheduling Future Listings](#scheduling-future-listings)
3230
- [Purchasing Items for Other Users](#purchasing-items-for-other-users)
@@ -43,15 +41,15 @@ A JavaScript library for crypto-native e-commerce: buying, selling, and bidding
4341

4442
This is the JavaScript SDK for [OpenSea](https://opensea.io), the largest marketplace for NFTs.
4543

46-
It allows developers to access the official orderbook, filter it, create buy orders (**offers**), create sell orders (**auctions**), and complete trades programmatically.
44+
It allows developers to access the official orderbook, filter it, create buy orders (**offers**), create sell orders (**listings**), and complete trades programmatically.
4745

4846
Get started by [requesting an API key](https://docs.opensea.io/reference/api-keys) 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.
4947

5048
Happy seafaring! ⛵️
5149

5250
## Installation
5351

54-
Switching to Node.js version 16 is required for SDK Version 3.0+ and to make sure common crypto dependencies work. Execute `nvm use`, if you have Node Version Manager.
52+
Node.js version 16 is the minimum required for the SDK. Execute `nvm use`, if you have Node Version Manager.
5553

5654
Then, in your project, run:
5755

@@ -169,37 +167,6 @@ const offer = await openseaSDK.createBuyOrder({
169167

170168
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.
171169

172-
#### Bidding on ENS Short Name Auctions
173-
174-
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).
175-
176-
To bid, you must use the ENS Short Name schema:
177-
178-
```typescript
179-
const {
180-
tokenId,
181-
// Token address should be `0xfac7bea255a6990f749363002136af6556b31e04` on mainnet
182-
tokenAddress,
183-
// Name must have `.eth` at the end and correspond with the tokenId
184-
name
185-
} = ENS_ASSET // You can get an ENS asset from `openseaSDK.api.getAsset(...)`
186-
187-
const offer = await openseaSDK.createBuyOrder({
188-
asset: {
189-
tokenId,
190-
tokenAddress,
191-
name,
192-
// Only needed for the short-name auction, not ENS names
193-
// that have been sold once already:
194-
tokenStandard: "ENSShortNameAuction"
195-
},
196-
// Your wallet address (the bidder's address):
197-
accountAddress: "0x1234..."
198-
// Value of the offer, in wrapped ETH:
199-
startAmount: 1.2,
200-
})
201-
```
202-
203170
#### Offer Limits
204171

205172
Note: The total value of buy orders must not exceed 1000 x wallet balance.
@@ -242,7 +209,7 @@ const paymentTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
242209

243210
const startAmount = 0; // The minimum amount to sell for, in normal units (e.g. ETH)
244211

245-
const auction = await openseaSDK.createSellOrder({
212+
const order = await openseaSDK.createSellOrder({
246213
asset: {
247214
tokenId,
248215
tokenAddress,
@@ -338,57 +305,6 @@ await openseaSDK.fulfillOrder({ order, accountAddress })
338305

339306
If the order is a buy order (`order.side === "bid"`), 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.
340307

341-
### Transferring Items or Coins (Gifting)
342-
343-
A handy feature in OpenSea.js is the ability to transfer any supported asset (fungible or non-fungible tokens) in one line of JavaScript.
344-
345-
To transfer an ERC-721 asset or an ERC-1155 asset, it's just one call:
346-
347-
```typescript
348-
const transactionHash = await openseaSDK.transfer({
349-
asset: { tokenId, tokenAddress },
350-
fromAddress, // Must own the asset
351-
toAddress,
352-
});
353-
```
354-
355-
For fungible ERC-1155 assets, you can set `tokenStandard` to "ERC1155" and pass a `quantity` in to transfer multiple at once:
356-
357-
```typescript
358-
const transactionHash = await openseaSDK.transfer({
359-
asset: {
360-
tokenId,
361-
tokenAddress,
362-
tokenStandard: "ERC1155",
363-
},
364-
fromAddress, // Must own the asset
365-
toAddress,
366-
quantity: 2,
367-
});
368-
```
369-
370-
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.
371-
372-
Example for transferring 2 DAI ($2) to another address:
373-
374-
```typescript
375-
const paymentToken = (await openseaSDK.api.getPaymentTokens({ symbol: "DAI" }))
376-
.tokens[0];
377-
const quantity = ethers.utils.parseUnits("2", paymentToken.decimals);
378-
const transactionHash = await openseaSDK.transfer({
379-
asset: {
380-
tokenId: null,
381-
tokenAddress: paymentToken.address,
382-
tokenStandard: "ERC20",
383-
},
384-
fromAddress, // Must own the tokens
385-
toAddress,
386-
quantity,
387-
});
388-
```
389-
390-
For more information, check out the [documentation](https://projectopensea.github.io/opensea-js/).
391-
392308
## Advanced
393309

394310
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.
@@ -398,7 +314,7 @@ Interested in purchasing for users server-side or with a bot, scheduling future
398314
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:
399315

400316
```typescript
401-
const auction = await openseaSDK.createSellOrder({
317+
const order = await openseaSDK.createSellOrder({
402318
tokenAddress,
403319
tokenId,
404320
accountAddress,
@@ -454,14 +370,9 @@ const order = await openseaSDK.api.getOrders({
454370
});
455371
```
456372

457-
**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:
458-
459-
- MANA, Decentraland's currency: https://etherscan.io/token/0x0f5d2fb29fb7d3cfee444a200298f468908cc942
460-
- DAI, Maker's stablecoin, pegged to $1 USD: https://etherscan.io/token/0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359
461-
462373
### Private Auctions
463374

464-
Now you can make auctions and listings that can only be fulfilled by an address or email of your choosing. This allows you to negotiate a price in some channel and sell for your chosen price on OpenSea, **without having to trust that the counterparty will abide by your terms!**
375+
You can make offers and listings that can only be fulfilled by an address or email of your choosing. This allows you to negotiate a price in some channel and sell for your chosen price on OpenSea, **without having to trust that the counterparty will abide by your terms!**
465376

466377
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!
467378

@@ -483,80 +394,40 @@ const listing = await openseaSDK.createSellOrder({
483394

484395
Events are fired whenever transactions or orders are being created, and when transactions return receipts from recently mined blocks on the Ethereum blockchain.
485396

486-
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:
397+
Our recommendation is that you "forward" OpenSea events to your own store or state management system. Here are examples of listening to the events:
487398

488399
```typescript
489400
import { openSeaSDK, EventType } from 'opensea-js'
490-
import * as ActionTypes from './index'
491-
492-
// ...
493401

494402
handleSDKEvents() {
495-
return async function(dispatch, getState) {
496403
openSeaSDK.addListener(EventType.TransactionCreated, ({ transactionHash, event }) => {
497-
console.info({ transactionHash, event })
498-
dispatch({ type: ActionTypes.SET_PENDING_TRANSACTION_HASH, hash: transactionHash })
404+
console.info('Transaction created: ', { transactionHash, event })
499405
})
500406
openSeaSDK.addListener(EventType.TransactionConfirmed, ({ transactionHash, event }) => {
501-
console.info({ transactionHash, event })
502-
// Only reset your exchange UI if we're finishing an order fulfillment or cancellation
503-
if (event == EventType.MatchOrders || event == EventType.CancelOrder) {
504-
dispatch({ type: ActionTypes.RESET_EXCHANGE })
505-
}
407+
console.info('Transaction confirmed: ',{ transactionHash, event })
506408
})
507409
openSeaSDK.addListener(EventType.TransactionDenied, ({ transactionHash, event }) => {
508-
console.info({ transactionHash, event })
509-
dispatch({ type: ActionTypes.RESET_EXCHANGE })
410+
console.info('Transaction denied: ',{ transactionHash, event })
510411
})
511412
openSeaSDK.addListener(EventType.TransactionFailed, ({ transactionHash, event }) => {
512-
console.info({ transactionHash, event })
513-
dispatch({ type: ActionTypes.RESET_EXCHANGE })
514-
})
515-
openSeaSDK.addListener(EventType.InitializeAccount, ({ accountAddress }) => {
516-
console.info({ accountAddress })
517-
dispatch({ type: ActionTypes.INITIALIZE_PROXY })
413+
console.info('Transaction failed: ',{ transactionHash, event })
518414
})
519415
openSeaSDK.addListener(EventType.WrapEth, ({ accountAddress, amount }) => {
520-
console.info({ accountAddress, amount })
521-
dispatch({ type: ActionTypes.WRAP_ETH })
416+
console.info('Wrap ETH: ',{ accountAddress, amount })
522417
})
523418
openSeaSDK.addListener(EventType.UnwrapWeth, ({ accountAddress, amount }) => {
524-
console.info({ accountAddress, amount })
525-
dispatch({ type: ActionTypes.UNWRAP_WETH })
526-
})
527-
openSeaSDK.addListener(EventType.ApproveCurrency, ({ accountAddress, tokenAddress }) => {
528-
console.info({ accountAddress, tokenAddress })
529-
dispatch({ type: ActionTypes.APPROVE_WETH })
530-
})
531-
openSeaSDK.addListener(EventType.ApproveAllAssets, ({ accountAddress, tokenAddress }) => {
532-
console.info({ accountAddress, tokenAddress })
533-
dispatch({ type: ActionTypes.APPROVE_ALL_ASSETS })
534-
})
535-
openSeaSDK.addListener(EventType.ApproveAsset, ({ accountAddress, tokenAddress, tokenId }) => {
536-
console.info({ accountAddress, tokenAddress, tokenId })
537-
dispatch({ type: ActionTypes.APPROVE_ASSET })
538-
})
539-
openSeaSDK.addListener(EventType.CreateOrder, ({ order, accountAddress }) => {
540-
console.info({ order, accountAddress })
541-
dispatch({ type: ActionTypes.CREATE_ORDER })
542-
})
543-
openSeaSDK.addListener(EventType.OrderDenied, ({ order, accountAddress }) => {
544-
console.info({ order, accountAddress })
545-
dispatch({ type: ActionTypes.RESET_EXCHANGE })
419+
console.info('Unwrap ETH: ',{ accountAddress, amount })
546420
})
547421
openSeaSDK.addListener(EventType.MatchOrders, ({ buy, sell, accountAddress }) => {
548-
console.info({ buy, sell, accountAddress })
549-
dispatch({ type: ActionTypes.FULFILL_ORDER })
422+
console.info('Match orders: ', { buy, sell, accountAddress })
550423
})
551424
openSeaSDK.addListener(EventType.CancelOrder, ({ order, accountAddress }) => {
552-
console.info({ order, accountAddress })
553-
dispatch({ type: ActionTypes.CANCEL_ORDER })
425+
console.info('Cancel order: ', { order, accountAddress })
554426
})
555-
}
556427
}
557428
```
558429

559-
To remove all listeners and start over, just call `openseaSDK.removeAllListeners()`.
430+
To remove all listeners call `openseaSDK.removeAllListeners()`.
560431

561432
## Learning More
562433

0 commit comments

Comments
 (0)