No description
  • Rust 78.7%
  • Shell 20.1%
  • Makefile 1.2%
Find a file
despiegk 9633b273b1
All checks were successful
Build and Test / build (push) Successful in 3m43s
chore: canonicalize LICENSE
2026-05-27 19:58:48 +02:00
.forgejo/workflows Add build_lib standardization: buildenv.sh, scripts/build_lib.sh, Makefile, CI workflows 2026-02-07 09:48:03 +04: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 Add build_lib standardization: buildenv.sh, scripts/build_lib.sh, Makefile, CI workflows 2026-02-07 09:48:03 +04:00
specs_for_ui specs 2026-01-20 06:49:18 +01:00
src feat: add get/set methods for node v3 opt-out metadata and Rhai bindings. 2026-02-26 15:16:11 +02:00
.gitignore chore: remove .DS_Store and add it to .gitignore 2026-02-22 16:50:58 +02: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
buildenv.sh Add build_lib standardization: buildenv.sh, scripts/build_lib.sh, Makefile, CI workflows 2026-02-07 09:48:03 +04: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
LICENSE chore: canonicalize LICENSE 2026-05-27 19:58:48 +02:00
Makefile Fix Makefile cargo and shell compatibility 2026-02-07 20:54:12 +04:00
README.md docs: restructure README with standard sections 2026-05-27 16:26:14 +02:00

tfchain_client

What this is

A Rust client library for interacting with the Ledger Chain blockchain infrastructure and the ThreeFold Grid. It provides modules for direct blockchain queries (twins, farms, nodes, balances) and Grid Proxy API access with optional Redis caching. A tfchain CLI binary is also provided for running Rhai scripts against the Ledger Chain.

What this repository contains

  • src/tfchain/ — Ledger Chain blockchain client with dynamic metadata support
  • src/explorer/ — Grid Explorer API client with optional Redis caching
  • Examples for mainnet and explorer usage
  • scripts/install.sh — Quick install script for the tfchain CLI binary

Role in the stack

The Ledger Chain client provides programmatic access to the blockchain layer that underpins the ThreeFold Grid. It is used by other components to query twins, farms, nodes, balances, and to interact with the Grid Proxy API for node discovery and pricing.

Relation to ThreeFold

This technology is used within the ThreeFold ecosystem and was first deployed on the ThreeFold Grid. The component itself is designed as reusable infrastructure technology and should be understood by its technical function first, independent of any specific deployment.

Ownership

This repository is owned and maintained by TF-Tech NV, a Belgian company responsible for the development and maintenance of this technology.

License

This project is licensed under the Apache License 2.0 — see the LICENSE file for details.


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 call the Rhai script directly — it has a shebang on top.

Modules

This library provides two main modules:

Module Description
tfchain Ledger Chain blockchain client with dynamic metadata support
explorer Grid Explorer API client with optional Redis caching

Quick Start

Ledger Chain 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:

# Ledger Chain 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

Ledger Chain (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

Installation

Add to your Cargo.toml:

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

Environment

Make sure your key is in the environment:

export TFCHAIN_KEY=...