pub struct SuiClient { /* private fields */ }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
impl SuiClient
pub fn builder() -> SuiClientBuilder
Sourcepub fn available_rpc_methods(&self) -> &Vec<String>
pub fn available_rpc_methods(&self) -> &Vec<String>
Returns a list of RPC methods supported by the node the client is connected to.
Sourcepub fn available_subscriptions(&self) -> &Vec<String>
pub fn available_subscriptions(&self) -> &Vec<String>
Returns a list of streaming/subscription APIs supported by the node the client is connected to.
Sourcepub fn api_version(&self) -> &str
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.
Sourcepub fn check_api_version(&self) -> SuiClientResult<()>
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.
Sourcepub fn http(&self) -> &HttpClient
pub fn http(&self) -> &HttpClient
Returns a reference to the underlying http client.
Sourcepub fn ws(&self) -> Option<&WsClient>
pub fn ws(&self) -> Option<&WsClient>
Returns a reference to the underlying WebSocket client, if any.
pub async fn get_imm_or_owned_oarg(&self, id: Address) -> SuiClientResult<Input>
Sourcepub 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>>
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>>
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).
Sourcepub async fn full_object(
&self,
id: Address,
) -> Result<Object, Box<dyn Error + Send + Sync + 'static>>
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.
Sourcepub 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>>
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>>
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).
Sourcepub async fn multi_get_objects<I>(
&self,
object_ids: I,
options: SuiObjectDataOptions,
) -> SuiClientResult<Vec<SuiObjectResponse>>
pub async fn multi_get_objects<I>( &self, object_ids: I, options: SuiObjectDataOptions, ) -> SuiClientResult<Vec<SuiObjectResponse>>
Return the object data for a list of objects.
This method works for any number of object ids.
Sourcepub async fn submit_transaction(
&self,
tx_data: &Transaction,
signatures: &[UserSignature],
options: Option<SuiTransactionBlockResponseOptions>,
) -> Result<SuiTransactionBlockResponse, JsonRpcClientError>
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.
Sourcepub async fn dry_run_transaction(
&self,
tx_kind: &TransactionKind,
sender: Address,
gas_price: u64,
) -> Result<DryRunTransactionBlockResponse, JsonRpcClientError>
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.
Sourcepub async fn gas_budget(
&self,
tx_kind: &TransactionKind,
sender: Address,
price: u64,
) -> Result<u64, DryRunError>
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.
Sourcepub async fn gas_budget_with_options(
&self,
tx_kind: &TransactionKind,
sender: Address,
options: GasBudgetOptions,
) -> Result<u64, DryRunError>
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.
Sourcepub async fn get_gas_data(
&self,
tx_kind: &TransactionKind,
sponsor: Address,
budget: u64,
price: u64,
) -> Result<GasPayment, GetGasDataError>
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.
Sourcepub async fn get_gas_payment(
&self,
sponsor: Address,
budget: u64,
exclude: &[Address],
) -> Result<Vec<(Address, Version, Digest)>, NotEnoughGasError>
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.
pub async fn select_coins( &self, address: Address, coin_type: Option<String>, amount: u64, exclude: Vec<Address>, ) -> SuiClientResult<Vec<Coin>>
Sourcepub async fn coins_for_amount(
&self,
address: Address,
coin_type: Option<String>,
amount: u64,
exclude: &[Address],
) -> SuiClientResult<Vec<Coin>>
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(())
}Sourcepub fn coins_for_address(
&self,
address: Address,
coin_type: Option<String>,
page_size: Option<u32>,
) -> impl Stream<Item = SuiClientResult<Coin>> + Send + '_
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(())
}Sourcepub fn owned_objects(
&self,
owner: Address,
query: Option<SuiObjectResponseQuery>,
page_size: Option<u32>,
) -> impl Stream<Item = SuiClientResult<SuiObjectData>> + Send + '_
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.
Sourcepub async fn latest_object_ref(
&self,
object_id: Address,
) -> SuiClientResult<(Address, Version, Digest)>
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§
Auto Trait Implementations§
impl Freeze for SuiClient
impl !RefUnwindSafe for SuiClient
impl Send for SuiClient
impl Sync for SuiClient
impl Unpin for SuiClient
impl !UnwindSafe for SuiClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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