Skip to Content
Smart ContractsOverview

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?

FeatureTAKO (TOS)Solidity (EVM)Rust (Solana)
LanguageRustSolidityRust
RuntimeTBPFv3 (eBPF)EVMBPF
Memory SafetyCompile-timeRuntimeCompile-time
Native SyscallsYesNoYes
PerformanceHighMediumHigh
Learning CurveMediumMediumMedium

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

# Install TOS Platform Tools curl -sSf https://tos.network/install.sh | sh # Verify installation cargo-tako --version

Method B: Manual Download from GitHub

Download the appropriate package from GitHub Releases :

PlatformArchitectureDownload
Linuxx86_64tos-platform-tools-linux-x86_64.tar.bz2  (549 MB)
LinuxARM64tos-platform-tools-linux-aarch64.tar.bz2  (545 MB)
macOSApple Silicontos-platform-tools-osx-aarch64.tar.bz2  (415 MB)
macOSInteltos-platform-tools-osx-x86_64.tar.bz2  (425 MB)
Windowsx86_64tos-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.1

Directory 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.md

2. Create a New Contract

# Create new contract project cargo-tako new my_contract cd my_contract

3. 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.so

Contract 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 errors

Available Features

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/:

ComponentVersionDescription
LLVM/Clang20.1.7C/C++ compiler for TBPF target
Rust1.91.0-devRust compiler with TOS target
Cargo0.94.0Rust package manager
cargo-tako0.3.1TAKO contract build tool
LLD20.1.7LLVM 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

OperationCompute UnitsApprox. Cost
Basic operation1 CU~$0.00001
Storage read200 CU~$0.002
Storage write20,000 CU~$0.02
Log message100 CU~$0.001
Transfer1,000 CU~$0.01
CPI call10,000 CU~$0.1
VRF random10,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

  1. TAKO SDK Reference - Learn the core SDK functions
  2. Syscalls API - Access native TOS features
  3. Examples - Study working contract code
  4. Deployment Guide - Deploy your first contract
Last updated on