npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@opensea/stream-js

v0.1.3

Published

An SDK to receive pushed updates from OpenSea over websocket

Downloads

2,937

Readme

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.