solana_kit_rpc 0.9.1 copy "solana_kit_rpc: ^0.9.1" to clipboard
solana_kit_rpc: ^0.9.1 copied to clipboard

Primary RPC client for the Solana Kit Dart SDK.

solana_kit_rpc #

pub package docs website CI coverage

The primary RPC client for the Solana Kit Dart SDK. createSolanaRpc wires the HTTP transport, request transformers, and typed method builders into a single Rpc you can call directly.

Most applications should use this package (or the solana_kit umbrella) for JSON-RPC access to a Solana node.

Installation #

Install the package directly:

dependencies:
  "solana_kit_rpc": ^0.9.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 #

Create a client #

import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_rpc/solana_kit_rpc.dart';

Future<void> main() async {
  final rpc = createSolanaRpc(url: 'https://api.mainnet-beta.solana.com');

  final slot = await rpc.getSlot().send();
  print('Current slot: $slot');

  final balance = await rpc
      .getBalance(const Address('83astBRguLMdt2h5U1Tbd4hU5SkfAWRkzG2HPM88BREAK'))
      .send();
  print('Balance: $balance');
}

rpc.getSlot() builds a typed request. The network call only happens when you call .send(), which keeps requests easy to inspect, compose, cache, batch, or wrap with middleware.

Typed RPC methods #

When you already have an Rpc, prefer typed convenience helpers over raw method-name strings. They keep parameter builders and response models attached to the method itself, which makes refactors and autocomplete significantly safer.

import 'package:solana_kit_rpc/solana_kit_rpc.dart';

Future<void> main() async {
  final rpc = createSolanaRpc(url: 'https://api.mainnet-beta.solana.com');

  final slot = await rpc.getSlot().send();
  final epochInfo = await rpc.getEpochInfo().send();
  final latestBlockhash = await rpc.getLatestBlockhashValue().send();

  print('Slot: $slot');
  print('Epoch: ${epochInfo['epoch']}');
  print('Latest blockhash: ${latestBlockhash.value.blockhash}');
}

These helpers forward to canonical request builders in solana_kit_rpc_api, return lazy PendingRpcRequest<T> values, and make it clear which Solana RPC shape each call expects.

Preferred Dart path

Start with createSolanaRpc(...) plus typed request helpers like rpc.getSlot() and rpc.getLatestBlockhashValue() before reaching for raw JSON-RPC method names.

Use raw rpc.request(...) only when you need an upstream surface that has not yet been wrapped or when you are validating parity behavior.

Raw requests #

For methods without a typed helper, call rpc.request(methodName, params) directly.

import 'package:solana_kit_rpc/solana_kit_rpc.dart';

Future<void> main() async {
  final rpc = createSolanaRpc(url: 'https://api.mainnet-beta.solana.com');

  final result = await rpc
      .request<Object?>('getSlot', <Object?>[])
      .send();
  print('Raw result: $result');
}

Custom transports #

createSolanaRpcFromTransport builds a client over any transport, which is how tests inject mocks.

import 'package:solana_kit_rpc/solana_kit_rpc.dart';

Future<void> main() async {
  final rpc = createSolanaRpcFromTransport(
    (config) async => <String, Object?>{'result': 42},
  );

  final slot = await rpc.getSlot().send();
  print('Mock slot: $slot');
}

Payload deduplication #

getSolanaRpcPayloadDeduplicationKey produces a stable key for a request payload, useful for caching or batching identical calls.

import 'package:solana_kit_rpc/solana_kit_rpc.dart';

void main() {
  final payload = <String, Object?>{
    'id': '1',
    'jsonrpc': '2.0',
    'method': 'getBalance',
    'params': ['11111111111111111111111111111111'],
  };

  final dedupeKey = getSolanaRpcPayloadDeduplicationKey(payload);
  print('Deduplication key: $dedupeKey');
}

Key APIs #

  • createSolanaRpc({url, ...}): the standard client factory.
  • createSolanaRpcFromTransport(transport): client over a custom transport.
  • Rpc interface with typed method helpers and request(...).
  • getSolanaRpcPayloadDeduplicationKey(payload).

Example #

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

  • Import path: package:solana_kit_rpc/solana_kit_rpc.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.