| Crates.io | tensora-rs |
| lib.rs | tensora-rs |
| version | 0.1.0 |
| created_at | 2025-10-20 08:49:56.734977+00 |
| updated_at | 2025-10-20 08:49:56.734977+00 |
| description | Rust SDK for the Tensora L2 AI Network built with OP Stack and BSC settlement. |
| homepage | https://tensora.sh |
| repository | https://github.com/TensoraL2/tensora-rs |
| max_upload_size | |
| id | 1891623 |
| size | 210,827 |
Official Rust SDK for the Tensora L2 AI Network
A production-ready SDK for building on Tensora โ an OP Stack Layer-2 blockchain with BSC settlement
๐ Documentation โข ๐ Quick Start โข ๐๏ธ Architecture โข ๐ฌ Discord
tokio and ethers-rsAdd to your Cargo.toml:
[dependencies]
tensora = "0.1"
ethers = "2"
tokio = { version = "1", features = ["full"] }
Or use cargo add:
cargo add tensora ethers
cargo add tokio --features full
Create a .env file:
TENSORA_RPC=https://rpc.tensora.sh
TENSORA_CHAIN_ID=44444444
BSC_RPC=https://bsc-dataseed.binance.org
PRIVATE_KEY=0x... # Optional, for signing transactions
use tensora::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment
let config = TensoraConfig::from_env()?;
// Create client
let client = TensoraClient::new(&config).await?;
// Get current block number
let block = client.get_block_number().await?;
println!("Current block: {}", block);
Ok(())
}
use tensora::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = TensoraClient::default().await?;
let address: Address = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb".parse()?;
let balance = client.get_balance(address).await?;
println!("Balance: {} BNB", ethers::utils::format_ether(balance));
Ok(())
}
use tensora::prelude::*;
use tensora::contracts::ToraToken;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = TensoraClient::default().await?;
// WTORA token address on Tensora L2
let wtora_addr: Address = "0x...".parse()?;
let wtora = ToraToken::new(wtora_addr, &client);
// Get token info
let symbol = wtora.symbol().await?;
let decimals = wtora.decimals().await?;
let total_supply = wtora.total_supply().await?;
println!("Token: {}", symbol);
println!("Decimals: {}", decimals);
println!("Total Supply: {}", ethers::utils::format_units(total_supply, decimals)?);
// Check balance
let my_addr: Address = "0x...".parse()?;
let balance = wtora.balance_of(my_addr).await?;
println!("My balance: {} {}", ethers::utils::format_units(balance, decimals)?, symbol);
Ok(())
}
use tensora::api::IndexerClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let indexer = IndexerClient::new("https://indexer.tensora.sh")?;
// List all subnets
let subnets = indexer.list_subnets().await?;
for subnet in subnets {
println!("Subnet #{}: {} ({} validators, {} miners)",
subnet.id,
subnet.name,
subnet.validator_count,
subnet.miner_count
);
}
Ok(())
}
Run the included examples:
# Check balance
cargo run --example get_balance
# Monitor bridge deposits
cargo run --example bridge_deposit
# Check staking info
cargo run --example stake
| Variable | Description | Default |
|---|---|---|
TENSORA_RPC |
Tensora L2 RPC endpoint | https://rpc.tensora.sh |
TENSORA_CHAIN_ID |
Tensora L2 chain ID | 44444444 |
BSC_RPC |
BSC L1 RPC endpoint | https://bsc-dataseed.binance.org |
BSC_CHAIN_ID |
BSC chain ID | 56 |
PRIVATE_KEY |
Private key for signing (optional) | - |
L1_WTORA |
WTORA address on BSC | - |
L2_WTORA |
WTORA address on Tensora | - |
L1_BRIDGE |
L1 Standard Bridge address | - |
L2_BRIDGE |
L2 Standard Bridge address | - |
STAKING_HUB |
Staking Hub contract address | - |
SUBNET_FACTORY |
Subnet Factory contract address | - |
ENTRY_POINT |
ERC-4337 EntryPoint address | - |
PAYMASTER |
Paymaster contract address | - |
use tensora::config::{TensoraConfig, AddressConfig};
let config = TensoraConfig::new(
"https://rpc.tensora.sh".to_string(),
"https://bsc-dataseed.binance.org".to_string(),
)
.with_private_key("0x...".to_string())
.with_addresses(AddressConfig {
l2_wtora: Some("0x...".to_string()),
staking_hub: Some("0x...".to_string()),
..Default::default()
});
client โ RPC client for L2 (Tensora) and L1 (BSC)config โ Configuration management and validationwallet โ Wallet and signer abstractiontypes โ Shared types (SubnetInfo, ValidatorInfo, etc.)errors โ Error handling with thiserrorcontracts โ Smart contract bindings
tora_token โ TORA/WTORA ERC-20 tokenstaking_hub โ Staking and rewardssubnet_factory โ Subnet creation and managementbridge โ OP Stack L1/L2 Standard Bridgepaymaster โ ERC-4337 Paymasterapi โ Off-chain API clients
indexer โ Subnet, validator, and miner dataexplorer โ Transaction and block datacoordinator โ Epoch and VRF data// Note: This requires a signer and actual bridge implementation
// Placeholder for reference:
// 1. Approve WTORA on L1
// 2. Call depositERC20() on L1 Bridge
// 3. Wait for L1 confirmation
// 4. Wait for L2 relay (2-5 minutes)
// 5. Verify balance on L2
โ ๏ธ Important: BSC can experience reorgs. Wait for at least 15 confirmations on L1 before considering a deposit finalized.
// Note: This requires a signer and actual bridge implementation
// Withdrawal process:
// 1. Call withdrawERC20() on L2 Bridge
// 2. Wait for state root submission (~1 hour)
// 3. Wait for challenge period (~7 days on mainnet, faster on testnet)
// 4. Call finalizeWithdrawal() on L1
// 5. Verify balance on L1
use tensora::contracts::StakingHub;
// Get staking info
let staking_hub = StakingHub::new(staking_addr, &client);
let total_staked = staking_hub.get_total_staked().await?;
let my_stake = staking_hub.get_stake(my_addr).await?;
let rewards = staking_hub.get_rewards(my_addr).await?;
// Note: stake(), unstake(), and claim() require SignerMiddleware
cargo test
Generate and view documentation:
cargo doc --open
Or visit docs.rs/tensora-rs
| Parameter | Value |
|---|---|
| Chain ID | 44444444 |
| RPC | https://rpc.tensora.sh |
| Explorer | https://explorer.tensora.sh |
| Native Token | BNB |
| Wrapped Token | WTORA |
| Parameter | Value |
|---|---|
| Chain ID | 56 |
| RPC | https://bsc-dataseed.binance.org |
| Explorer | https://bscscan.com |
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)Licensed under the Apache License, Version 2.0. See LICENSE for details.
This SDK is provided "as is" without warranty of any kind. Use at your own risk. Always test on testnet before using on mainnet.
Built with โค๏ธ by the Tensora Labs team