Skip to content

glin-ai/glin-sdk-rust

Repository files navigation

GLIN Logo

GLIN SDK - Rust

License Rust Crates.io

Official Rust SDK for GLIN Network - A decentralized AI training platform built on Substrate.

🎯 Overview

Complete Rust SDK for building applications on GLIN Network. Provides all core blockchain features (same as TypeScript and Python SDKs) plus Rust-specific extensions for high-performance tools.

βœ… Core Features (Standard across all GLIN SDKs)

  • 🌐 Network connection and RPC
  • πŸ” Account management and signing
  • πŸ“œ Contract deployment and interaction
  • πŸ’Έ Transaction building and submission
  • πŸ“‘ Event subscriptions
  • πŸ“‹ Metadata parsing

πŸš€ Rust-Specific Extensions

  • 🎨 CLI tools with colored output and progress bars
  • ⚑ High-performance blockchain indexing
  • βœ… Contract verification utilities
  • πŸ”§ Type-safe contract code generation

πŸ“š Documentation

πŸ“– Full Documentation β†’

πŸ“¦ Workspace Structure

This is a Cargo workspace containing four crates:

  • glin-client: Network connection, accounts, and RPC operations
  • glin-contracts: Contract metadata, deployment, interaction, and verification
  • glin-types: Shared types and data structures
  • glin-indexer: Blockchain indexing utilities (block streaming, event decoding)

πŸš€ Quick Start

Installation

Add to your Cargo.toml:

[dependencies]
glin-client = "0.1.0"
glin-contracts = "0.1.0"

# Or use local path during development
glin-client = { path = "../glin-sdk-rust/glin-client" }
glin-contracts = { path = "../glin-sdk-rust/glin-contracts" }

Network Connection

use glin_client::{create_client, GlinClient};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Connect to network
    let client = create_client("wss://testnet.glin.ai").await?;

    // Use client for RPC calls
    let block_hash = client.rpc().finalized_head().await?;
    println!("Latest finalized block: {:?}", block_hash);

    Ok(())
}

Account Management

use glin_client::{get_dev_account, account_from_seed, get_address};

// Development accounts
let alice = get_dev_account("alice")?;
println!("Alice address: {}", get_address(&alice));

// From seed phrase
let keypair = account_from_seed("//Alice")?;

// From mnemonic
let mnemonic = "word1 word2 word3 ... word12";
let keypair = account_from_seed(mnemonic)?;

Contract Metadata Fetching

use glin_contracts::{fetch_contract_metadata, MetadataFetchOptions};

let options = MetadataFetchOptions {
    local_path: None,
    explorer_url: Some("https://glinscan.com".to_string()),
    cache_dir: Some("/home/user/.glin/cache".to_string()),
};

let metadata = fetch_contract_metadata(
    &client,
    "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    options
).await?;

Contract Information

use glin_contracts::get_contract_info;

let info = get_contract_info(&client, contract_address).await?;
println!("Code hash: 0x{}", hex::encode(info.code_hash));
println!("Storage deposit: {}", info.storage_deposit);

πŸ› οΈ Use Cases

For Application Developers

Build DApps and services on GLIN Network:

use glin_client::GlinClient;
use glin_contracts::Contract;

// Connect and interact with contracts
let client = create_client("wss://testnet.glin.ai").await?;
let contract = Contract::new(&client, address, metadata)?;

For CLI Tool Developers

Build developer tools like glin-forge:

use colored::Colorize;
use glin_client::create_client;

println!("{} Deploying contract...", "β†’".cyan());
let client = create_client(rpc_url).await?;
println!("{} Connected!", "βœ“".green().bold());

For Indexer Developers

Build high-performance blockchain indexers like glinscan:

use glin_client::create_client;
use glin_indexer::{BlockStream, EventDecoder, ExtrinsicParser};
use futures::StreamExt;

let client = create_client("wss://testnet.glin.ai").await?;
let decoder = EventDecoder::new(&client)?;
let parser = ExtrinsicParser::new();

let mut stream = BlockStream::subscribe_finalized(&client).await?;

while let Some(block) = stream.next().await {
    let block = block?;

    // Parse extrinsics
    for ext in block.extrinsics().await?.iter() {
        let info = parser.parse(&ext?, block.number())?;
        // Store in database...
    }

    // Decode events
    for event in block.events().await?.iter() {
        let decoded = decoder.decode(&event?)?;
        // Store in database...
    }
}

See examples/block_indexer.rs for a complete example.

πŸ—οΈ Projects Using This SDK

  • glin-forge: CLI tools for ink! contract development
  • glinscan (planned): Blockchain explorer and indexer
  • Your project here! πŸš€

πŸ“š Architecture

glin-sdk-rust/
β”œβ”€β”€ glin-client/       # Network & RPC
β”‚   β”œβ”€β”€ Connection management
β”‚   β”œβ”€β”€ Account utilities
β”‚   β”œβ”€β”€ Block subscriptions
β”‚   └── Batch operations
β”‚
β”œβ”€β”€ glin-contracts/    # Contract utilities
β”‚   β”œβ”€β”€ Metadata fetching
β”‚   β”œβ”€β”€ Chain info queries
β”‚   β”œβ”€β”€ Encoding/decoding
β”‚   β”œβ”€β”€ Metadata parsing
β”‚   └── Contract verification
β”‚
β”œβ”€β”€ glin-types/        # Shared types
β”‚   β”œβ”€β”€ Block types
β”‚   β”œβ”€β”€ Event types
β”‚   β”œβ”€β”€ Extrinsic types
β”‚   β”œβ”€β”€ Account types
β”‚   └── Contract types
β”‚
└── glin-indexer/      # Indexing utilities (NEW in v0.2.0)
    β”œβ”€β”€ BlockStream - Block subscription helper
    β”œβ”€β”€ EventDecoder - Event decoding utilities
    └── ExtrinsicParser - Transaction parsing

πŸ”— Related SDKs

GLIN Network provides SDKs for multiple languages:

  • glin-sdk: TypeScript/JavaScript SDK (frontend + backend)
  • glin-sdk-rust (this repo): Rust SDK (backend + CLI tools)
  • glin-sdk-python (planned): Python SDK (data science + analytics)

All SDKs share the same core features, with language-specific extensions. See Rust SDK Documentation β†’ for details.

πŸ› οΈ Development

# Clone repository
git clone https://github.com/glin-ai/glin-sdk-rust.git
cd glin-sdk-rust

# Build all crates
cargo build

# Run tests
cargo test

# Check formatting
cargo fmt --check

# Lint
cargo clippy --all-targets --all-features -- -D warnings

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

πŸ“„ License

Apache-2.0 - see LICENSE for details

πŸ”— Links

πŸ“§ Contact

About

Official Rust SDK for GLIN Network - A decentralized AI training platform

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages