1 Star 0 Fork 0

ProjectOpenSea / seaport-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Version npm Test CI Code Coverage License Docs Discussions

Seaport.js

Seaport is a new marketplace protocol for safely and efficiently buying and selling NFTs. This is a TypeScript library intended to make interfacing with the contract reasonable and easy.

Synopsis

This is a TypeScript library to help interface with Seaport. It includes various helper methods and constants that makes interfacing with Seaport easier. These include creating orders, fulfilling orders, doing the necessary balance and approval checks, and more. We recommend taking a look at the Seaport docs to get a better understanding of how the Seaport marketplace works.

Installation

We recommend using nvm to manage Node.js versions. Execute nvm use, if you have nvm installed.

Then, in your project, run:

npm install --save @opensea/seaport-js

Getting Started

Instantiate your instance of seaport using your ethers provider:

Examples

Through a browser provider (i.e. Metamask)

import { Seaport } from "@opensea/seaport-js";
import { ethers } from "ethers";

const provider = new ethers.BrowserProvider(window.ethereum);

const seaport = new Seaport(provider);

Through a RPC Provider (i.e. Alchemy)

import { Seaport } from "@opensea/seaport-js";
import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider(
  "https://<network>.alchemyapi.io/v2/YOUR-API-KEY",
);

const seaport = new Seaport(provider);

With custom signer

import { Seaport } from "@opensea/seaport-js";
import { ethers } from "ethers";

// Provider must be provided to the signer when supplying a custom signer
const provider = new ethers.JsonRpcProvider(
  "https://<network>.alchemyapi.io/v2/YOUR-API-KEY",
);

const signer = new ethers.Wallet("YOUR_PK", provider);

const seaport = new Seaport(signer);

Look at the relevant definitions in seaport.ts in order to see the different functionality this library offers.

Use Cases

Many of the main core flows return use cases. What this means is that if you were to create an order (a la createOrder), the library helps perform the necessary balance and approval checks based on the offer of the order being created. If the offerer requires approvals on one asset contract, the actions field of the use case would contain an approval action that the user should execute first in order for the trade to succeed in the future.

Examples

Listing an ERC-721 for 10 ETH and fulfilling it

const offerer = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
const fulfiller = "0x70997970c51812dc3a010c7d01b50e0d17dc79c8";
const { executeAllActions } = await seaport.createOrder(
  {
    offer: [
      {
        itemType: ItemType.ERC721,
        token: "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
        identifier: "1",
      },
    ],
    consideration: [
      {
        amount: ethers.parseEther("10").toString(),
        recipient: offerer,
      },
    ],
  },
  offerer,
);

const order = await executeAllActions();

const { executeAllActions: executeAllFulfillActions } =
  await seaport.fulfillOrder({
    order,
    accountAddress: fulfiller,
  });

const transaction = executeAllFulfillActions();

Making an offer for an ERC-721 for 10 WETH and fulfilling it

const offerer = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
const fulfiller = "0x70997970c51812dc3a010c7d01b50e0d17dc79c8";
const { executeAllActions } = await seaport.createOrder(
  {
    offer: [
      {
        amount: parseEther("10").toString(),
        // WETH
        token: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      },
    ],
    consideration: [
      {
        itemType: ItemType.ERC721,
        token: "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
        identifier: "1",
        recipient: offerer,
      },
    ],
  },
  offerer,
);

const order = await executeAllActions();

const { executeAllActions: executeAllFulfillActions } =
  await seaport.fulfillOrder({
    order,
    accountAddress: fulfiller,
  });

const transaction = executeAllFulfillActions();

Contributing

See the contributing guide for detailed instructions on how to get started with this project.

License

MIT Copyright 2022 Ozone Networks, Inc.

Copyright 2022 Ozone Networks, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A JavaScript library to interface with the Seaport marketplace. 展开 收起
TypeScript 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ProjectOpenSea/seaport-js.git
git@gitee.com:ProjectOpenSea/seaport-js.git
ProjectOpenSea
seaport-js
seaport-js
main

搜索帮助