1 Star 0 Fork 0

ProjectOpenSea / stream-js

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

Version npm Test CI Coverage Status License Docs

OpenSea Stream API - TypeScript SDK

A TypeScript SDK for receiving updates from the OpenSea Stream API - pushed over websockets. We currently support the following event types on a per-collection basis:

  • item listed
  • item sold
  • item transferred
  • item metadata updates
  • item cancelled
  • item received offer
  • item received bid

This is a best effort delivery messaging system. Messages that are not received due to connection errors will not be re-sent. Messages may be delivered out of order. This SDK is offered as a beta experience as we work with developers in the ecosystem to make this a more robust and reliable system.

Documentation: https://docs.opensea.io/reference/stream-api-overview

Installation

Please use Node.js version 16 or greater to make sure common crypto dependencies work.

  • Install this package: npm install @opensea/stream-js
  • Install types for phoenix: npm install --save-dev @types/phoenix
  • NodeJS only: Install required libraries: npm install ws node-localstorage

Getting Started

Authentication

In order to make onboarding easy, we've integrated the OpenSea Stream API with our existing API key system. The API keys you have been using for the REST API should work here as well. If you don't already have one, you can create an API key in your OpenSea account settings.

Create a client

Browser

import { OpenSeaStreamClient } from '@opensea/stream-js';

const client = new OpenSeaStreamClient({
  token: 'YOUR_OPENSEA_API_KEY'
});

Node.js

import { OpenSeaStreamClient } from '@opensea/stream-js';
import { WebSocket } from 'ws';
import { LocalStorage } from 'node-localstorage';

const client = new OpenSeaStreamClient({
  token: 'YOUR_OPENSEA_API_KEY',
  connectOptions: {
    transport: WebSocket,
    sessionStorage: LocalStorage
  }
});

You can also optionally pass in:

  • a network if you would like to access testnet networks.
    • The default value is Network.MAINNET for all mainnet chains
    • Can also select Network.TESTNET for all testnet chains
  • apiUrl if you would like to access another OpenSea Stream API endpoint. Not needed if you provide a network or use the default values.
  • an onError callback to handle errors. The default behavior is to console.error the error.
  • a logLevel to set the log level. The default is LogLevel.INFO.

Available Networks

The OpenSea Stream API is available on the following networks:

Mainnet

wss://stream.openseabeta.com/socket

Testnet

wss://testnets-stream.openseabeta.com/socket

To create testnet instance of the client, you can create it with the following arguments:

import { OpenSeaStreamClient, Network } from '@opensea/stream-js';

const client = new OpenSeaStreamClient({
  network: Network.TESTNET,
  token: 'YOUR_OPENSEA_API_KEY'
});

An API key is not needed for testnets, so any value is okay for token when network is Network.TESTNET.

Manually connecting to the socket (optional)

The client will automatically connect to the socket as soon as you subscribe to the first channel. If you would like to connect to the socket manually (before that), you can do so:

client.connect();

After successfully connecting to our websocket it is time to listen to specific events you're interested in!

Streaming metadata updates

We will only send out metadata updates when we detect that the metadata provided in tokenURI has changed from what OpenSea has previously cached.

client.onItemMetadataUpdated('collection-slug', (event) => {
  // handle event
});

Streaming item listed events

client.onItemListed('collection-slug', (event) => {
  // handle event
});

Streaming item sold events

client.onItemSold('collection-slug', (event) => {
  // handle event
});

Streaming item transferred events

client.onItemTransferred('collection-slug', (event) => {
  // handle event
});

Streaming bids and offers

client.onItemReceivedBid('collection-slug', (event) => {
  // handle event
});

client.onItemReceivedOffer('collection-slug', (event) => {
  // handle event
});

Streaming multiple event types

client.onEvents(
  'collection-slug',
  [EventType.ITEM_RECEIVED_OFFER, EventType.ITEM_TRANSFERRED],
  (event) => {
    // handle event
  }
);

Streaming order cancellations events

client.onItemCancelled('collection-slug', (event) => {
  // handle event
});

Subscribing to events from all collections

If you'd like to listen to an event from all collections use wildcard * for the collectionSlug parameter.

Types

Types are included to make working with our event payload objects easier.

Disconnecting

From a specific stream

All subscription methods return a callback function that will unsubscribe from a stream when invoked.

const unsubscribe = client.onItemMetadataUpdated('collection-slug', noop);

unsubscribe();

From the socket

client.disconnect();

Contributing

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

License

MIT Copyright 2022 Ozone Networks, Inc.

MIT License Copyright (c) 2022 OpenSea 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.

简介

An SDK to receive pushed updates from OpenSea over websocket. 展开 收起
TypeScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助