No description
Find a file
despiegk 57925bf520
Some checks failed
Build Linux / build-linux (linux-amd64, false, x86_64-unknown-linux-gnu) (push) Successful in 1m21s
Build macOS / build-macos (push) Has been cancelled
Add oschema specs for grid explorer and tfchain services
2026-01-05 18:46:24 +01:00
.forgejo/workflows Fix forgejo workflows for tfchain binary 2026-01-05 06:46:23 +01:00
examples Move Rhai examples to rhaiexamples/, fix build scripts, add forgejo workflow 2026-01-05 06:40:35 +01:00
rhaiexamples Move Rhai examples to rhaiexamples/, fix build scripts, add forgejo workflow 2026-01-05 06:40:35 +01:00
scripts Update install script for tfchain, add installation instructions to README 2026-01-05 06:53:54 +01:00
specs Add oschema specs for grid explorer and tfchain services 2026-01-05 18:46:24 +01:00
src Add Rhai scripting support, transfer functionality, and Explorer API bindings 2026-01-05 05:47:06 +01:00
.gitignore Initial release: TFChain client and Explorer API 2025-12-31 14:58:33 +01:00
build.rs Initial release: TFChain client and Explorer API 2025-12-31 14:58:33 +01:00
build.sh Add Rhai scripting support, transfer functionality, and Explorer API bindings 2026-01-05 05:47:06 +01:00
build_package.sh Update install script for tfchain, add installation instructions to README 2026-01-05 06:53:54 +01:00
build_publish.sh Move Rhai examples to rhaiexamples/, fix build scripts, add forgejo workflow 2026-01-05 06:40:35 +01:00
Cargo.lock Add Rhai scripting support, transfer functionality, and Explorer API bindings 2026-01-05 05:47:06 +01:00
Cargo.toml Move Rhai examples to rhaiexamples/, fix build scripts, add forgejo workflow 2026-01-05 06:40:35 +01:00
README.md Simplify README install instructions 2026-01-05 06:55:12 +01:00

Mycelium TFChain Client

A Rust client library for interacting with the ThreeFold Grid infrastructure.

Install Binary

curl -sSL https://forge.ourworld.tf/geomind_code/tfchain_client/raw/branch/main/scripts/install.sh | bash

Usage

# Run a Rhai script
tfchain script.rhai

# Show help
tfchain --help

or just call rhai script it has shebang on top

Modules

This library provides two main modules:

Module Description
tfchain TFChain blockchain client with dynamic metadata support
explorer TFGrid Explorer API client with optional Redis caching

to play

make sure your key is in env:

export TFCHAIN_KEY=...

Installation

Add to your Cargo.toml:

[dependencies]
mycelium_tfchain_client = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

Quick Start

TFChain Client

Query the blockchain directly for twins, farms, nodes, and balances:

use mycelium_tfchain_client::{Client, KeyPair, KeyType};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let keypair = KeyPair::from_phrase(KeyType::Sr25519, "your mnemonic here", None)?;
    let client = Client::new("wss://tfchain.grid.tf:443").await?;

    if let Some(info) = client.get_balance(&keypair.account_id()).await? {
        println!("Balance: {} TFT", info.free as f64 / 10_000_000.0);
    }

    Ok(())
}

Explorer Client

Query the Grid Proxy API for nodes, farms, and grid statistics:

use mycelium_tfchain_client::explorer::GridExplorerBuilder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let explorer = GridExplorerBuilder::new().mainnet().build()?;

    let stats = explorer.get_stats().await?;
    println!("Grid has {} nodes", stats.nodes);

    // Find nodes for a VM with 4 cores, 8GB RAM, 100GB disk
    let nodes = explorer.find_nodes_for_vm(4, 8, 100, Some(5)).await?;
    for node in nodes {
        println!("Node {} - ${:.4}/hr", node.id, node.price_usd);
    }

    Ok(())
}

Examples

Run the examples:

# TFChain client example (requires TFCHAIN_SECRET env var)
cargo run --example mainnet

# Explorer client examples
cargo run --example tfgrid3-explorer-client
cargo run --example tfgrid3-explorer-client-highlevel

Network Endpoints

TFChain (WebSocket)

Network URL
Mainnet wss://tfchain.grid.tf:443
Testnet wss://tfchain.test.grid.tf:443
Devnet wss://tfchain.dev.grid.tf:443

Grid Proxy (HTTP)

Network URL
Mainnet https://gridproxy.grid.tf
Testnet https://gridproxy.test.grid.tf
Devnet https://gridproxy.dev.grid.tf

License

Apache-2.0