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 crates (circles-types, circles-rpc, circles-pathfinder, circles-profiles, tokio, reqwest).
  2. Initialize an RpcClient with your endpoint.
  3. Run a query (profiles/trust/balances) and print results.
  4. Run prepare_flow_for_contract to get transfer params (hold for runner later).

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 these read-only endpoints from a Rust backend (REST/gRPC/etc.). Writes will be added once the runner is ready.