rootchain-rs 1.0.1

The primary Rust SDK for the RootChain ecosystem, providing RPC clients, wallet management, and transaction construction.
Documentation

rootchain-rs

Crates.io License: MIT

The primary Rust SDK for interacting with the RootChain network.

rootchain-rs provides a high-level async client for building Rust applications that communicate with RootChain nodes: wallets, bots, indexers, relayers, and tooling.


What's Inside

Module Description
client JSON-RPC async client for communicating with a RootChain node (getBalance, sendTransaction, getBlock, etc.)
wallet Wallet type for key management, BIP-39 mnemonic support, AES-256-GCM encrypted storage, and transaction signing
contract Typed Contract wrapper for encoding/decoding ABI calls to RootChain WASM contracts
error Unified SdkError type covering RPC, signing, and serialization errors

Installation

[dependencies]
rootchain-rs = "1.0.1"
tokio = { version = "1", features = ["full"] }

Usage

Connecting to a Node

use rootchain_rs::client::RootchainClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = RootchainClient::new("http://localhost:8545");

    let balance = client.get_balance("0xabc...").await?;
    println!("Balance: {} µROOT", balance.balance);

    let block = client.get_block(1000).await?;
    println!("Block hash: {}", block.header.merkle_root);

    Ok(())
}

Wallet Management

use rootchain_rs::wallet::Wallet;

// Create a new wallet from a BIP-39 mnemonic
let wallet = Wallet::from_mnemonic("word1 word2 ... word24")?;
let address = wallet.address();

// Sign and send a transfer
let client = RootchainClient::new("http://localhost:8545");
let tx_hash = wallet.send_transfer(&client, &recipient, 1_000_000u128, 100u128).await?;

Contract Interaction

use rootchain_rs::contract::Contract;

let contract = Contract::at("0xcontract_address...");

// Encode a method call (method ID + bincode payload)
let payload = contract.encode_call(1u32, &my_args)?;

// Submit via wallet
let tx_hash = wallet.call_contract(&client, &contract, payload).await?;

High-Precision Balances

All balance fields use u128 internally to support the full 18-decimal precision of ROOT tokens (1 ROOT = 1,000,000 µROOT). Balances are safely serialized as decimal strings over JSON.

let balance: u128 = 1_000_000_000_000u128; // 1,000,000 ROOT

License

MIT — See LICENSE for details.