Skip to content

Commit 0904934

Browse files
author
Michael Cohen
authored
Copy README over to root directory to appear in npmjs (#73)
* Copy README over to root directory to appear in npmjs * 0.0.3
1 parent c60936c commit 0904934

File tree

3 files changed

+179
-3
lines changed

3 files changed

+179
-3
lines changed

README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# OpenSea Stream API - JavaScript SDK
2+
3+
[![https://badges.frapsoft.com/os/mit/mit.svg?v=102](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://opensource.org/licenses/MIT)
4+
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
5+
6+
A Javascript SDK for receiving updates from the OpenSea Stream API - pushed over websockets. We currently support the following event types on a per-collection basis:
7+
8+
- item listed
9+
- item sold
10+
- item transferred
11+
- item metadata updates
12+
- item cancelled
13+
- item received offer
14+
- item received bid
15+
16+
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 delievered 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.
17+
18+
# Setup
19+
20+
Run `nvm use`
21+
And then `npm install`
22+
23+
# Getting Started
24+
25+
## Authentication
26+
27+
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, request an API key from us [here](https://docs.opensea.io/reference/request-an-api-key).
28+
29+
## Create a client
30+
31+
```javascript
32+
import { OpenSeaStreamClient } from '@opensea/opensea-stream-js-sdk';
33+
34+
const client = new OpenSeaStreamClient({
35+
token: 'openseaApiKey'
36+
});
37+
```
38+
39+
You can also optionally pass in:
40+
41+
- a `network` if you would like to access testnet networks.
42+
- The default value is `Network.MAINNET`, which represents the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet
43+
- Can also select `Network.TESTNET`, which represents the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).
44+
- `apiUrl` if you would like to access another OpenSea Stream API endpoint. Not needed if you provide a network or use the default values.
45+
- an `onError` callback to handle errors. The default behavior is to `console.error` the error.
46+
- a `logLevel` to set the log level. The default is `LogLevel.INFO`.
47+
48+
## Available Networks
49+
50+
The OpenSea Stream API is available on the following networks:
51+
52+
### Mainnet
53+
54+
`wss://stream.openseabeta.com/socket`
55+
56+
Mainnet supports events from the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet.
57+
58+
### Testnet
59+
60+
`wss://testnets-stream.openseabeta.com/socket`
61+
62+
Testnet supports events from the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).
63+
64+
To create testnet instance of the client, you can create it with the following arguments:
65+
66+
```javascript
67+
import { OpenSeaStreamClient, Network } from '@opensea/opensea-stream-js-sdk';
68+
69+
const client = new OpenSeaStreamClient({
70+
network: Network.TESTNET,
71+
token: 'openseaApiKey'
72+
});
73+
```
74+
75+
## Manually connecting to the socket (optional)
76+
77+
The client will automatically connect to the socket as soon as you subscribe to the first channel.
78+
If you would like to connect to the socket manually (before that), you can do so:
79+
80+
```javascript
81+
client.connect();
82+
```
83+
84+
After successfully connecting to our websocket it is time to listen to specific events you're interested in!
85+
86+
## Streaming metadata updates
87+
88+
We will only send out metadata updates when we detect that the metadata provided in `tokenURI` has changed from what OpenSea has previously cached.
89+
90+
```javascript
91+
client.onItemMetadataUpdated('collection-slug', (event) => {
92+
// handle event
93+
});
94+
```
95+
96+
## Streaming item listed events
97+
98+
```javascript
99+
client.onItemListed('collection-slug', (event) => {
100+
// handle event
101+
});
102+
```
103+
104+
## Streaming item sold events
105+
106+
```javascript
107+
client.onItemSold('collection-slug', (event) => {
108+
// handle event
109+
});
110+
```
111+
112+
## Streaming item transferred events
113+
114+
```javascript
115+
client.onItemTransferred('collection-slug', (event) => {
116+
// handle event
117+
});
118+
```
119+
120+
## Streaming bids and offers
121+
122+
```javascript
123+
client.onItemReceivedBid('collection-slug', (event) => {
124+
// handle event
125+
});
126+
127+
client.onItemReceivedOffer('collection-slug', (event) => {
128+
// handle event
129+
});
130+
```
131+
132+
## Streaming multiple event types
133+
134+
```javascript
135+
client.onEvents(
136+
'collection-slug',
137+
[EventType.ITEM_RECEIVED_OFFER, EventType.ITEM_TRANSFERRED],
138+
(event) => {
139+
// handle event
140+
}
141+
);
142+
```
143+
144+
## Streaming order cancellations events
145+
146+
```javascript
147+
client.onItemCancelled('collection-slug', (event) => {
148+
// handle event
149+
});
150+
```
151+
152+
# Subscribing to events from all collections
153+
154+
If you'd like to listen to an event from all collections use wildcard `*` for the `collectionSlug` parameter.
155+
156+
# Types
157+
158+
Types are included to make working with our event payload objects easier.
159+
160+
# Disconnecting
161+
162+
## From a specific stream
163+
164+
All subscription methods return a callback function that will unsubscribe from a stream when invoked.
165+
166+
```javascript
167+
const unsubscribe = client.onItemMetadataUpdated('collection-slug', noop);
168+
169+
unsubscribe();
170+
```
171+
172+
## From the socket
173+
174+
```javascript
175+
client.disconnect();
176+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opensea/opensea-stream-js-sdk",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "An SDK to receive pushed updates from OpenSea over websocket",
55
"license": "MIT",
66
"author": "OpenSea Developers",

0 commit comments

Comments
 (0)