pub struct CoinReadApi { /* private fields */ }Expand description
Coin Read API provides the functionality needed to get information from the Sui network regarding the coins owned by an address.
Implementations§
Source§impl CoinReadApi
impl CoinReadApi
Sourcepub async fn get_coins(
&self,
owner: SuiAddress,
coin_type: Option<String>,
cursor: Option<String>,
limit: Option<usize>,
) -> SuiRpcResult<CoinPage>
pub async fn get_coins( &self, owner: SuiAddress, coin_type: Option<String>, cursor: Option<String>, limit: Option<usize>, ) -> SuiRpcResult<CoinPage>
Return a paginated response with the coins for the given address, or an error upon failure.
The coins can be filtered by coin_type (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)
or use None for the default Coin<SUI>.
§Examples
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let coins = sui
.coin_read_api()
.get_coins(address, None, None, None)
.await?;
Ok(())
}Sourcepub async fn get_all_coins(
&self,
owner: SuiAddress,
cursor: Option<String>,
limit: Option<usize>,
) -> SuiRpcResult<CoinPage>
pub async fn get_all_coins( &self, owner: SuiAddress, cursor: Option<String>, limit: Option<usize>, ) -> SuiRpcResult<CoinPage>
Return a paginated response with all the coins for the given address, or an error upon failure.
This function includes all coins. If needed to filter by coin type, use the get_coins method instead.
§Examples
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let coins = sui
.coin_read_api()
.get_all_coins(address, None, None)
.await?;
Ok(())
}Sourcepub fn get_coins_stream(
&self,
owner: SuiAddress,
coin_type: Option<String>,
) -> impl Stream<Item = Coin> + '_
pub fn get_coins_stream( &self, owner: SuiAddress, coin_type: Option<String>, ) -> impl Stream<Item = Coin> + '_
Return the coins for the given address as a stream.
The coins can be filtered by coin_type (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)
or use None for the default Coin<SUI>.
§Examples
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let coins = sui
.coin_read_api()
.get_coins_stream(address, None);
Ok(())
}Sourcepub async fn select_coins(
&self,
address: SuiAddress,
coin_type: Option<String>,
amount: u128,
exclude: Vec<ObjectID>,
) -> SuiRpcResult<Vec<Coin>>
pub async fn select_coins( &self, address: SuiAddress, coin_type: Option<String>, amount: u128, exclude: Vec<ObjectID>, ) -> SuiRpcResult<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_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let coins = sui
.coin_read_api()
.select_coins(address, None, 5, vec![])
.await?;
Ok(())
}Sourcepub async fn get_balance(
&self,
owner: SuiAddress,
coin_type: Option<String>,
) -> SuiRpcResult<Balance>
pub async fn get_balance( &self, owner: SuiAddress, coin_type: Option<String>, ) -> SuiRpcResult<Balance>
Return the balance for the given coin type owned by address, or an error upon failure.
Note that this function sums up all the balances of all the coins matching
the given coin type. By default, if coin_type is set to None,
it will use the default Coin<SUI>.
§Examples
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let balance = sui
.coin_read_api()
.get_balance(address, None)
.await?;
Ok(())
}Sourcepub async fn get_all_balances(
&self,
owner: SuiAddress,
) -> SuiRpcResult<Vec<Balance>>
pub async fn get_all_balances( &self, owner: SuiAddress, ) -> SuiRpcResult<Vec<Balance>>
Return a list of balances for each coin type owned by the given address, or an error upon failure.
Note that this function groups the coins by coin type, and sums up all their balances.
§Examples
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::SuiAddress;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let address = SuiAddress::from_str("0x0000....0000")?;
let all_balances = sui
.coin_read_api()
.get_all_balances(address)
.await?;
Ok(())
}Sourcepub async fn get_coin_metadata(
&self,
coin_type: String,
) -> SuiRpcResult<Option<SuiCoinMetadata>>
pub async fn get_coin_metadata( &self, coin_type: String, ) -> SuiRpcResult<Option<SuiCoinMetadata>>
Return the coin metadata (name, symbol, description, decimals, etc.) for a given coin type, or an error upon failure.
§Examples
use sui_sdk::SuiClientBuilder;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let coin_metadata = sui
.coin_read_api()
.get_coin_metadata("0x2::sui::SUI".to_string())
.await?;
Ok(())
}Sourcepub async fn get_total_supply(&self, coin_type: String) -> SuiRpcResult<Supply>
pub async fn get_total_supply(&self, coin_type: String) -> SuiRpcResult<Supply>
Return the total supply for a given coin type, or an error upon failure.
§Examples
use sui_sdk::SuiClientBuilder;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default().build_localnet().await?;
let total_supply = sui
.coin_read_api()
.get_total_supply("0x2::sui::SUI".to_string())
.await?;
Ok(())
}Trait Implementations§
Source§impl Clone for CoinReadApi
impl Clone for CoinReadApi
Source§fn clone(&self) -> CoinReadApi
fn clone(&self) -> CoinReadApi
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CoinReadApi
impl !RefUnwindSafe for CoinReadApi
impl Send for CoinReadApi
impl Sync for CoinReadApi
impl Unpin for CoinReadApi
impl !UnwindSafe for CoinReadApi
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
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§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a Request§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.