Tensora Rust SDK
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
๐ Features
- โ Typed Contract Bindings โ Auto-generated bindings for TORA token, staking, subnets, bridge, and paymaster
- ๐ Wallet Abstraction โ Secure keystore and signer management
- ๐ Bridge Helpers โ L1โL2 token bridging (WTORA deposits/withdrawals)
- ๐ API Clients โ REST clients for indexer, explorer, and coordinator services
- โฝ Paymaster Support โ ERC-4337 gasless transactions
- ๐๏ธ Subnet Management โ Create and manage subnets, validators, and miners
- ๐ Async-first โ Built on
tokioandethers-rs - ๐ก๏ธ BSC Reorg Handling โ Safe bridge operations with confirmation tracking
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.1"
= "2"
= { = "1", = ["full"] }
Or use cargo add:
โก Quick Start
1. Set Up Environment
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
2. Connect to Tensora L2
use *;
async
3. Check Balance
use *;
async
4. Work with TORA Token
use *;
use ToraToken;
async
5. Query Subnet Information
use IndexerClient;
async
๐ Examples
Run the included examples:
# Check balance
# Monitor bridge deposits
# Check staking info
๐ง Configuration
Environment Variables
| 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 | - |
Programmatic Configuration
use ;
let config = new
.with_private_key
.with_addresses;
๐๏ธ Architecture
Core Modules
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 withthiserrorcontractsโ Smart contract bindingstora_tokenโ TORA/WTORA ERC-20 tokenstaking_hubโ Staking and rewardssubnet_factoryโ Subnet creation and managementbridgeโ OP Stack L1/L2 Standard Bridgepaymasterโ ERC-4337 Paymaster
apiโ Off-chain API clientsindexerโ Subnet, validator, and miner dataexplorerโ Transaction and block datacoordinatorโ Epoch and VRF data
๐ Bridge Operations
L1 โ L2 Deposit (BSC โ Tensora)
// 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.
L2 โ L1 Withdrawal (Tensora โ BSC)
// 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
๐ Staking
use StakingHub;
// Get staking info
let staking_hub = new;
let total_staked = staking_hub.get_total_staked.await?;
let my_stake = staking_hub.get_stake.await?;
let rewards = staking_hub.get_rewards.await?;
// Note: stake(), unstake(), and claim() require SignerMiddleware
๐งช Testing
๐ Documentation
Generate and view documentation:
Or visit docs.rs/tensora-rs
๐ Network Information
Tensora L2 Mainnet
| Parameter | Value |
|---|---|
| Chain ID | 44444444 |
| RPC | https://rpc.tensora.sh |
| Explorer | https://explorer.tensora.sh |
| Native Token | BNB |
| Wrapped Token | WTORA |
BSC L1
| Parameter | Value |
|---|---|
| Chain ID | 56 |
| RPC | https://bsc-dataseed.binance.org |
| Explorer | https://bscscan.com |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
๐ Links
- Homepage: https://tensora.sh
- Documentation: https://docs.tensora.sh
- Explorer: https://explorer.tensora.sh
- GitHub: https://github.com/TensoraL2/tensora-rs
- Discord: https://discord.gg/tensora
โ ๏ธ Disclaimer
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