Struct RpcClient

Source
pub struct RpcClient { /* private fields */ }
Expand description

The Client.

Implementations§

Source§

impl Client

Source

pub fn new(sender: RpcChannel) -> Self

Creates a new Client.

Source

pub fn slot_subscribe(&self) -> RpcResult<TypedSubscriptionStream<SlotInfo>>

Subscribe to slot notifications.

This method allows clients to subscribe to updates for a specific slot. The subscriber will receive notifications whenever the slot changes.

§Parameters
  • meta: WebSocket metadata containing RPC context and connection information.
  • subscriber: The subscription sink for sending slot update notifications to the client.
§Returns

This method does not return a value directly. Instead, it establishes a continuous WebSocket subscription that will send SlotInfo notifications to the subscriber whenever the slot changes.

§Example WebSocket Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "slotSubscribe",
  "params": [
    {
      "commitment": "finalized"
    }
  ]
}
§Example WebSocket Response (Subscription Confirmation)
{
  "jsonrpc": "2.0",
  "result": 5207624,
  "id": 1
}
§Example WebSocket Notification
{
  "jsonrpc": "2.0",
  "method": "slotNotification",
  "params": {
    "result": {
      "slot": 5207624
    },
    "subscription": 5207624
  }
}
§Notes
  • The subscription remains active until explicitly unsubscribed or the connection is closed.
  • Slot notifications are sent whenever the slot changes.
  • The subscription automatically terminates when the slot changes.
  • Each subscription runs in its own async task for optimal performance.
§See Also
  • slotUnsubscribe: Remove an active slot subscription
Source

pub fn account_subscribe( &self, pubkey_str: String, config: Option<RpcAccountSubscribeConfig>, ) -> RpcResult<TypedSubscriptionStream<RpcResponse<UiAccount>>>

Subscribe to account change notifications via WebSocket.

This method allows clients to subscribe to updates for a specific account. The subscriber will receive notifications whenever the account’s data, lamports balance, ownership, or other properties change.

§Parameters
  • meta: WebSocket metadata containing RPC context and connection information.
  • subscriber: The subscription sink for sending account update notifications to the client.
  • pubkey_str: The account public key to monitor, as a base-58 encoded string.
  • config: Optional configuration specifying commitment level and encoding format for account data.
§Returns

This method does not return a value directly. Instead, it establishes a continuous WebSocket subscription that will send RpcResponse<UiAccount> notifications to the subscriber whenever the account state changes.

§Example WebSocket Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "accountSubscribe",
  "params": [
    "CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",
    {
      "commitment": "finalized",
      "encoding": "base64"
    }
  ]
}
§Example WebSocket Response (Subscription Confirmation)
{
  "jsonrpc": "2.0",
  "result": 23784,
  "id": 1
}
§Example WebSocket Notification
{
  "jsonrpc": "2.0",
  "method": "accountNotification",
  "params": {
    "result": {
      "context": {
        "slot": 5208469
      },
      "value": {
        "data": ["base64EncodedAccountData", "base64"],
        "executable": false,
        "lamports": 33594,
        "owner": "11111111111111111111111111111112",
        "rentEpoch": 636
      }
    },
    "subscription": 23784
  }
}
§Notes
  • The subscription remains active until explicitly unsubscribed or the connection is closed.
  • Account notifications are sent whenever any aspect of the account changes.
  • The encoding format specified in the config determines how account data is serialized.
  • Invalid public key formats will cause the subscription to be rejected with an error.
  • Each subscription runs in its own async task to ensure optimal performance.
§See Also
  • accountUnsubscribe: Remove an active account subscription
  • getAccountInfo: Get current account information
Source

pub fn signature_subscribe( &self, signature_str: String, config: Option<RpcSignatureSubscribeConfig>, ) -> RpcResult<TypedSubscriptionStream<RpcResponse<RpcSignatureResult>>>

Subscribe to signature status notifications via WebSocket.

This method allows clients to subscribe to status updates for a specific transaction signature. The subscriber will receive notifications when the transaction reaches the desired confirmation level or when it’s initially received by the network (if configured).

§Parameters
  • meta: WebSocket metadata containing RPC context and connection information.
  • subscriber: The subscription sink for sending signature status notifications to the client.
  • signature_str: The transaction signature to monitor, as a base-58 encoded string.
  • config: Optional configuration specifying commitment level and notification preferences.
§Returns

This method does not return a value directly. Instead, it establishes a WebSocket subscription that will send RpcResponse<RpcSignatureResult> notifications to the subscriber when the transaction status changes.

§Example WebSocket Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "signatureSubscribe",
  "params": [
    "2id3YC2jK9G5Wo2phDx4gJVAew8DcY5NAojnVuao8rkxwPYPe8cSwE5GzhEgJA2y8fVjDEo6iR6ykBvDxrTQrtpb",
    {
      "commitment": "finalized",
      "enableReceivedNotification": false
    }
  ]
}
§Example WebSocket Response (Subscription Confirmation)
{
  "jsonrpc": "2.0",
  "result": 0,
  "id": 1
}
§Example WebSocket Notification
{
  "jsonrpc": "2.0",
  "method": "signatureNotification",
  "params": {
    "result": {
      "context": {
        "slot": 5207624
      },
      "value": {
        "err": null
      }
    },
    "subscription": 0
  }
}
§Notes
  • If the transaction already exists with the desired confirmation status, the subscriber will be notified immediately and the subscription will complete.
  • The subscription automatically terminates after sending the first matching notification.
  • Invalid signature formats will cause the subscription to be rejected with an error.
  • Each subscription runs in its own async task for optimal performance.
§See Also
  • signatureUnsubscribe: Remove an active signature subscription
  • getSignatureStatuses: Get current status of multiple signatures
Source

pub fn logs_subscribe( &self, mentions: Option<RpcTransactionLogsFilter>, commitment: Option<CommitmentLevel>, ) -> RpcResult<TypedSubscriptionStream<RpcResponse<RpcLogsResponse>>>

Subscribe to logs notifications.

This method allows clients to subscribe to transaction log messages emitted during transaction execution. It supports filtering by signature, account mentions, or all transactions.

§Parameters
  • meta: WebSocket metadata containing RPC context and connection information.
  • subscriber: The subscription sink for sending log notifications to the client.
  • mentions: Optional filter for the subscription: can be a specific signature, account, or "all".
  • commitment: Optional commitment level for filtering logs by block finality.
§Returns

This method establishes a continuous WebSocket subscription that streams RpcLogsResponse notifications as new transactions are processed.

§Example WebSocket Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "logsSubscribe",
  "params": [
    {
      "mentions": ["11111111111111111111111111111111"]
    },
    {
      "commitment": "finalized"
    }
  ]
}
§Example WebSocket Response (Subscription Confirmation)
{
  "jsonrpc": "2.0",
  "result": 42,
  "id": 1
}
§Example WebSocket Notification
{
  "jsonrpc": "2.0",
  "method": "logsNotification",
  "params": {
    "result": {
      "signature": "3s6n...",
      "err": null,
      "logs": ["Program 111111... invoke [1]", "Program 111111... success"]
    },
    "subscription": 42
  }
}
§Notes
  • The subscription remains active until explicitly unsubscribed or the connection is closed.
  • Each log subscription runs independently and supports filtering.
  • Log messages may be truncated depending on cluster configuration.
§See Also
  • logsUnsubscribe: Remove an active logs subscription.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<RpcChannel> for Client

Source§

fn from(channel: RpcChannel) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,