Skip to main content

Crate mina_sdk

Crate mina_sdk 

Source
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 safetyCurrency type with nanomina precision and overflow-safe arithmetic
  • ExtensibleMinaClient::execute_query runs arbitrary GraphQL through the same retry-aware client; queries module 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

MethodDescription
MinaClient::get_sync_statusNode sync state (Synced, Bootstrap, etc.)
MinaClient::get_daemon_statusComprehensive daemon info
MinaClient::get_network_idNetwork identifier string
MinaClient::get_accountAccount balance, nonce, delegate
MinaClient::get_best_chainRecent blocks from the best chain
MinaClient::get_peersConnected peer list
MinaClient::get_pooled_user_commandsPending transaction pool
MinaClient::send_paymentSend a MINA payment
MinaClient::send_delegationDelegate stake to a validator
MinaClient::set_snark_workerEnable/disable SNARK worker
MinaClient::set_snark_work_feeSet SNARK work fee
MinaClient::execute_queryRun 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§

pub use error::Error;
pub use error::Result;

Modules§

error
queries
GraphQL query and mutation strings for the Mina daemon API.

Structs§

AccountBalance
Account balance with total, liquid, and locked amounts.
AccountData
Account data returned by the daemon.
BlockInfo
Block info from the best chain.
ClientConfig
Configuration for the Mina daemon client.
Currency
Represents a Mina currency amount stored internally as nanomina (atomic units).
DaemonStatus
Comprehensive daemon status.
Delegation
Parameters for sending a stake delegation transaction.
MinaClient
Client for interacting with a Mina daemon via its GraphQL API.
Payment
Parameters for sending a payment transaction.
PeerInfo
Information about a connected peer.
PooledUserCommand
A pooled user command from the transaction pool.
QueryBuilder
Builder returned by MinaClient::query for running arbitrary GraphQL.
SendDelegationResult
Result of a send_delegation mutation.
SendPaymentResult
Result of a send_payment mutation.

Enums§

SyncStatus
Sync status of a Mina daemon node.