OpenSea JavaScript SDK
Synopsis
This is the JavaScript SDK for OpenSea. It allows developers to access the orderbook, filter it, create new buy orders (offers), create new sell orders (auctions), and fulfill orders to complete trades, programmatically.
You get started by instantiating your own seaport. Then you can create orders off-chain or fulfill orders on-chain, and listen to events (like ApproveAllAssets
or WrapEthComplete
) in the process.
Happy seafaring! ⛵️
Installation
In your project, run:
npm install --save opensea-js
Install web3 too if you haven't already.
Getting Started
To get started, create a new OpenSeaJS client, called an OpenSeaPort 🚢, using your Web3 provider:
import * as Web3 from 'web3'
import { OpenSeaPort, Network } from 'opensea-js'
const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')
const seaport = new OpenSeaPort(provider, {
networkName: Network.Main
})
Then, you can do this to make an offer on an asset:
const offer = await seaport.createBuyOrder({ tokenId, tokenAddress, accountAddress, amountInEth, expirationTime: 0 })
To retrieve a list of offers and auction on an asset, you can use an instance of the OpenSeaAPI
exposed on the client:
import { OrderSide } from 'opensea-js/types'
const { orders, count } = await seaport.api.getOrders({
tokenAddress, tokenId,
side: OrderSide.Buy
})
const { orders, count } = await seaport.api.getOrders({
tokenAddress, tokenId,
side: OrderSide.Sell
}, 2)
Learning More
Detailed documentation is coming soon on docs.opensea.io.
In the meantime, visit the auto-generated documentation here, or contact the OpenSea devs for help! They're available every day on Discord in the #developers
channel.
Development Information
Setup
Node >= v8.11.2 required.
Before any development, install the required NPM dependencies:
npm install
Build
Then, lint and build the library into the lib
directory:
npm run build
Or run the barebones tests:
npm test
Generate Documentation
Generate html docs, also available for browsing here:
npm run docsHtml
Or generate markdown docs available for browsing on git repos:
npm run docsMarkdown
Or generate both:
npm run docs
Contributing
Contributions welcome! Please use GitHub issues for suggestions/concerns - if you prefer to express your intentions in code, feel free to submit a pull request.