Expand description
Rust SDK for interacting with Mina Protocol nodes via GraphQL.
Mina is a lightweight blockchain (about 22 KB) powered by recursive zero-knowledge proofs. This crate provides a typed, async client for the Mina daemon’s GraphQL API — covering node status, account queries, block exploration, payments, stake delegation, and SNARK worker configuration.
§Features
- Async/await — built on tokio and reqwest
- Typed responses — every query returns a strongly-typed Rust struct
- Automatic retry — configurable retry count and delay for transient failures
- Currency safety —
Currencytype with nanomina precision and overflow-safe arithmetic - Extensible —
MinaClient::execute_queryruns arbitrary GraphQL through the same retry-aware client;queriesmodule exposes all built-in query strings - Tracing — all requests are instrumented with
tracing
§Quick Start
use mina_sdk::{MinaClient, Payment, Currency};
let client = MinaClient::new("http://127.0.0.1:3085/graphql");
// Query node status
let status = client.get_sync_status().await?;
println!("Node is {status}");
// Send a payment
let result = client.send_payment(
Payment::sender("B62q..sender..")
.to("B62q..receiver..")
.amount(Currency::from_mina("1.5")?)
.fee(Currency::from_mina("0.01")?)
.memo("hello"),
).await?;
println!("Payment hash: {}", result.hash);§Custom Configuration
use mina_sdk::{ClientConfig, MinaClient};
use std::time::Duration;
let client = MinaClient::with_config(ClientConfig {
graphql_uri: "http://my-node:3085/graphql".to_string(),
retries: 5,
retry_delay: Duration::from_secs(10),
timeout: Duration::from_secs(60),
});§Currency
The Currency type represents MINA amounts stored internally as nanomina (1 MINA = 10^9
nanomina). It provides safe conversions and arithmetic:
use mina_sdk::Currency;
let amount = Currency::from_mina("1.5").unwrap();
assert_eq!(amount.nanomina(), 1_500_000_000);
assert_eq!(amount.mina(), "1.500000000");
let fee = Currency::from_mina("0.01").unwrap();
let total = amount + fee;
assert_eq!(total, Currency::from_mina("1.51").unwrap());
// Overflow-safe variants
assert!(fee.checked_add(amount).is_some());
assert!(amount.checked_sub(fee).is_ok());§Error Handling
All fallible operations return Result<T>, which uses Error. Match on
variants for fine-grained control:
use mina_sdk::{MinaClient, Error};
let client = MinaClient::new("http://127.0.0.1:3085/graphql");
match client.get_account("B62q...", None).await {
Ok(account) => println!("Balance: {}", account.balance.total),
Err(Error::AccountNotFound(key)) => eprintln!("No such account: {key}"),
Err(Error::Connection { attempts, .. }) => eprintln!("Node unreachable after {attempts} tries"),
Err(e) => eprintln!("Error: {e}"),
}§API Overview
| Method | Description |
|---|---|
MinaClient::get_sync_status | Node sync state (Synced, Bootstrap, etc.) |
MinaClient::get_daemon_status | Comprehensive daemon info |
MinaClient::get_network_id | Network identifier string |
MinaClient::get_account | Account balance, nonce, delegate |
MinaClient::get_best_chain | Recent blocks from the best chain |
MinaClient::get_peers | Connected peer list |
MinaClient::get_pooled_user_commands | Pending transaction pool |
MinaClient::send_payment | Send a MINA payment |
MinaClient::send_delegation | Delegate stake to a validator |
MinaClient::set_snark_worker | Enable/disable SNARK worker |
MinaClient::set_snark_work_fee | Set SNARK work fee |
MinaClient::execute_query | Run arbitrary GraphQL |
§Examples
See the examples/
directory for runnable programs:
- basic_usage — connect, query status, browse blocks and accounts
- send_payment — submit a payment transaction
- stake_delegation — delegate stake to a validator
- currency_operations — create, convert, and do arithmetic on amounts (no node needed)
- custom_query — run arbitrary GraphQL through
execute_query - error_handling — match on specific error variants
- node_monitoring — health checks, peer listing, block browsing
Re-exports§
Modules§
Structs§
- Account
Balance - Account balance with total, liquid, and locked amounts.
- Account
Data - Account data returned by the daemon.
- Block
Info - Block info from the best chain.
- Client
Config - Configuration for the Mina daemon client.
- Currency
- Represents a Mina currency amount stored internally as nanomina (atomic units).
- Daemon
Status - Comprehensive daemon status.
- Delegation
- Parameters for sending a stake delegation transaction.
- Mina
Client - Client for interacting with a Mina daemon via its GraphQL API.
- Payment
- Parameters for sending a payment transaction.
- Peer
Info - Information about a connected peer.
- Pooled
User Command - A pooled user command from the transaction pool.
- Query
Builder - Builder returned by
MinaClient::queryfor running arbitrary GraphQL. - Send
Delegation Result - Result of a send_delegation mutation.
- Send
Payment Result - Result of a send_payment mutation.
Enums§
- Sync
Status - Sync status of a Mina daemon node.