solana_kit_rpc_types 0.9.3 copy "solana_kit_rpc_types: ^0.9.3" to clipboard
solana_kit_rpc_types: ^0.9.3 copied to clipboard

Shared RPC types for the Solana Kit Dart SDK.

solana_kit_rpc_types #

pub package docs website CI coverage

Shared types used across the Solana Kit RPC stack. Defines commitment levels, lamports, blockhashes, transaction errors, token amounts, account info variants, and the SolanaRpcResponse<T> wrapper. Both solana_kit_rpc_api and solana_kit_rpc depend on this package for their parameter and response shapes.

Installation #

Install the package directly:

dependencies:
  "solana_kit_rpc_types": ^0.9.3

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 #

Commitment levels #

Commitment is an enum with three finality levels. commitmentComparator orders them by finality.

import 'package:solana_kit_rpc_types/solana_kit_rpc_types.dart';

void main() {
  const c1 = Commitment.processed;
  const c2 = Commitment.confirmed;
  const c3 = Commitment.finalized;

  print(commitmentComparator(c1, c3)); // -1
  print(commitmentComparator(c3, c3)); // 0
  print(c2);

  final list = [Commitment.finalized, Commitment.processed, Commitment.confirmed];
  list.sort(commitmentComparator);
  print(list); // [processed, confirmed, finalized]
}

Lamports #

Lamports wraps BigInt for values denominated in the smallest unit of SOL (1 SOL = 10^9 lamports).

import 'package:solana_kit_rpc_types/solana_kit_rpc_types.dart';

void main() {
  final oneSol = Lamports(BigInt.from(1000000000)); // 1 SOL

  final validated = lamports(BigInt.from(500000)); // validates range
  print(isLamports(BigInt.from(100))); // true
  print(isLamports(BigInt.from(-1))); // false

  // u64 little-endian codec.
  final encoder = getDefaultLamportsEncoder();
  final decoder = getDefaultLamportsDecoder();
  print(oneSol.value);
  print(validated.value);
  print(encoder.encode(oneSol).length);
  print(decoder.fixedSize);
}

Blockhash #

Blockhash wraps a validated base58-encoded string (32 bytes).

import 'package:solana_kit_rpc_types/solana_kit_rpc_types.dart';

void main() {
  const bh = Blockhash('4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY');
  final validated = blockhash('4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY');
  print(isBlockhash('too-short')); // false
  print(bh.value);
  print(validated.value);
}

Transaction and instruction errors #

Sealed class hierarchies represent Solana runtime errors.

import 'package:solana_kit_rpc_types/solana_kit_rpc_types.dart';

void main() {
  const simple = TransactionErrorSimple('BlockhashNotFound');
  const instrError = TransactionErrorInstructionError(
    0,
    InstructionErrorCustom(42),
  );
  print(simple.label); // 'BlockhashNotFound'
  print(instrError.instructionIndex); // 0
  print(instrError.instructionError.label); // 'Custom'
}

Token amounts and account info #

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

void main() {
  final tokenAmount = TokenAmount(
    amount: StringifiedBigInt('1000000'),
    decimals: 6,
    uiAmountString: StringifiedNumber('1'),
  );
  print(tokenAmount.amount); // '1000000'

  final accountInfo = AccountInfoBase(
    executable: false,
    lamports: Lamports(BigInt.from(1000000)),
    owner: Address('11111111111111111111111111111111'),
    space: BigInt.from(165),
  );
  print(accountInfo.lamports); // Lamports(1000000)
}

Cluster URLs, slots, and timestamps #

import 'package:solana_kit_rpc_types/solana_kit_rpc_types.dart';

void main() {
  // Branded cluster URL types for compile-time safety.
  final mainnetUrl = mainnet('https://api.mainnet-beta.solana.com');
  print(mainnetUrl);

  // Slot and Epoch are BigInt aliases.
  Slot currentSlot = BigInt.from(250000000);
  Epoch currentEpoch = BigInt.from(580);

  // UnixTimestamp wraps BigInt.
  final ts = UnixTimestamp(BigInt.from(1700000000));
  final validated = unixTimestamp(BigInt.from(1700000000));

  print(currentSlot);
  print(currentEpoch);
  print(ts.value);
  print(validated.value);
}

Key APIs #

  • Commitment enum: processed, confirmed, finalized.
  • Lamports(BigInt) / Blockhash(String) / UnixTimestamp(BigInt): validated extension types.
  • MicroLamports(BigInt) / StringifiedBigInt(String) / StringifiedNumber(String): string-encoded numeric types.
  • MainnetUrl / DevnetUrl / TestnetUrl: branded URL types via mainnet(), devnet(), testnet().
  • TokenAmount: amount, decimals, uiAmountString.
  • AccountInfoBase and encoding variants (AccountInfoWithBase64EncodedData, etc.).
  • TransactionError / InstructionError: sealed error hierarchies.
  • SolanaRpcResponse<T>: context + value wrapper for RPC responses.
  • Slot / Epoch / SignedLamports: BigInt type aliases.

Example #

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

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