Skip to main content

SolanaRpcClient

Struct SolanaRpcClient 

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

Blocking Solana JSON-RPC 2.0 client.

Mirrors the Python SolanaNetwork class from coldstar-devsyrem.

Implementations§

Source§

impl SolanaRpcClient

Source

pub fn new(rpc_url: Option<&str>) -> Result<Self>

Create a new client pointing at rpc_url.

The URL must start with http:// or https://. If None is passed the default from ColdstarConfig is used.

Source

pub fn from_config(cfg: &ColdstarConfig) -> Result<Self>

Build a client from an existing ColdstarConfig.

Source

pub fn rpc_url(&self) -> &str

Return the RPC URL this client is connected to.

Source

pub fn get_balance(&self, pubkey: &str) -> Result<u64>

Get SOL balance for pubkey in lamports.

Source

pub fn get_balance_sol(&self, pubkey: &str) -> Result<f64>

Get SOL balance for pubkey in SOL (floating point).

Source

pub fn get_latest_blockhash(&self) -> Result<String>

Fetch the latest blockhash and last valid block height.

Source

pub fn get_latest_blockhash_with_height(&self) -> Result<(String, u64)>

Fetch the latest blockhash together with the last valid block height.

Source

pub fn get_minimum_balance_for_rent_exemption( &self, data_len: usize, ) -> Result<u64>

Get the minimum lamport balance required for rent exemption at data_len bytes of account data.

Source

pub fn send_transaction(&self, signed_tx_base64: &str) -> Result<String>

Broadcast a signed transaction encoded as base-64.

Returns the transaction signature on success.

Source

pub fn confirm_transaction( &self, signature: &str, timeout_secs: u64, ) -> Result<bool>

Poll getSignatureStatuses until the transaction reaches confirmed or finalized, or the timeout elapses.

timeout_secs defaults to 30 if set to 0.

Source

pub fn request_airdrop(&self, pubkey: &str, lamports: u64) -> Result<String>

Request an airdrop of lamports to pubkey (devnet/testnet only).

Returns the airdrop transaction signature.

Source

pub fn get_account_info(&self, pubkey: &str) -> Result<Option<AccountInfo>>

Get on-chain account information for pubkey.

Returns None when the account does not exist.

Source

pub fn is_connected(&self) -> bool

Check whether the RPC endpoint is healthy.

Source

pub fn get_network_info(&self) -> Result<NetworkInfo>

Collect high-level network information (version, slot, epoch).

Source

pub fn get_transaction_history( &self, pubkey: &str, limit: usize, ) -> Result<Vec<TransactionRecord>>

Get recent transaction signatures for pubkey.

Source

pub fn get_transaction_details( &self, signature: &str, ) -> Result<TransactionDetails>

Get full details for a single transaction by signature.

Trait Implementations§

Source§

impl Debug for SolanaRpcClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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<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