ProjectOpenSea/seaport-js
概要
Seaport マーケットプレイスと連携するための TypeScript ライブラリです。
開発ツール計測したスター増加
- 24時間
- 0
- 7日間
- +1
- 15日間
- +1
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナル
Seaport.js
Seaport is a 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.
Seaport.js talks to the Seaport contracts directly and knows nothing about OpenSea. To list, buy, or make offers on OpenSea, use the OpenSea SDK (@opensea/sdk) instead. It builds on this library and also handles the OpenSea API, including posting orders and fetching listings and offers.
Installation
Seaport.js runs on viem 2.24 or newer, which is a peer dependency. Node.js 22 or newer is required.
npm install @opensea/seaport-js viem
The package ships ESM and CommonJS builds.
Getting started
Create a Seaport instance from a viem public client, plus a wallet client when you need to sign orders or send transactions:
import { Seaport } from "@opensea/seaport-js"
import { createPublicClient, createWalletClient, http } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { mainnet } from "viem/chains"
const transport = http("https://<network>.g.alchemy.com/v2/YOUR-API-KEY")
const seaport = new Seaport({
publicClient: createPublicClient({ chain: mainnet, transport }),
walletClient: createWalletClient({
chain: mainnet,
transport,
account: privateKeyToAccount(PRIVATE_KEY),
}),
})
The public client does every read: balances, approvals, counters, order status, simulations and gas estimates. When its chain has a Multicall3 address (most chains in viem/chains have one), each create or fulfill call sends its contract reads as one Multicall3 call; otherwise they go out in parallel. To also batch the remaining JSON-RPC calls (the native balance, the block, the chain id), create the transport with http(url, { batch: true }). The wallet client signs orders and sends transactions; without one, you can still build, hash and check orders. Methods that sign or send act as the wallet client's account unless you pass account (an address or a viem Account).
To connect through a browser wallet, see Examples. The public methods and their parameters are documented in src/seaport.ts.
Values
Amounts, token identifiers, times, salts and counters are bigint. Addresses are viem Address values and byte strings (zoneHash, conduitKey, signatures, proofs) are Hex. Orders that seaport-js returns use the same types, so convert them before JSON.stringify with orderToJson, and read an order from JSON (for example an API response) with orderFromJson.
Configuration
Besides publicClient and walletClient, the constructor takes optional settings. Every setting has a default, so you only pass the ones you want to change. examples/configuration.ts shows each of them in use.
ascendingAmountFulfillmentBuffer(default300) is the number of seconds added to the current block time when computing how much to pay for an item whose amount rises over time, so the fill still covers it if the transaction confirms later.balanceAndApprovalChecksOnOrderCreation(defaulttrue) turns the offerer's balance and approval checks increateOrderandcreateBulkOrderson or off. Whenfalse, both skip the checks and return no approval actions.conduitKeyToConduit(default: the OpenSea conduit only) adds mappings from conduit key to conduit address. Add one for each custom conduit you use, so approvals are checked against the right address.seaportAddress(default0x0000000000000068F116a894984e2DB1123eB395) is the Seaport contract address. The default is Seaport 1.6, deployed at the same address on every supported chain.seaportVersion(default"1.6") is the Seaport version in the EIP-712 domain used for signing. Set it to matchseaportAddress.domainRegistryAddress(default0x000000000DaD0DE04D2B2D4a5A74581EBA94124A) is the domain registry contract address.defaultConduitKey(default: the zero hash, meaning no conduit) is the conduit key used when you don't passconduitKeytocreateOrder,createBulkOrders,fulfillOrderorfulfillOrders. With no conduit, approvals go to the Seaport contract itself.
Use cases
Most of the main flows return a use case. When you create an order with createOrder, the library checks the offerer's balances and approvals for the order's offer. If the offerer still needs to approve an asset contract, the use case's actions include an approval action to run first, so the trade can succeed later. executeAllActions runs every action in order, waiting for each approval to be mined, and returns the result of the last one: the signed order for a create, or the transaction hash for a fulfillment.
const hash = await (await seaport.fulfillOrder({ order })).executeAllActions()
const receipt = await seaport.publicClient.waitForTransactionReceipt({ hash })
Both take optional { confirmations, timeout } for the approval receipts.
executeAllActions sends the approvals and the fulfillment without asking again, for whatever the order says. When an order comes from an API or another party, show its offer, consideration and recipients to the user (or check them in code) before calling it. orderFromJson checks that an order is well-formed, not that its terms are what you expect.
To create an order the offerer approves onchain instead of by signature, as a smart contract wallet may have to, run executeApprovals() and pass the create action's orderComponents to validate(). Neither asks the wallet for a signature.
Each transaction action has transactionMethods with transact() (send, resolves to the hash), simulate(), estimateGas() and buildTransaction(). A Seaport revert is thrown as viem's ContractFunctionExecutionError, whose ContractFunctionRevertedError cause names the Seaport error. When one of the library's own checks fails first (an unknown conduit, a missing balance, an order already filled), it throws a SeaportError with a code to branch on.
Exports
@opensea/seaport-jshasSeaport, the types, the constants (ItemType,OrderType, Seaport and conduit addresses,EIP_712_ORDER_TYPE) and helpers such asgetOrderHash,getMaximumSizeForOrder,generateRandomSalt,MerkleTree,orderToJsonandorderFromJson, andSeaportError.@opensea/seaport-js/abihasseaportAbi,conduitControllerAbi,conduitAbi,domainRegistryAbi,erc20Abi,erc721Abianderc1155Abi, typedas constfor use with viem.
Examples
Each example is a TypeScript file in examples/ that CI type-checks against the library source, so it stays in step with the API.
rpc-provider.tsconnects to a JSON-RPC node that holds its own accounts, such as a local anvil node.browser-provider.tsconnects through an injected browser wallet such as MetaMask.custom-signer.tssigns with a private key you hold.configuration.tspasses every setting from the list above.list-erc721.tslists an ERC-721 for 10 ETH and fulfills the listing.offer-erc721.tsoffers 10 WETH for one ERC-721 and fulfills the offer.collection-offer.tsoffers 10 WETH for any ERC-721 in a collection and fulfills it with a token the fulfiller picks.
Run npm run typecheck:examples to check them locally.
Contributing
See the contributing guide for detailed instructions on how to get started with this project.
Security
Found a vulnerability? Report it through OpenSea's Bugcrowd program at https://bugcrowd.com/engagements/opensea rather than opening a public issue. See SECURITY.md.
License
MIT Copyright 2022 Ozone Networks, Inc.
関連プロジェクトを探す
読み込み中…