Skip to content

Setting up Circles SDK (Rust Adaptation)

The TS docs show a React/JS setup. For Rust, favor backend/CLI or service workflows:

  1. Add circles-sdk and Tokio.
  2. Initialize Sdk with config::gnosis_mainnet().
  3. Run reads with Sdk::new(config, None).
  4. Attach EoaContractRunner or SafeContractRunner when you need execution.

Minimal CLI example:

use circles_rpc::{QueryMethods, RpcClient};
use circles_types::{OrderBy, QueryParams};
use reqwest::Url;
 
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = RpcClient::http(Url::parse("https://rpc.aboutcircles.com/")?);
    let queries = QueryMethods::new(client);
 
    let rows: Vec<serde_json::Value> = queries
        .circles_query(QueryParams {
            namespace: "circles".into(),
            table: "profiles".into(),
            columns: vec!["avatar".into(), "name".into()],
            filter: vec![],
            order: vec![OrderBy::asc("avatar".into())],
            limit: Some(5),
        })
        .await?;
 
    println!("{}", serde_json::to_string_pretty(&rows)?);
    Ok(())
}

Add pathfinding:

use circles_pathfinder::{prepare_flow_for_contract, FindPathParams};
use alloy_primitives::U256;
 
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let params = FindPathParams {
        from: "0x1234567890123456789012345678901234567890".parse()?,
        to: "0x0987654321098765432109876543210987654321".parse()?,
        target_flow: U256::from(1_000_000_000_000_000_000u64),
        use_wrapped_balances: Some(true),
        from_tokens: None,
        to_tokens: None,
        exclude_from_tokens: None,
        exclude_to_tokens: None,
        simulated_balances: None,
        max_transfers: Some(6),
    };
    let flow = prepare_flow_for_contract("https://rpc.aboutcircles.com/", params).await?;
    println!("vertices: {}, edges: {}", flow.flow_vertices.len(), flow.flow_edges.len());
    Ok(())
}

UI integrations: expose the Rust SDK from a backend, CLI, or service layer. For browser wallets specifically, keep the current boundary in mind: core Rust stops at native runners plus SafeExecutionBuilder.