iota_grpc_client/api/state/coin_info.rs
1// Copyright (c) 2026 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! High-level API for coin info queries.
5
6use iota_grpc_types::v1::state_service::{GetCoinInfoRequest, GetCoinInfoResponse};
7use iota_sdk_types::StructTag;
8
9use crate::{
10 Client,
11 api::{MetadataEnvelope, Result},
12};
13
14impl Client {
15 /// Get information about a coin type.
16 ///
17 /// Returns the [`GetCoinInfoResponse`] proto type with metadata, treasury,
18 /// and regulation information for the specified coin type.
19 ///
20 /// # Parameters
21 ///
22 /// - `coin_type` - The coin type as a [`StructTag`].
23 ///
24 /// # Example
25 ///
26 /// ```no_run
27 /// # use iota_grpc_client::Client;
28 /// # use iota_sdk_types::StructTag;
29 /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
30 /// let client = Client::connect("http://localhost:9000").await?;
31 /// let coin_type: StructTag = "0x2::iota::IOTA".parse()?;
32 ///
33 /// let response = client.get_coin_info(coin_type).await?;
34 /// let info = response.body();
35 /// println!("Coin info: {:?}", info);
36 /// # Ok(())
37 /// # }
38 /// ```
39 pub async fn get_coin_info(
40 &self,
41 coin_type: StructTag,
42 ) -> Result<MetadataEnvelope<GetCoinInfoResponse>> {
43 let request = GetCoinInfoRequest::default().with_coin_type(coin_type.to_string());
44
45 let mut client = self.state_service_client();
46 let response = client.get_coin_info(request).await?;
47
48 Ok(MetadataEnvelope::from(response))
49 }
50}