pub struct MinaClient { /* private fields */ }Expand description
Client for interacting with a Mina daemon via its GraphQL API.
§Examples
use mina_sdk::MinaClient;
let client = MinaClient::new("http://127.0.0.1:3085/graphql");
let status = client.get_sync_status().await?;
println!("Sync status: {status}");Implementations§
Source§impl MinaClient
impl MinaClient
Sourcepub fn from_host_and_port(host: &str, port: u16) -> Self
pub fn from_host_and_port(host: &str, port: u16) -> Self
Create a client targeting http://{host}:{port}/graphql.
use mina_sdk::MinaClient;
let client = MinaClient::from_host_and_port("127.0.0.1", 3085);Sourcepub fn with_config(config: ClientConfig) -> Self
pub fn with_config(config: ClientConfig) -> Self
Create a new client with custom configuration.
§Panics
Panics if retries is 0, retry_delay is negative, or timeout is zero.
Sourcepub fn query<'a>(&'a self, query: &'a str) -> QueryBuilder<'a>
pub fn query<'a>(&'a self, query: &'a str) -> QueryBuilder<'a>
Start building a custom GraphQL query with named options.
Preferred entry point for arbitrary queries — variables and name are
opt-in via the builder, so callers don’t have to spell out None:
use mina_sdk::MinaClient;
use serde_json::json;
let client = MinaClient::default();
let data = client.query("query { version }").send().await?;
println!("{}", data["version"]);
let data = client
.query("query ($len: Int) { bestChain(maxLength: $len) { stateHash } }")
.variables(json!({ "len": 3 }))
.name("best_chain_custom")
.send()
.await?;Sourcepub async fn execute_query(
&self,
query: &str,
variables: Option<Value>,
query_name: &str,
) -> Result<Value>
pub async fn execute_query( &self, query: &str, variables: Option<Value>, query_name: &str, ) -> Result<Value>
Execute a raw GraphQL query and return the data field of the response.
This low-level method stays public so downstream crates
(e.g. mina-perf-testing) can reuse the client’s retry logic. For new
code prefer MinaClient::query, which exposes a builder.
Sourcepub fn graphql_uri(&self) -> &str
pub fn graphql_uri(&self) -> &str
Get the GraphQL endpoint URI.
Sourcepub async fn get_sync_status(&self) -> Result<SyncStatus>
pub async fn get_sync_status(&self) -> Result<SyncStatus>
Get the node’s sync status.
Sourcepub async fn get_daemon_status(&self) -> Result<DaemonStatus>
pub async fn get_daemon_status(&self) -> Result<DaemonStatus>
Get comprehensive daemon status.
Sourcepub async fn get_network_id(&self) -> Result<String>
pub async fn get_network_id(&self) -> Result<String>
Get the network identifier.
Sourcepub async fn get_account(
&self,
public_key: &str,
token_id: Option<&str>,
) -> Result<AccountData>
pub async fn get_account( &self, public_key: &str, token_id: Option<&str>, ) -> Result<AccountData>
Get account data for a public key.
Sourcepub async fn get_best_chain(
&self,
max_length: Option<u32>,
) -> Result<Vec<BlockInfo>>
pub async fn get_best_chain( &self, max_length: Option<u32>, ) -> Result<Vec<BlockInfo>>
Get blocks from the best chain.
Sourcepub async fn get_pooled_user_commands(
&self,
public_key: Option<&str>,
) -> Result<Vec<PooledUserCommand>>
pub async fn get_pooled_user_commands( &self, public_key: Option<&str>, ) -> Result<Vec<PooledUserCommand>>
Get pending user commands from the transaction pool.
Sourcepub async fn send_payment(&self, payment: Payment) -> Result<SendPaymentResult>
pub async fn send_payment(&self, payment: Payment) -> Result<SendPaymentResult>
Send a payment transaction.
Requires the sender’s account to be unlocked on the node.
§Examples
use mina_sdk::{Payment, Currency};
let result = client.send_payment(
Payment::sender("B62qsender...")
.to("B62qreceiver...")
.amount(Currency::from_mina("1.5")?)
.fee(Currency::from_mina("0.01")?)
.memo("coffee"),
).await?;
println!("Tx hash: {}", result.hash);Sourcepub async fn send_delegation(
&self,
delegation: Delegation,
) -> Result<SendDelegationResult>
pub async fn send_delegation( &self, delegation: Delegation, ) -> Result<SendDelegationResult>
Send a stake delegation transaction.
Requires the sender’s account to be unlocked on the node.
§Examples
use mina_sdk::{Delegation, Currency};
let result = client.send_delegation(
Delegation::sender("B62qsender...")
.to("B62qdelegate...")
.fee(Currency::from_mina("0.01")?),
).await?;Sourcepub async fn set_snark_worker(
&self,
public_key: Option<&str>,
) -> Result<Option<String>>
pub async fn set_snark_worker( &self, public_key: Option<&str>, ) -> Result<Option<String>>
Set or unset the SNARK worker key.
Pass None to disable the SNARK worker.
Sourcepub async fn set_snark_work_fee(&self, fee: Currency) -> Result<String>
pub async fn set_snark_work_fee(&self, fee: Currency) -> Result<String>
Set the fee for SNARK work.