Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/rpc-subscriptions-spec

Package Overview
Dependencies
Maintainers
0
Versions
898
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/rpc-subscriptions-spec

A generic implementation of JSON RPC Subscriptions using proxies

  • 2.0.0-canary-20241015225219
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.1K
decreased by-39.77%
Maintainers
0
Weekly downloads
 
Created
Source

npm npm-downloads semantic-release
code-style-prettier

@solana/rpc-subscriptions-spec

This package contains types that describe the implementation of the JSON RPC Subscriptions API, as well as methods to create one. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK @solana/web3.js@rc.

This API is designed to be used as follows:

const rpcSubscriptions =
    // Step 1 - Create an `RpcSubscriptions` instance. This may be stateful.
    createSolanaRpcSubscriptions(mainnet('wss://api.mainnet-beta.solana.com'));
const response = await rpcSubscriptions
    // Step 2 - Call supported methods on it to produce `PendingRpcSubscriptionsRequest` objects.
    .slotNotifications({ commitment: 'confirmed' })
    // Step 3 - Call the `subscribe()` method on those pending requests to trigger them.
    .subscribe({ abortSignal: AbortSignal.timeout(10_000) });
// Step 4 - Iterate over the result.
try {
    for await (const slotNotification of slotNotifications) {
        console.log('Got a slot notification', slotNotification);
    }
} catch (e) {
    console.error('The subscription closed unexpectedly', e);
} finally {
    console.log('We have stopped listening for notifications');
}

Types

RpcSubscriptionsChannel<TOutboundMessage, TInboundMessage>

A channel is a DataPublisher that you can subscribe to events of type RpcSubscriptionChannelEvents<TInboundMessage>. Additionally, you can use it to send messages of type TOutboundMessage back to the remote end by calling the send(message) method.

RpcSubscriptionsChannelCreator<TOutboundMessage, TInboundMessage>

A channel creator is a function that accepts an AbortSignal, returns a new RpcSubscriptionsChannel, and tears down the channel when the abort signal fires.

RpcSubscriptionChannelEvents<TInboundMessage>

Subscription channels publish events on two channel names:

  • error: Fires when the channel closes unexpectedly
  • message: Fires on every message received from the remote end

Functions

executeRpcPubSubSubscriptionPlan({ channel, responseTransformer, signal, subscribeMethodName, subscribeParams, unsubscribeMethodName })

Given a channel, this function executes the particular subscription plan required by the Solana JSON RPC Subscriptions API.

  1. Calls the subscribeMethodName on the remote RPC
  2. Waits for a response containing the subscription id
  3. Returns a DataPublisher that publishes notifications related to that subscriptions id, filtering out all others
  4. Calls the unsubscribeMethodName on the remote RPC when the abort signal is fired.

Keywords

FAQs

Package last updated on 15 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc