Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v7: remove v1 APIs, upgrade to ethers v6 #1310

Merged
merged 12 commits into from
Dec 8, 2023
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

# OpenSea.js <!-- omit in toc -->

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

It allows developers to access the official orderbook, filter it, create listings and offers, and complete trades programmatically.

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.
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 in the process.

Happy seafaring! ⛵️

Expand Down
11 changes: 5 additions & 6 deletions developerDocs/advanced-use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ const order = await openseaSDK.createListing({
You can buy and transfer an item to someone else in one step! Just pass the `recipientAddress` parameter:

```typescript
const order = await openseaSDK.api.getOrder({ side: "ask", ... })
const order = await openseaSDK.api.getOrder({ side: OrderSide.ASK, ... })
await openseaSDK.fulfillOrder({
order,
accountAddress, // The address of your wallet, which will sign the transaction
recipientAddress // The address of the recipient, i.e. the wallet you're purchasing on behalf of
})
```

If the order is a listing (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 an offer (buy order, `"bid"`), the taker is the _seller_ but the bid amount be sent to the `recipientAddress`.
If the order is a listing (sell order, `order.side === OrderSide.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 an offer (buy order, `"bid"`), the taker is the _seller_ but the bid amount be sent to the `recipientAddress`.

This will automatically approve the assets for trading and confirm the transaction for sending them.

Expand All @@ -68,14 +68,13 @@ const order = await openseaSDK.createListing({
});
```

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:
You can use `getPaymentToken` to search for payment tokens by address. And you can even list all orders for a specific ERC-20 token by querying the API:

```typescript
const token = (await openseaSDK.api.getPaymentTokens({ symbol: "MANA" }))
.tokens[0];
const token = await openseaSDK.api.getPaymentToken(paymentTokenAddress);

const order = await openseaSDK.api.getOrders({
side: "ask",
side: OrderSide.ASK,
paymentTokenAddress: token.address,
});
```
Expand Down
20 changes: 10 additions & 10 deletions developerDocs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hidden: false
### Fetching NFTs

```TypeScript
const { nft } = await openseaSDK.api.getNFT(openseaSDK.chain, tokenAddress, tokenId)
const { nft } = await openseaSDK.api.getNFT(tokenAddress, tokenId)
```

Also see methods `getNFTsByCollection`, `getNFTsByContract`, and `getNFTsByAccount`.
Expand All @@ -42,7 +42,7 @@ const balance = await openseaSDK.getBalance({
asset,
});

const ownsKitty = balance.gt(0);
const ownsKitty = balance > 0n;
ryanio marked this conversation as resolved.
Show resolved Hide resolved
```

### Making Offers
Expand Down Expand Up @@ -128,18 +128,18 @@ Note that auctions aren't supported with Ether directly due to limitations in Et
To retrieve a list of offers and auctions on an asset, you can use `getOrders`. Parameters passed into API filter objects are camel-cased and serialized before being sent as [API parameters](https://docs.opensea.io/v2.0/reference):

```typescript
// Get offers (bids), a.k.a. orders where `side == "bid"`
// Get offers (bids), a.k.a. orders where `side == OrderSide.BID`
const { orders, count } = await openseaSDK.api.getOrders({
assetContractAddress: tokenAddress,
tokenId,
side: "bid",
side: OrderSide.BID,
});

// Get page 2 of all auctions, a.k.a. orders where `side == "ask"`
// Get page 2 of all auctions, a.k.a. orders where `side == OrderSide.ASK`
const { orders, count } = await openseaSDK.api.getOrders({
assetContractAddress: tokenAddress,
tokenId,
side: "ask",
side: OrderSide.ASK,
});
```

Expand All @@ -166,23 +166,23 @@ const offer = await openseaSDK.api.getBestOffer(collectionSlug, tokenId);
To buy an item, you need to **fulfill a listing**. To do that, it's just one call:

```typescript
const order = await openseaSDK.api.getOrder({ side: "ask", ... })
const order = await openseaSDK.api.getOrder({ side: OrderSide.ASK, ... })
const accountAddress = "0x..." // The buyer's wallet address, also the taker
const transactionHash = await openseaSDK.fulfillOrder({ order, accountAddress })
```

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.

If the order is a listing (sell order, `order.side === "ask"`), the taker is the _buyer_ and this will prompt the buyer to pay for the item(s).
If the order is a listing (sell order, `order.side === OrderSide.ASK`), the taker is the _buyer_ and this will prompt the buyer to pay for the item(s).

### Accepting Offers

Similar to fulfilling listings above, you need to fulfill an offer (buy order) on an item you own to receive the tokens in the offer.

```typescript
const order = await openseaSDK.api.getOrder({ side: "bid", ... })
const order = await openseaSDK.api.getOrder({ side: OrderSide.BID, ... })
const accountAddress = "0x..." // The owner's wallet address, also the taker
await openseaSDK.fulfillOrder({ order, accountAddress })
```

If the order is an offer (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.
If the order is an offer (buy order, `order.side === OrderSide.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.
6 changes: 2 additions & 4 deletions developerDocs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ import { ethers } from "ethers";
import { OpenSeaSDK, Chain } from "opensea-js";

// This example provider won't let you make transactions, only read-only calls:
const provider = new ethers.providers.JsonRpcProvider(
"https://mainnet.infura.io",
);
const provider = new ethers.JsonRpcProvider("https://mainnet.infura.io");

const openseaSDK = new OpenSeaSDK(walletWithProvider, {
const openseaSDK = new OpenSeaSDK(provider, {
chain: Chain.Mainnet,
apiKey: YOUR_API_KEY,
});
Expand Down