TAKO Smart Contracts
TOS Network smart contracts are written in Rust and compiled to TBPFv3 bytecode, running on the TAKO runtime - an eBPF-inspired virtual machine designed for high-performance blockchain execution.
Why TAKO?
| Feature | TAKO (TOS) | Solidity (EVM) | Rust (Solana) |
|---|---|---|---|
| Language | Rust | Solidity | Rust |
| Runtime | TBPFv3 (eBPF) | EVM | BPF |
| Memory Safety | Compile-time | Runtime | Compile-time |
| Native Syscalls | Yes | No | Yes |
| Performance | High | Medium | High |
| Learning Curve | Medium | Medium | Medium |
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Your Rust Contract │
│ (uses tako_sdk) │
└───────────────────────────┬─────────────────────────────────┘
│ compile (cargo-tako)
▼
┌─────────────────────────────────────────────────────────────┐
│ TBPFv3 Bytecode (.so) │
└───────────────────────────┬─────────────────────────────────┘
│ deploy
▼
┌─────────────────────────────────────────────────────────────┐
│ TAKO Runtime │
│ ┌──────────────┬───────────────┬────────────────────────┐ │
│ │ Executor │ Storage │ Syscalls │ │
│ │ (TBPFv3) │ (RocksDB) │ (Native Features) │ │
│ └──────────────┴───────────────┴────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ TOS Blockchain │
│ (BlockDAG, Consensus, State) │
└─────────────────────────────────────────────────────────────┘Quick Start
1. Install Platform Tools
Method A: Quick Install (Recommended)
# Install TOS Platform Tools
curl -sSf https://tos.network/install.sh | sh
# Verify installation
cargo-tako --versionMethod B: Manual Download from GitHub
Download the appropriate package from GitHub Releases :
| Platform | Architecture | Download |
|---|---|---|
| Linux | x86_64 | tos-platform-tools-linux-x86_64.tar.bz2 (549 MB) |
| Linux | ARM64 | tos-platform-tools-linux-aarch64.tar.bz2 (545 MB) |
| macOS | Apple Silicon | tos-platform-tools-osx-aarch64.tar.bz2 (415 MB) |
| macOS | Intel | tos-platform-tools-osx-x86_64.tar.bz2 (425 MB) |
| Windows | x86_64 | tos-platform-tools-windows-x86_64.tar.bz2 (597 MB) |
Installation Steps:
# 1. Download (example for macOS Apple Silicon)
curl -LO https://github.com/tos-network/platform-tools/releases/latest/download/tos-platform-tools-osx-aarch64.tar.bz2
# 2. Create installation directory
mkdir -p ~/.cache/tos/v1.54
# 3. Extract
tar -xjf tos-platform-tools-osx-aarch64.tar.bz2 -C ~/.cache/tos/v1.54
# 4. Add to PATH (add to ~/.bashrc or ~/.zshrc)
export PATH="$HOME/.cache/tos/v1.54/tos-platform-tools/llvm/bin:$PATH"
export PATH="$HOME/.cache/tos/v1.54/tos-platform-tools/rust/bin:$PATH"
# 5. Verify installation
cargo-tako --version
# Output: cargo-tako 0.3.1Directory Structure After Installation:
~/.cache/tos/v1.54/tos-platform-tools/
├── llvm/
│ └── bin/
│ ├── clang # LLVM Clang 20.1.7
│ ├── lld # LLVM Linker
│ └── ...
├── rust/
│ └── bin/
│ ├── cargo # Cargo 0.94.0
│ ├── cargo-tako # TAKO build tool 0.3.1
│ ├── rustc # Rust 1.91.0-dev
│ └── rustfmt
└── version.md2. Create a New Contract
# Create new contract project
cargo-tako new my_contract
cd my_contract3. Write Your Contract
//! src/lib.rs
#![no_std]
#![no_main]
use tako_sdk::*;
#[no_mangle]
pub extern "C" fn entrypoint() -> u64 {
log("Hello, TOS!");
SUCCESS
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}4. Build and Deploy
# Build the contract
cargo-tako build
# Deploy to testnet
tos_wallet deploy_contract ./target/deploy/my_contract.soContract Structure
Every TAKO contract has:
Required Elements
#![no_std] // No standard library (blockchain environment)
#![no_main] // No main function (uses entrypoint)
use tako_sdk::*; // Import TAKO SDK
// Entry point - called when contract is invoked
#[no_mangle]
pub extern "C" fn entrypoint() -> u64 {
// Your contract logic here
SUCCESS
}
// Panic handler - required for no_std
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}Return Values
// Success - transaction succeeds
return SUCCESS; // 0
// Error - transaction fails
return ERROR; // 1
// Custom error codes
return 1001; // Application-specific errorsAvailable Features
TAKO SDK
Core SDK functions for storage, transfers, and logging
Syscalls APINative TOS features: VRF, Referrals, Privacy
Contract ExamplesHello World, ERC20, Counter, and more
Deployment GuideBuild, test, and deploy your contracts
Key Concepts
Storage
Contracts have persistent storage accessible via key-value operations:
// Write to storage
storage_write(b"my_key", &value_bytes)?;
// Read from storage
let mut buffer = [0u8; 32];
let len = storage_read(b"my_key", &mut buffer);Cross-Contract Calls (CPI)
Contracts can call other contracts:
// Call another contract
let result = cpi_call(
&target_contract, // Contract address
&input_data, // Call data
&mut return_data, // Return buffer
)?;Native Syscalls
Access TOS native features directly:
// VRF Randomness
let random = vrf_random(&seed)?;
// Referral queries
let uplines = tos_get_uplines(&user, 3)?;
// Transfers
transfer(&recipient, amount)?;Development Tools
Platform Tools (v1.54)
Located at ~/.cache/tos/v1.54/tos-platform-tools/:
| Component | Version | Description |
|---|---|---|
| LLVM/Clang | 20.1.7 | C/C++ compiler for TBPF target |
| Rust | 1.91.0-dev | Rust compiler with TOS target |
| Cargo | 0.94.0 | Rust package manager |
| cargo-tako | 0.3.1 | TAKO contract build tool |
| LLD | 20.1.7 | LLVM linker |
Cargo Configuration
Every contract needs .cargo/config.toml:
[build]
target = "tbpfv3-tos-tos"
[target.tbpfv3-tos-tos]
rustflags = [
"-C", "link-arg=-z", "-C", "link-arg=notext",
]Rust Toolchain
rust-toolchain.toml:
[toolchain]
channel = "1.91.0-dev"Gas Costs
| Operation | Compute Units | Approx. Cost |
|---|---|---|
| Basic operation | 1 CU | ~$0.00001 |
| Storage read | 200 CU | ~$0.002 |
| Storage write | 20,000 CU | ~$0.02 |
| Log message | 100 CU | ~$0.001 |
| Transfer | 1,000 CU | ~$0.01 |
| CPI call | 10,000 CU | ~$0.1 |
| VRF random | 10,000 CU | ~$0.01 |
Best Practices
1. Use Checked Arithmetic
// Good - handles overflow
let result = amount.checked_add(fee).ok_or(ERR_OVERFLOW)?;
// Bad - can panic
let result = amount + fee;2. Validate All Inputs
// Validate at entry
if amount == 0 {
return ERR_INVALID_AMOUNT;
}
if is_zero_address(&recipient) {
return ERR_INVALID_ADDRESS;
}3. Emit Events for Important State Changes
// Log important operations
log("Transfer executed");
log_u64(amount, from_balance, to_balance, 0, 0);4. Handle All Error Cases
match storage_write(key, &value) {
Ok(_) => SUCCESS,
Err(e) => {
log("Storage write failed");
e
}
}Next Steps
- TAKO SDK Reference - Learn the core SDK functions
- Syscalls API - Access native TOS features
- Examples - Study working contract code
- Deployment Guide - Deploy your first contract
Last updated on