• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A TypeScript SDK to receive pushed updates from OpenSea over websocket.

Version npm Test CI Coverage Status License Docs

OpenSea Stream API - JavaScript SDK

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:

  • 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

We recommend switching to Node.js version 16 to make sure common crypto dependencies work. Our minimum supported version is 16.11.0.

  • Install this package with npm install @opensea/stream-js
  • NodeJS only: Install the WebSocket library with npm install ws
  • Install the required dev-dependency to use the Phoenix client for web socket connections npm install --save-dev @types/phoenix

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, request an API key from us here.

Create a client

Browser

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

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

Node.JS

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

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

You can also optionally pass in:

  • a network if you would like to access testnet networks.
    • The default value is Network.MAINNET, which represents the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet
    • Can also select Network.TESTNET, which represents the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).
  • 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

Mainnet supports events from the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet.

Testnet

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

Testnet supports events from the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).

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: 'openseaApiKey'
});

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.

More Repositories

1

opensea-js

TypeScript SDK for the OpenSea marketplace
TypeScript
2,278
star
2

seaport

Seaport is a marketplace protocol for safely and efficiently buying and selling NFTs.
Solidity
2,141
star
3

opensea-creatures

Example non-fungible collectible, to demonstrate OpenSea integration
JavaScript
1,167
star
4

opensea-erc1155

Example semi-fungible collectible, to demonstrate OpenSea integration for an ERC-1155 contract
JavaScript
605
star
5

embeddable-nfts

Easily embed OpenSea listings in your website!
TypeScript
329
star
6

operator-filter-registry

Solidity
311
star
7

seadrop

Smart contracts for primary drops on EVM chains
Solidity
290
star
8

seaport-js

A TypeScript library to interface with the Seaport marketplace.
TypeScript
255
star
9

opensea-whitelabel

Easily whitelabel an OpenSea marketplace for your own website
TypeScript
226
star
10

metadata-api-nodejs

Sample metadata API for crypto collectibles, written in Node.js
JavaScript
193
star
11

seaport-gossip

A peer-to-peer network for sharing Seaport orders.
TypeScript
125
star
12

metadata-api-python

Simple API for serving ERC721 metadata
Python
117
star
13

nft-tutorial

A very basic NFT tutorial repository for absolute beginners in the world of Web3 and smart contracts
JavaScript
96
star
14

marketplace-benchmarks

A comparison supported features and respective gas overhead for NFT marketplaces
Solidity
70
star
15

meta-transactions

Solidity
49
star
16

seaport-order-validator

Seaport Order Validator provides a simple method for validating and diagnosing Seaport orders
Solidity
48
star
17

shipyard-core

Solidity
48
star
18

seaport-core

Core Seaport smart contracts
Solidity
45
star
19

SIPs

The Seaport Improvement Proposal repository
31
star
20

ethmoji-contracts

Ethmoji smart contracts
JavaScript
22
star
21

seaport.py

Python
21
star
22

seaport-sol

Solidity helpers for working with Seaport on and off-chain using Forge scripts
Solidity
21
star
23

ships-log

An example dapp listing recent auctions and bids on OpenSea, with the ability to buy items or accept offers right from the page.
JavaScript
20
star
24

seaport-1.6

A unified repo containing the core Seaport contracts, types, tools, and tests to facilitate Seaport 1.6 development
Solidity
20
star
25

ethmoji-js

SDK for Ethmoji blockchain avatars
JavaScript
19
star
26

opensea-stream-discord-webhook

A sample repo showing how a developer using the OpenSea Stream API might be able to connect a Discord webhook to send messages whenever new events occur for a collection
TypeScript
18
star
27

0x-fee-wrapper

Solidity
16
star
28

shipyard

Template Repo for OpenSea smart contract development
Solidity
13
star
29

redeemables

EVM smart contracts for redeemables and dynamic traits
Solidity
12
star
30

seaport-types

Standalone structs and interfaces related to Seaport
Solidity
12
star
31

tstorish

Use TSTORE in contracts deployed to multiple chains with varying opcode support
Solidity
11
star
32

ethdenver-workshop

Devcon 5 workshop
JavaScript
10
star
33

seaport-generic-adapter

A proof of concept Seaport app that enables fulfilling non-Seaport listings through Seaport.
Solidity
10
star
34

seaport-deploy

A utility for deploying Seaport to local chains for use in testing.
Solidity
9
star
35

seaport-hooks

A collection of various Seaport Hooks (zone hooks, contract hooks, and item hooks): https://docs.opensea.io/docs/seaport-hooks
5
star
36

ethmoji-js-demo

JavaScript
5
star
37

jellyfish

Build UIs as state machines using Compose.
Kotlin
5
star
38

buy-sell-opensea-sdk-demo

https://docs.opensea.io/docs/buy-sell-nfts
TypeScript
3
star
39

vercel-repros

TypeScript
1
star