SuiClient

Struct SuiClient 

Source
pub struct SuiClient { /* private fields */ }
Available on crate feature client only.
Expand description

SuiClient is the basic type that provides all the necessary abstractions for interacting with the Sui network.

§Usage

Use SuiClientBuilder to build a SuiClient.

Implementations§

Source§

impl SuiClient

Source

pub fn builder() -> SuiClientBuilder

Source

pub fn available_rpc_methods(&self) -> &Vec<String>

Returns a list of RPC methods supported by the node the client is connected to.

Source

pub fn available_subscriptions(&self) -> &Vec<String>

Returns a list of streaming/subscription APIs supported by the node the client is connected to.

Source

pub fn api_version(&self) -> &str

Returns the API version information as a string.

The format of this string is <major>.<minor>.<patch>, e.g., 1.6.0, and it is retrieved from the OpenRPC specification via the discover service method.

Source

pub fn check_api_version(&self) -> SuiClientResult<()>

Verifies if the API version matches the server version and returns an error if they do not match.

Source

pub fn http(&self) -> &HttpClient

Returns a reference to the underlying http client.

Source

pub fn ws(&self) -> Option<&WsClient>

Returns a reference to the underlying WebSocket client, if any.

Source

pub async fn get_shared_oarg( &self, id: Address, mutable: bool, ) -> SuiClientResult<Input>

Source

pub async fn get_imm_or_owned_oarg(&self, id: Address) -> SuiClientResult<Input>

Source

pub async fn object_args<Iter>( &self, ids: Iter, ) -> Result<impl Iterator<Item = Result<Input, Box<dyn Error + Send + Sync + 'static>>> + use<Iter>, Box<dyn Error + Send + Sync + 'static>>
where Iter: IntoIterator<Item = Address> + Send, Iter::IntoIter: Send,

Query the PTB args for several objects.

Mutability (for shared objects) defaults to false.

This has no consistency guarantees, i.e., object versions may come from different points in the chain’s history (i.e., from different checkpoints).

Source

pub async fn full_object( &self, id: Address, ) -> Result<Object, Box<dyn Error + Send + Sync + 'static>>

Query the full object contents as a standard Sui type.

Source

pub async fn full_objects<Iter>( &self, ids: Iter, ) -> Result<impl Iterator<Item = Result<Object, Box<dyn Error + Send + Sync + 'static>>>, Box<dyn Error + Send + Sync + 'static>>
where Iter: IntoIterator<Item = Address> + Send, Iter::IntoIter: Send,

Query the full contents for several objects.

This has no consistency guarantees, i.e., object versions may come from different points in the chain’s history (i.e., from different checkpoints).

Source

pub async fn multi_get_objects<I>( &self, object_ids: I, options: SuiObjectDataOptions, ) -> SuiClientResult<Vec<SuiObjectResponse>>
where I: IntoIterator<Item = Address> + Send, I::IntoIter: Send,

Return the object data for a list of objects.

This method works for any number of object ids.

Source

pub async fn submit_transaction( &self, tx_data: &Transaction, signatures: &[UserSignature], options: Option<SuiTransactionBlockResponseOptions>, ) -> Result<SuiTransactionBlockResponse, JsonRpcClientError>

Helper to execute a transaction using standard Sui types.

See JsonRpcClientErrorExt::as_error_object and ErrorObjectExt for how to inspect the error in case a transaction failed before being included in a checkpoint.

Source

pub async fn dry_run_transaction( &self, tx_kind: &TransactionKind, sender: Address, gas_price: u64, ) -> Result<DryRunTransactionBlockResponse, JsonRpcClientError>

Helper to dry run a transaction kind for its effects.

This sets the gas budget to the maximum possible. If you want to test different values, manually perform the dry-run using the inner Self::http client.

Source

pub async fn gas_budget( &self, tx_kind: &TransactionKind, sender: Address, price: u64, ) -> Result<u64, DryRunError>

Estimate a budget for the transaction by dry-running it.

Uses default GasBudgetOptions to compute the cost estimate.

Source

pub async fn gas_budget_with_options( &self, tx_kind: &TransactionKind, sender: Address, options: GasBudgetOptions, ) -> Result<u64, DryRunError>

Estimate a budget for the transaction by dry-running it.

Source

pub async fn get_gas_data( &self, tx_kind: &TransactionKind, sponsor: Address, budget: u64, price: u64, ) -> Result<GasPayment, GetGasDataError>

Build the gas data for a transaction by querying the node for gas objects.

Source

pub async fn get_gas_payment( &self, sponsor: Address, budget: u64, exclude: &[Address], ) -> Result<Vec<(Address, Version, Digest)>, NotEnoughGasError>

Query the node for gas objects to fulfill a certain budget.

excludes certain object ids from being part of the returned objects.

Source

pub async fn select_coins( &self, address: Address, coin_type: Option<String>, amount: u64, exclude: Vec<Address>, ) -> SuiClientResult<Vec<Coin>>

👎Deprecated since 0.14.5: use SuiClient::coins_for_amount
Source

pub async fn coins_for_amount( &self, address: Address, coin_type: Option<String>, amount: u64, exclude: &[Address], ) -> SuiClientResult<Vec<Coin>>

Return a list of coins for the given address, or an error upon failure.

Note that the function selects coins to meet or exceed the requested amount. If that it is not possible, it will fail with an insufficient fund error.

The coins can be filtered by coin_type (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC) or use None to use the default Coin<SUI>.

§Examples
use sui_jsonrpc::client::SuiClientBuilder;
use sui_sdk_types::Address;

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
    let sui = SuiClientBuilder::default().build_localnet().await?;
    let address = "0x0000....0000".parse()?;
    let coins = sui
        .select_coins(address, None, 5, vec![])
        .await?;
    Ok(())
}
Source

pub fn coins_for_address( &self, address: Address, coin_type: Option<String>, page_size: Option<u32>, ) -> impl Stream<Item = SuiClientResult<Coin>> + Send + '_

Return a stream of coins for the given address, or an error upon failure.

This simply wraps a paginated query. Use page_size to control the inner query’s page size.

The coins can be filtered by coin_type (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC) or use None to use the default Coin<SUI>.

§Examples
use sui_jsonrpc::client::SuiClientBuilder;
use sui_sdk_types::Address;
use futures::TryStreamExt as _;

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
    let sui = SuiClientBuilder::default().build_localnet().await?;
    let address = "0x0000....0000".parse()?;
    let mut coins = std::pin::pin!(sui.coins_for_address(address, None, Some(5)));

    while let Some(coin) = coins.try_next().await? {
        println!("{coin:?}");
    }
    Ok(())
}
Source

pub fn owned_objects( &self, owner: Address, query: Option<SuiObjectResponseQuery>, page_size: Option<u32>, ) -> impl Stream<Item = SuiClientResult<SuiObjectData>> + Send + '_

Return a stream of objects owned by the given address.

This simply wraps a paginated query. Use page_size to control the inner query’s page size.

Source

pub async fn latest_object_ref( &self, object_id: Address, ) -> SuiClientResult<(Address, Version, Digest)>

Get the latest object reference for an ID from the node.

Trait Implementations§

Source§

impl Clone for SuiClient

Source§

fn clone(&self) -> SuiClient

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 Debug for SuiClient

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> 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> 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> 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,

Source§

impl<T> MaybeSend for T
where T: Send,