pub struct Client { /* private fields */ }Expand description
gRPC client factory for IOTA gRPC operations.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn execute_transaction(
&self,
signed_transaction: SignedTransaction,
read_mask: Option<&str>,
checkpoint_inclusion_timeout_ms: Option<u64>,
) -> Result<MetadataEnvelope<ExecutedTransaction>>
pub async fn execute_transaction( &self, signed_transaction: SignedTransaction, read_mask: Option<&str>, checkpoint_inclusion_timeout_ms: Option<u64>, ) -> Result<MetadataEnvelope<ExecutedTransaction>>
Execute a signed transaction.
This submits the transaction to the network for execution and waits for the result. The transaction must be signed with valid signatures.
Returns proto ExecutedTransaction. Use lazy conversion methods to
extract data:
result.effects()- Get transaction effectsresult.events()- Get transaction events (if available)result.input_objects()- Get input objects (if requested)result.output_objects()- Get output objects (if requested)
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns. If None, uses EXECUTE_TRANSACTIONS_READ_MASK which
includes effects, events, and input/output objects.
§Transaction Fields
transaction- includes all transaction fieldstransaction.digest- the transaction digesttransaction.bcs- the full BCS-encoded transaction
signatures- includes all signature fieldssignatures.bcs- the full BCS-encoded signature
effects- includes all effects fieldseffects.digest- the effects digesteffects.bcs- the full BCS-encoded effects
checkpoint- the checkpoint that included the transaction. Requirescheckpoint_inclusion_timeout_msto be set.timestamp- the timestamp of the checkpoint. Requirescheckpoint_inclusion_timeout_msto be set.
§Event Fields
events- includes all event fields (all events of the transaction)events.digest- the events digestevents.events.bcs- the full BCS-encoded eventevents.events.package_id- the ID of the package that emitted the eventevents.events.module- the module that emitted the eventevents.events.sender- the sender that triggered the eventevents.events.event_type- the type of the eventevents.events.bcs_contents- the full BCS-encoded contents of the eventevents.events.json_contents- the JSON-encoded contents of the event
§Object Fields
input_objects- includes all input object fieldsinput_objects.reference- includes all reference fieldsinput_objects.reference.object_id- the ID of the input objectinput_objects.reference.version- the version of the input objectinput_objects.reference.digest- the digest of the input object contents
input_objects.bcs- the full BCS-encoded object
output_objects- includes all output object fieldsoutput_objects.reference- includes all reference fieldsoutput_objects.reference.object_id- the ID of the output objectoutput_objects.reference.version- the version of the output objectoutput_objects.reference.digest- the digest of the output object contents
output_objects.bcs- the full BCS-encoded object
§Checkpoint Inclusion
If checkpoint_inclusion_timeout_ms is set, the server will wait up to
the specified duration (in milliseconds) for the transaction to be
included in a checkpoint before returning. When set, include
checkpoint and timestamp in the read_mask to receive the data.
§Example
let client = Client::connect("http://localhost:9000").await?;
let signed_tx: SignedTransaction = todo!();
// Execute transaction - returns proto type
let result = client.execute_transaction(signed_tx, None, None).await?;
// Lazy conversion - only deserialize what you need
let effects = result.body().effects()?.effects()?;
println!("Status: {:?}", effects.status());
let events = result.body().events()?.events()?;
if !events.0.is_empty() {
println!("Events: {}", events.0.len());
}Sourcepub async fn execute_transactions(
&self,
transactions: Vec<SignedTransaction>,
read_mask: Option<&str>,
checkpoint_inclusion_timeout_ms: Option<u64>,
) -> Result<MetadataEnvelope<Vec<Result<ExecutedTransaction>>>>
pub async fn execute_transactions( &self, transactions: Vec<SignedTransaction>, read_mask: Option<&str>, checkpoint_inclusion_timeout_ms: Option<u64>, ) -> Result<MetadataEnvelope<Vec<Result<ExecutedTransaction>>>>
Execute a batch of signed transactions.
Transactions are executed sequentially on the server. Each transaction is independent — failure of one does not abort the rest.
Returns a Vec<Result<ExecutedTransaction>> in the same order as the
input. Each element is either the successfully executed transaction or
the per-item error returned by the server.
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns for each ExecutedTransaction. If None, uses
EXECUTE_TRANSACTIONS_READ_MASK which includes effects, events, and
input/output objects.
See execute_transaction for the full list
of supported read mask fields.
§Checkpoint Inclusion
If checkpoint_inclusion_timeout_ms is set, the server will wait up to
the specified duration (in milliseconds) for all executed transactions
to be included in a checkpoint before returning. When set, include
checkpoint and timestamp in the read_mask to receive the data.
§Errors
Returns Error::EmptyRequest if transactions is empty.
Returns a transport-level Error::Grpc if the entire RPC fails
(e.g. batch size exceeded).
Source§impl Client
impl Client
Sourcepub async fn simulate_transaction(
&self,
transaction: Transaction,
skip_checks: bool,
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<SimulatedTransaction>>
pub async fn simulate_transaction( &self, transaction: Transaction, skip_checks: bool, read_mask: Option<&str>, ) -> Result<MetadataEnvelope<SimulatedTransaction>>
Simulate a transaction without executing it.
This allows you to preview the effects of a transaction before actually submitting it to the network.
§Parameters
transaction: The transaction to simulateskip_checks: Set to true for relaxed Move VM checks (useful for debugging and development)read_mask: Optional field mask to control which fields are returned
Returns [SimulatedTransaction] which contains:
executed_transaction()- Access to the simulated ExecutedTransactioncommand_results()- Access to intermediate command execution results
Use lazy conversion methods on the executed transaction to extract data:
result.executed_transaction()?.effects()- Get simulated effectsresult.executed_transaction()?.events()- Get simulated events (if available)result.executed_transaction()?.input_objects()- Get input objects (if requested)result.executed_transaction()?.output_objects()- Get output objects (if requested)
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns. If None, uses SIMULATE_TRANSACTIONS_READ_MASK which
includes effects, events, and input/output objects.
§Transaction Fields
executed_transaction- includes all executed transaction fieldsexecuted_transaction.transaction- includes all transaction fieldsexecuted_transaction.transaction.digest- the transaction digestexecuted_transaction.transaction.bcs- the full BCS-encoded transaction
executed_transaction.signatures- includes all signature fieldsexecuted_transaction.signatures.bcs- the full BCS-encoded signature
executed_transaction.effects- includes all effects fieldsexecuted_transaction.effects.digest- the effects digestexecuted_transaction.effects.bcs- the full BCS-encoded effects
executed_transaction.events- includes all event fieldsexecuted_transaction.events.digest- the events digestexecuted_transaction.events.events- includes all event fields (all events of the transaction)executed_transaction.events.events.bcs- the full BCS-encoded eventexecuted_transaction.events.events.package_id- the ID of the package that emitted the eventexecuted_transaction.events.events.module- the module that emitted the eventexecuted_transaction.events.events.sender- the sender that triggered the eventexecuted_transaction.events.events.event_type- the type of the eventexecuted_transaction.events.events.bcs_contents- the full BCS-encoded contents of the eventexecuted_transaction.events.events.json_contents- the JSON-encoded contents of the event
executed_transaction.checkpoint- the checkpoint that included the transaction (not available for just-executed transactions)executed_transaction.timestamp- the timestamp of the checkpoint (not available for just-executed transactions)executed_transaction.input_objects- includes all input object fieldsexecuted_transaction.input_objects.reference- includes all reference fieldsexecuted_transaction.input_objects.reference.object_id- the ID of the input objectexecuted_transaction.input_objects.reference.version- the version of the input objectexecuted_transaction.input_objects.reference.digest- the digest of the input object contents
executed_transaction.input_objects.bcs- the full BCS-encoded object
executed_transaction.output_objects- includes all output object fieldsexecuted_transaction.output_objects.reference- includes all reference fieldsexecuted_transaction.output_objects.reference.object_id- the ID of the output objectexecuted_transaction.output_objects.reference.version- the version of the output objectexecuted_transaction.output_objects.reference.digest- the digest of the output object contents
executed_transaction.output_objects.bcs- the full BCS-encoded object
§Gas Fields
suggested_gas_price- the suggested gas price for the transaction, denominated in NANOS
§Execution Result Fields
execution_result- the execution result (oneof: command_results on success, execution_error on failure)execution_result.command_results- includes all fields of per-command results if execution succeededexecution_result.command_results.mutated_by_ref- includes all fields of objects mutated by referenceexecution_result.command_results.mutated_by_ref.argument- the argument referenceexecution_result.command_results.mutated_by_ref.type_tag- the Move type tagexecution_result.command_results.mutated_by_ref.bcs- the BCS-encoded valueexecution_result.command_results.mutated_by_ref.json- the JSON-encoded value
execution_result.command_results.return_values- includes all fields of return values returned by the commandexecution_result.command_results.return_values.argument- the argument referenceexecution_result.command_results.return_values.type_tag- the Move type tagexecution_result.command_results.return_values.bcs- the BCS-encoded valueexecution_result.command_results.return_values.json- the JSON-encoded value
execution_result.execution_error- includes all fields of the execution error if execution failedexecution_result.execution_error.bcs_kind- the BCS-encoded error kindexecution_result.execution_error.source- the error source descriptionexecution_result.execution_error.command_index- the index of the command that failed
§Example
let client = Client::connect("http://localhost:9000").await?;
let tx: Transaction = todo!();
// Simulate transaction - returns proto type
let result = client.simulate_transaction(tx, false, None).await?;
// Lazy conversion - only deserialize what you need
let executed_tx = result.body().executed_transaction()?;
let effects = executed_tx.effects()?.effects()?;
println!("Simulation status: {:?}", effects.status());
let output_objs = executed_tx.output_objects()?;
println!("Would create {} objects", output_objs.objects.len());Sourcepub async fn simulate_transactions(
&self,
transactions: Vec<SimulateTransactionInput>,
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<Vec<Result<SimulatedTransaction>>>>
pub async fn simulate_transactions( &self, transactions: Vec<SimulateTransactionInput>, read_mask: Option<&str>, ) -> Result<MetadataEnvelope<Vec<Result<SimulatedTransaction>>>>
Simulate a batch of transactions without executing them.
Transactions are simulated sequentially on the server. Each transaction is independent — failure of one does not abort the rest.
Returns a Vec<Result<SimulatedTransaction>> in the same order as the
input. Each element is either the successfully simulated transaction or
the per-item error returned by the server.
§Errors
Returns Error::EmptyRequest if transactions is empty.
Returns a transport-level Error::Grpc if the entire RPC fails
(e.g. batch size exceeded).
Source§impl Client
impl Client
Sourcepub async fn get_checkpoint_latest(
&self,
read_mask: Option<&str>,
transactions_filter: Option<TransactionFilter>,
events_filter: Option<EventFilter>,
) -> Result<MetadataEnvelope<CheckpointResponse>>
pub async fn get_checkpoint_latest( &self, read_mask: Option<&str>, transactions_filter: Option<TransactionFilter>, events_filter: Option<EventFilter>, ) -> Result<MetadataEnvelope<CheckpointResponse>>
Get the latest checkpoint.
This retrieves the checkpoint including summary, contents, transactions, and events based on the provided read mask.
§Parameters
read_mask- Optional field mask specifying which fields to include. IfNone, usescrate::api::GET_CHECKPOINT_READ_MASKas default. See module-level documentation for all available fields.transactions_filter- Optional filter to apply to transactionsevents_filter- Optional filter to apply to events
§Example
let client = Client::connect("http://localhost:9000").await?;
let checkpoint = client.get_checkpoint_latest(None, None, None).await?;
println!("Received checkpoint {}", checkpoint.body().sequence_number,);Sourcepub async fn get_checkpoint_by_sequence_number(
&self,
sequence_number: CheckpointSequenceNumber,
read_mask: Option<&str>,
transactions_filter: Option<TransactionFilter>,
events_filter: Option<EventFilter>,
) -> Result<MetadataEnvelope<CheckpointResponse>>
pub async fn get_checkpoint_by_sequence_number( &self, sequence_number: CheckpointSequenceNumber, read_mask: Option<&str>, transactions_filter: Option<TransactionFilter>, events_filter: Option<EventFilter>, ) -> Result<MetadataEnvelope<CheckpointResponse>>
Get checkpoint by sequence number.
This retrieves the checkpoint including summary, contents, transactions, and events based on the provided read mask.
§Parameters
sequence_number- The checkpoint sequence number to fetchread_mask- Optional field mask specifying which fields to include. IfNone, usescrate::api::GET_CHECKPOINT_READ_MASKas default. See module-level documentation for all available fields.transactions_filter- Optional filter to apply to transactionsevents_filter- Optional filter to apply to events
§Example
let client = Client::connect("http://localhost:9000").await?;
let checkpoint = client
.get_checkpoint_by_sequence_number(100, None, None, None)
.await?;
println!("Received checkpoint {}", checkpoint.body().sequence_number,);Sourcepub async fn get_checkpoint_by_digest(
&self,
digest: Digest,
read_mask: Option<&str>,
transactions_filter: Option<TransactionFilter>,
events_filter: Option<EventFilter>,
) -> Result<MetadataEnvelope<CheckpointResponse>>
pub async fn get_checkpoint_by_digest( &self, digest: Digest, read_mask: Option<&str>, transactions_filter: Option<TransactionFilter>, events_filter: Option<EventFilter>, ) -> Result<MetadataEnvelope<CheckpointResponse>>
Get checkpoint by digest.
This retrieves the checkpoint including summary, contents, transactions, and events based on the provided read mask.
§Parameters
digest- The checkpoint digest to fetchread_mask- Optional field mask specifying which fields to include. IfNone, usescrate::api::GET_CHECKPOINT_READ_MASKas default. See module-level documentation for all available fields.transactions_filter- Optional filter to apply to transactionsevents_filter- Optional filter to apply to events
§Example
let client = Client::connect("http://localhost:9000").await?;
let digest: Digest = todo!();
let checkpoint = client
.get_checkpoint_by_digest(digest, None, None, None)
.await?;
println!("Received checkpoint {}", checkpoint.body().sequence_number,);Sourcepub async fn stream_checkpoints(
&self,
start_sequence_number: Option<CheckpointSequenceNumber>,
end_sequence_number: Option<CheckpointSequenceNumber>,
read_mask: Option<&str>,
transactions_filter: Option<TransactionFilter>,
events_filter: Option<EventFilter>,
) -> Result<MetadataEnvelope<Pin<Box<dyn Stream<Item = Result<CheckpointResponse>> + Send>>>>
pub async fn stream_checkpoints( &self, start_sequence_number: Option<CheckpointSequenceNumber>, end_sequence_number: Option<CheckpointSequenceNumber>, read_mask: Option<&str>, transactions_filter: Option<TransactionFilter>, events_filter: Option<EventFilter>, ) -> Result<MetadataEnvelope<Pin<Box<dyn Stream<Item = Result<CheckpointResponse>> + Send>>>>
Stream checkpoints across a range of checkpoints.
Returns a stream of CheckpointResponse objects, each representing
a complete checkpoint with its transactions and events. Every checkpoint
in the range is yielded, even if the filters produce no matching
transactions or events within it.
To skip non-matching checkpoints entirely, use
stream_checkpoints_filtered.
Note: The metadata in the returned MetadataEnvelope is captured
from the initial gRPC response headers when the stream is opened. It is
not updated as subsequent checkpoint data arrives.
§Parameters
start_sequence_number- Optional starting checkpoint. IfNone, starts from the latest checkpoint.end_sequence_number- Optional ending checkpoint. IfNone, streams indefinitely.read_mask- Optional field mask specifying which fields to include. IfNone, usescrate::api::GET_CHECKPOINT_READ_MASKas default. See module-level documentation for all available fields.transactions_filter- Optional filter to apply to transactionsevents_filter- Optional filter to apply to events
§Example
let client = Client::connect("http://localhost:9000").await?;
let mut stream = client
.stream_checkpoints(Some(0), Some(10), None, None, None)
.await?;
while let Some(checkpoint) = stream.body_mut().next().await {
let checkpoint = checkpoint?;
println!("Received checkpoint {}", checkpoint.sequence_number);
}Sourcepub async fn stream_checkpoints_filtered(
&self,
start_sequence_number: Option<CheckpointSequenceNumber>,
end_sequence_number: Option<CheckpointSequenceNumber>,
read_mask: Option<&str>,
transactions_filter: Option<TransactionFilter>,
events_filter: Option<EventFilter>,
progress_interval_ms: Option<u32>,
) -> Result<MetadataEnvelope<Pin<Box<dyn Stream<Item = Result<CheckpointStreamItem>> + Send>>>>
pub async fn stream_checkpoints_filtered( &self, start_sequence_number: Option<CheckpointSequenceNumber>, end_sequence_number: Option<CheckpointSequenceNumber>, read_mask: Option<&str>, transactions_filter: Option<TransactionFilter>, events_filter: Option<EventFilter>, progress_interval_ms: Option<u32>, ) -> Result<MetadataEnvelope<Pin<Box<dyn Stream<Item = Result<CheckpointStreamItem>> + Send>>>>
Stream checkpoints, skipping those with no matching data.
Unlike stream_checkpoints, this method
sets filter_checkpoints = true on the server, which means checkpoints
without any matching transactions or events are skipped entirely.
The returned stream yields CheckpointStreamItem, which is either a
CheckpointStreamItem::Checkpoint or a
CheckpointStreamItem::Progress. Progress messages are sent
periodically during scanning to indicate liveness and the current scan
position (default every 2 seconds, configurable via
progress_interval_ms).
For liveness detection, wrap stream.next() in
tokio::time::timeout() — if neither a Checkpoint nor a Progress
arrives within your chosen duration plus some buffer for connection
latency, the connection is likely dead.
At least one of transactions_filter or events_filter must be set.
§Parameters
start_sequence_number- Optional starting checkpoint. IfNone, starts from the latest checkpoint.end_sequence_number- Optional ending checkpoint. IfNone, streams indefinitely.read_mask- Optional field mask specifying which fields to include. IfNone, usescrate::api::GET_CHECKPOINT_READ_MASKas default. See module-level documentation for all available fields.transactions_filter- Optional filter to apply to transactionsevents_filter- Optional filter to apply to eventsprogress_interval_ms- Optional progress message interval in milliseconds. Defaults to 2000ms. Minimum 500ms.
§Example
let client = Client::connect("http://localhost:9000").await?;
// At least one filter is required
let tx_filter = grpc_filter::TransactionFilter::default();
let mut stream = client
.stream_checkpoints_filtered(Some(0), None, None, Some(tx_filter), None, None)
.await?;
while let Some(item) = stream.body_mut().next().await {
match item? {
CheckpointStreamItem::Checkpoint(cp) => {
println!("Matched checkpoint {}", cp.sequence_number);
}
CheckpointStreamItem::Progress {
latest_scanned_sequence_number,
} => {
println!("Scanned up to {latest_scanned_sequence_number}");
}
}
}Source§impl Client
impl Client
Sourcepub async fn get_epoch(
&self,
epoch: Option<u64>,
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<Epoch>>
pub async fn get_epoch( &self, epoch: Option<u64>, read_mask: Option<&str>, ) -> Result<MetadataEnvelope<Epoch>>
Get epoch information.
Returns the [Epoch] proto type with fields populated according to the
read_mask.
§Parameters
epoch- The epoch to query. IfNone, returns the current epoch.read_mask- Optional field mask specifying which fields to include. IfNone, usesGET_EPOCH_READ_MASK.
§Available Read Mask Fields
§Epoch Fields
epoch- the epoch numbercommittee- the validator committee for this epochbcs_system_state- the BCS-encoded system state at the beginning of the epoch for past epochs or the current system state for the current epoch, which can be used for historical state queries or to get the current state respectively
§Checkpoint Fields
first_checkpoint- the first checkpoint included in the epochlast_checkpoint- the last checkpoint included in the epoch, which may be unavailable for the current epoch if it has not ended yet
§Timing Fields
start- the timestamp of the first checkpoint included in the epochend- the timestamp of the last checkpoint included in the epoch, which may be unavailable for the current epoch if it has not ended yet
§Gas Fields
reference_gas_price- the reference gas price during the epoch, denominated in NANOS
§Protocol Configuration Fields
-
protocol_config- the protocol configuration during the epochprotocol_config.protocol_version- the protocol version during the epochprotocol_config.feature_flags- the individual protocol feature flags during the epoch (useprotocol_config.feature_flags.<key>to filter specific flags)protocol_config.attributes- the individual protocol attributes during the epoch (useprotocol_config.attributes.<key>to filter specific attributes)
Note: Other than for all other fields, wildcards don’t work for
protocol_config.feature_flagsandprotocol_config.attributessince they are maps (protocol_configis not enough). If you want all entries, you must specify the map directly, or single entries of it by name. (e.g.protocol_config.feature_flagsto get all entries, orprotocol_config.feature_flags.zklogin_authto get a single flag)
§Example
let client = Client::connect("http://localhost:9000").await?;
// Get current epoch with default fields
let epoch = client.get_epoch(None, None).await?;
println!("Epoch: {:?}", epoch.body().epoch);
// Get specific epoch with custom fields
let epoch = client
.get_epoch(Some(0), Some("epoch,reference_gas_price,first_checkpoint"))
.await?;
// Get all feature flags for the current epoch
let epoch = client
.get_epoch(None, Some("protocol_config.feature_flags"))
.await?
.into_inner();
let flags = epoch.protocol_config.unwrap().feature_flags.unwrap().flags;
// Get a single named feature flag
let epoch = client
.get_epoch(None, Some("protocol_config.feature_flags.zklogin_auth"))
.await?;
// Get all protocol attributes for the current epoch
let epoch = client
.get_epoch(None, Some("protocol_config.attributes"))
.await?
.into_inner();
let attributes = epoch
.protocol_config
.unwrap()
.attributes
.unwrap()
.attributes;
// Get a single named attribute
let epoch = client
.get_epoch(None, Some("protocol_config.attributes.max_tx_gas"))
.await?;Sourcepub async fn get_reference_gas_price(&self) -> Result<MetadataEnvelope<u64>>
pub async fn get_reference_gas_price(&self) -> Result<MetadataEnvelope<u64>>
Get the reference gas price for the current epoch.
§Example
let client = Client::connect("http://localhost:9000").await?;
let gas_price = client.get_reference_gas_price().await?.into_inner();
println!("Reference gas price: {gas_price} NANOS");Source§impl Client
impl Client
Sourcepub async fn get_health(
&self,
threshold_ms: Option<u64>,
) -> Result<MetadataEnvelope<GetHealthResponse>>
pub async fn get_health( &self, threshold_ms: Option<u64>, ) -> Result<MetadataEnvelope<GetHealthResponse>>
Check the health of the node.
Returns a MetadataEnvelope<[GetHealthResponse]> with the
latest checkpoint sequence number and an estimated validator latency
field (reserved for future use).
If the node’s latest checkpoint is stale (beyond the threshold), the
server returns an UNAVAILABLE error.
§Parameters
threshold_ms- Optional threshold in milliseconds. If provided, the node is considered healthy only if the latest executed checkpoint timestamp is within this many milliseconds of the current system time. IfNone, the server applies its default threshold (5 seconds).
Source§impl Client
impl Client
Sourcepub async fn get_objects(
&self,
refs: &[(ObjectId, Option<Version>)],
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<Vec<Object>>>
pub async fn get_objects( &self, refs: &[(ObjectId, Option<Version>)], read_mask: Option<&str>, ) -> Result<MetadataEnvelope<Vec<Object>>>
Get objects by their IDs and optional versions.
Returns proto Object types. Use obj.object() to convert to SDK
type, or use obj.object_reference() to get the object reference.
Results are returned in the same order as the input refs. If an object is not found, an error is returned.
§Errors
Returns Error::EmptyRequest if refs is empty.
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns. If None, uses GET_OBJECTS_READ_MASK.
§Reference Fields
reference- includes all reference fieldsreference.object_id- the ID of the object to fetchreference.version- the version of the object, which can be used to fetch a specific historical version or the latest version if not providedreference.digest- the digest of the object contents, which can be used for integrity verification
§Data Fields
bcs- the full BCS-encoded object
§Example
let client = Client::connect("http://localhost:9000").await?;
let object_id: ObjectId = "0x2".parse()?;
// Get proto objects
let objs = client.get_objects(&[(object_id, None)], None).await?;
for obj in objs.body() {
// Convert proto object to SDK type
let sdk_obj = obj.object()?;
println!("Got object ID: {:?}", sdk_obj.object_id());
let obj_ref = obj.object_reference()?;
println!("Object version: {:?}", obj_ref.version());
}Source§impl Client
impl Client
Sourcepub async fn get_service_info(
&self,
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<GetServiceInfoResponse>>
pub async fn get_service_info( &self, read_mask: Option<&str>, ) -> Result<MetadataEnvelope<GetServiceInfoResponse>>
Get service info from the node.
Returns the [GetServiceInfoResponse] proto type with fields populated
according to the read_mask.
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns. If None, uses GET_SERVICE_INFO_READ_MASK.
§Network Fields
chain_id- the ID of the chain, which can be used to identify the networkchain- the chain identifier, which can be used to identify the network
§Current State Fields
epoch- the current epochexecuted_checkpoint_height- the height of the last executed checkpointexecuted_checkpoint_timestamp- the timestamp of the last executed checkpoint
§Availability Fields
lowest_available_checkpoint- lowest available checkpoint for which transaction and checkpoint data can be requestedlowest_available_checkpoint_objects- lowest available checkpoint for which object data can be requested
§Server Fields
server- the server version
§Example
let client = Client::connect("http://localhost:9000").await?;
// Get service info with default fields
let info = client.get_service_info(None).await?;
println!("Chain ID: {:?}", info.body().chain_id);
println!("Epoch: {:?}", info.body().epoch);
// Get service info with all fields
let info = client
.get_service_info(Some(
"chain_id,chain,epoch,executed_checkpoint_height,\
executed_checkpoint_timestamp,lowest_available_checkpoint,\
lowest_available_checkpoint_objects,server",
))
.await?;Source§impl Client
impl Client
Sourcepub async fn get_transactions(
&self,
digests: &[Digest],
read_mask: Option<&str>,
) -> Result<MetadataEnvelope<Vec<ExecutedTransaction>>>
pub async fn get_transactions( &self, digests: &[Digest], read_mask: Option<&str>, ) -> Result<MetadataEnvelope<Vec<ExecutedTransaction>>>
Get transactions by their digests.
Returns proto ExecutedTransaction for each transaction. Use the lazy
conversion methods to extract data:
tx.digest()- Get transaction digesttx.transaction()- Deserialize transactiontx.signatures()- Deserialize signaturestx.effects()- Deserialize effectstx.events()- Deserialize events (if available)tx.checkpoint_sequence_number()- Get checkpoint numbertx.timestamp_ms()- Get timestamp
Results are returned in the same order as the input digests. If a transaction is not found, an error is returned.
§Errors
Returns Error::EmptyRequest if digests is empty.
§Available Read Mask Fields
The optional read_mask parameter controls which fields the server
returns. If None, uses GET_TRANSACTIONS_READ_MASK.
§Transaction Fields
transaction- includes all transaction fieldstransaction.digest- the transaction digesttransaction.bcs- the full BCS-encoded transaction
signatures- includes all signature fieldssignatures.bcs- the full BCS-encoded signature
effects- includes all effects fieldseffects.digest- the effects digesteffects.bcs- the full BCS-encoded effects
§Event Fields
events- includes all event fieldsevents.digest- the events digestevents.events- includes all event fieldsevents.events.bcs- the full BCS-encoded eventevents.events.package_id- the ID of the package that emitted the eventevents.events.module- the module that emitted the eventevents.events.sender- the sender that triggered the eventevents.events.event_type- the type of the eventevents.events.bcs_contents- the full BCS-encoded contents of the eventevents.events.json_contents- the JSON-encoded contents of the event
§Timing Fields
checkpoint- the checkpoint that included the transactiontimestamp- the timestamp of the checkpoint that included the transaction
§Object Fields
input_objects- includes all input object fieldsinput_objects.reference- includes all reference fieldsinput_objects.reference.object_id- the ID of the input objectinput_objects.reference.version- the version of the input object, which can be used to fetch a specific historical version or the latest version if not providedinput_objects.reference.digest- the digest of the input object contents, which can be used for integrity verification
input_objects.bcs- the full BCS-encoded object
output_objects- includes all output object fieldsoutput_objects.reference- includes all reference fieldsoutput_objects.reference.object_id- the ID of the output objectoutput_objects.reference.version- the version of the output object, which can be used to fetch a specific historical version or the latest version if not providedoutput_objects.reference.digest- the digest of the output object contents, which can be used for integrity verification
output_objects.bcs- the full BCS-encoded object
§Example
let client = Client::connect("http://localhost:9000").await?;
let digest: Digest = todo!();
// Get transactions - returns proto types
let txs = client.get_transactions(&[digest], None).await?;
for tx in txs.body() {
// Lazy conversion - only deserialize what you need
let effects = tx.effects()?.effects()?;
println!("Status: {:?}", effects.status());
// Access checkpoint number
let checkpoint = tx.checkpoint_sequence_number()?;
println!("Checkpoint: {}", checkpoint);
}Source§impl Client
impl Client
Sourcepub fn list_package_versions(
&self,
package_id: ObjectId,
page_size: Option<u32>,
page_token: Option<Bytes>,
) -> ListPackageVersionsQuery
pub fn list_package_versions( &self, package_id: ObjectId, page_size: Option<u32>, page_token: Option<Bytes>, ) -> ListPackageVersionsQuery
List all versions of a Move package.
Returns a query builder. Await it directly for a single page
(with access to next_page_token), or call .collect(limit) to
auto-paginate through all results.
§Parameters
package_id- The object ID of any version of the package.page_size- Optional maximum number of versions per page.page_token- Optional continuation token from a previous page.
§Examples
Single page:
let client = Client::connect("http://localhost:9000").await?;
let package_id: ObjectId = "0x2".parse()?;
let page = client.list_package_versions(package_id, None, None).await?;
for version in &page.body().items {
println!("Package version: {:?}", version);
}Auto-paginate:
let client = Client::connect("http://localhost:9000").await?;
let package_id: ObjectId = "0x2".parse()?;
let all = client
.list_package_versions(package_id, Some(50), None)
.collect(None)
.await?;
for version in all.body() {
println!("Package version: {:?}", version);
}Source§impl Client
impl Client
Sourcepub async fn get_coin_info(
&self,
coin_type: StructTag,
) -> Result<MetadataEnvelope<GetCoinInfoResponse>>
pub async fn get_coin_info( &self, coin_type: StructTag, ) -> Result<MetadataEnvelope<GetCoinInfoResponse>>
Get information about a coin type.
Returns the [GetCoinInfoResponse] proto type with metadata, treasury,
and regulation information for the specified coin type.
§Parameters
coin_type- The coin type as a [StructTag].
§Example
let client = Client::connect("http://localhost:9000").await?;
let coin_type: StructTag = "0x2::iota::IOTA".parse()?;
let response = client.get_coin_info(coin_type).await?;
let info = response.body();
println!("Coin info: {:?}", info);Source§impl Client
impl Client
Sourcepub fn list_dynamic_fields(
&self,
parent: ObjectId,
page_size: Option<u32>,
page_token: Option<Bytes>,
read_mask: Option<&str>,
) -> ListDynamicFieldsQuery
pub fn list_dynamic_fields( &self, parent: ObjectId, page_size: Option<u32>, page_token: Option<Bytes>, read_mask: Option<&str>, ) -> ListDynamicFieldsQuery
List dynamic fields owned by a parent object.
Returns a query builder. Await it directly for a single page
(with access to next_page_token), or call .collect(limit) to
auto-paginate through all results.
§Parameters
parent- The object ID of the parent object.page_size- Optional maximum number of fields per page.page_token- Optional continuation token from a previous page.read_mask- Optional field mask. IfNone, usesLIST_DYNAMIC_FIELDS_READ_MASK.
§Examples
Single page:
let client = Client::connect("http://localhost:9000").await?;
let parent: ObjectId = "0x2".parse()?;
let page = client.list_dynamic_fields(parent, None, None, None).await?;
for field in &page.body().items {
println!("Dynamic field: {:?}", field);
}Auto-paginate:
let client = Client::connect("http://localhost:9000").await?;
let parent: ObjectId = "0x2".parse()?;
let all = client
.list_dynamic_fields(parent, Some(50), None, None)
.collect(None)
.await?;
for field in all.body() {
println!("Dynamic field: {:?}", field);
}Source§impl Client
impl Client
Sourcepub fn list_owned_objects(
&self,
owner: Address,
object_type: Option<StructTag>,
page_size: Option<u32>,
page_token: Option<Bytes>,
read_mask: Option<&str>,
) -> ListOwnedObjectsQuery
pub fn list_owned_objects( &self, owner: Address, object_type: Option<StructTag>, page_size: Option<u32>, page_token: Option<Bytes>, read_mask: Option<&str>, ) -> ListOwnedObjectsQuery
List objects owned by an address.
Returns a query builder. Await it directly for a single page
(with access to next_page_token), or call .collect(limit) to
auto-paginate through all results.
§Parameters
owner- The address that owns the objects.object_type- Optional type filter as a [StructTag].page_size- Optional maximum number of objects per page.page_token- Optional continuation token from a previous page.read_mask- Optional field mask. IfNone, usesLIST_OWNED_OBJECTS_READ_MASK.
§Examples
Single page:
let client = Client::connect("http://localhost:9000").await?;
let owner: Address = "0x1".parse()?;
let page = client
.list_owned_objects(owner, None, None, None, None)
.await?;
for obj in &page.body().items {
println!("Owned object: {:?}", obj);
}
if let Some(token) = &page.body().next_page_token {
// Fetch the next page using the token
let next = client
.list_owned_objects(owner, None, None, Some(token.clone()), None)
.await?;
}Auto-paginate:
let client = Client::connect("http://localhost:9000").await?;
let owner: Address = "0x1".parse()?;
let all = client
.list_owned_objects(owner, None, Some(50), None, None)
.collect(Some(500))
.await?;
for obj in all.body() {
println!("Owned object: {:?}", obj);
}Source§impl Client
impl Client
Sourcepub async fn connect<T>(uri: T) -> Result<Self>
pub async fn connect<T>(uri: T) -> Result<Self>
Connect to a gRPC server and create a new Client instance.
pub fn uri(&self) -> &Uri
Sourcepub fn channel(&self) -> &Channel
pub fn channel(&self) -> &Channel
Get a reference to the underlying channel.
This can be useful for creating additional service clients that aren’t yet integrated into Client.
pub fn headers(&self) -> &HeadersInterceptor
pub fn max_decoding_message_size(&self) -> Option<usize>
pub fn with_headers(self, headers: HeadersInterceptor) -> Self
pub fn with_max_decoding_message_size(self, limit: usize) -> Self
Sourcepub fn ledger_service_client(&self) -> LedgerServiceClient<InterceptedChannel>
pub fn ledger_service_client(&self) -> LedgerServiceClient<InterceptedChannel>
Get a ledger service client.
Sourcepub fn execution_service_client(
&self,
) -> TransactionExecutionServiceClient<InterceptedChannel>
pub fn execution_service_client( &self, ) -> TransactionExecutionServiceClient<InterceptedChannel>
Get a transaction execution service client.
Sourcepub fn state_service_client(&self) -> StateServiceClient<InterceptedChannel>
pub fn state_service_client(&self) -> StateServiceClient<InterceptedChannel>
Get a state service client.
Sourcepub fn move_package_service_client(
&self,
) -> MovePackageServiceClient<InterceptedChannel>
pub fn move_package_service_client( &self, ) -> MovePackageServiceClient<InterceptedChannel>
Get a move package service client.
Trait Implementations§
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§
§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 moreSource§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> 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>
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§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> 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.