Skip to main content

solana_kit_rpc_subscriptions 0.11.1 copy "solana_kit_rpc_subscriptions: ^0.11.1" to clipboard
solana_kit_rpc_subscriptions: ^0.11.1 copied to clipboard

Subscription client for the Solana Kit Dart SDK.

solana_kit_rpc_subscriptions #

pub package docs website CI coverage

Subscription client for the Solana Kit Dart SDK. createSolanaRpcSubscriptions wires a WebSocket channel, the subscriptions API, JSON serialization, and error handling into a client that streams account, signature, log, slot, and program notifications.

Installation #

Install the package directly:

dependencies:
  "solana_kit_rpc_subscriptions": ^0.11.1

If your app uses several Solana Kit packages together, you can also depend on the umbrella package instead:

dart pub add solana_kit

Inside this monorepo, Dart workspace resolution uses the local package automatically.

Documentation #

For architecture notes, getting-started guides, and cross-package examples, start with the workspace docs site and then drill down into the package README and API reference.

Usage #

Subscribing to notifications #

createSolanaRpcSubscriptions returns a client whose request method returns a PendingRpcSubscriptionsRequest. Call .subscribe(...) to send the JSON-RPC subscription request and await its server subscription ID. The returned stream emits only the matching notification result payloads; other requests and subscriptions on a shared channel are filtered out. Cancel with a CancellationTokenSource to unsubscribe and release listeners. Notifications that arrive during acquisition are retained until the first listener attaches, up to 1024 events; exceeding this bound ends the subscription with a StateError. Listen promptly after acquisition. Cancellation before acknowledgement still releases a late server subscription when its ID arrives.

import 'package:solana_kit_rpc_subscriptions/solana_kit_rpc_subscriptions.dart';
import 'package:solana_kit_subscribable/solana_kit_subscribable.dart';

Future<void> main() async {
  final subscriptions = createSolanaRpcSubscriptions(
    'wss://api.mainnet-beta.solana.com',
  );

  final controller = CancellationTokenSource();

  final pending = subscriptions.request('slotNotifications');
  final stream = await pending.subscribe(
    RpcSubscribeOptions(abortSignal: controller.token),
  );

  var count = 0;
  await for (final notification in stream) {
    print('Slot: $notification');
    count++;
    if (count >= 3) {
      controller.cancel();
    }
  }
}

Typed subscription methods #

The client exposes typed helpers for each subscription method, with parameter builders from solana_kit_rpc_subscriptions_api.

import 'package:solana_kit_rpc_subscriptions/solana_kit_rpc_subscriptions.dart';
import 'package:solana_kit_subscribable/solana_kit_subscribable.dart';

Future<void> main() async {
  final subscriptions = createSolanaRpcSubscriptions(
    'wss://api.mainnet-beta.solana.com',
  );

  final controller = CancellationTokenSource();
  final stream = await subscriptions
      .request('slotNotifications')
      .subscribe(RpcSubscribeOptions(abortSignal: controller.token));

  await for (final notification in stream) {
    print(notification);
    controller.cancel();
  }
}

Inbound resource limits #

DefaultRpcSubscriptionsChannelConfig accepts inboundLimits, maxPendingMessages, and maxPendingBytes. Defaults allow 16 MiB per inbound message, 64 JSON container levels, one million JSON tokens, and at most 128 messages or 16 MiB queued for each paused channel listener. Budget violations emit InboundPayloadLimitException and close the channel with application code 4009. See the WebSocket channel documentation for queue behavior and platform allocation limits.

Key APIs #

  • createSolanaRpcSubscriptions(url, [config]): the standard client factory.
  • RpcSubscriptions interface with request(methodName, params).
  • PendingRpcSubscriptionsRequest.subscribe(options) returning a Stream.
  • RpcSubscribeOptions with abortSignal for cancellation.

Example #

Use example/main.dart as a runnable starting point for solana_kit_rpc_subscriptions.

  • Import path: package:solana_kit_rpc_subscriptions/solana_kit_rpc_subscriptions.dart
  • This section is centrally maintained with mdt to keep package guidance aligned.
  • After updating shared docs templates, run docs:update from the repo root.

Maintenance #

  • Validate docs in CI and locally with docs:check.
  • Keep examples focused on one workflow and reference package README sections for deeper API details.