OutLayer SDK
Rust SDK for building WASM applications on OutLayer - verifiable off-chain computation for NEAR.
Installation
[]
= "0.1"
Requirements: WASI Preview 2 (wasm32-wasip2 target)
Quick Start
use ;
Features
Environment (outlayer::env)
Access execution context and I/O:
use env;
// Get NEAR account info
let signer = signer_account_id; // User who signed tx (alice.near)
let predecessor = predecessor_account_id; // Contract that called OutLayer
let tx_hash = transaction_hash;
// Input/Output
let input: MyRequest = input_json?.unwrap;
output_json?;
// Environment variables (including secrets)
let api_key = var;
Available environment variables:
NEAR_SENDER_ID- Account that signed the transactionNEAR_PREDECESSOR_ID- Contract that called OutLayerNEAR_TRANSACTION_HASH- Transaction hashUSD_PAYMENT- Attached USD payment (micro-units)- Custom secrets stored via dashboard
Storage (outlayer::storage)
Encrypted persistent key-value storage:
use storage;
// Basic operations
set?;
let data = get?;
let exists = has;
delete;
let keys = list_keys?;
// Convenience methods
set_string?;
set_json?;
let config: Config = get_json?.unwrap;
// Atomic operations (concurrent-safe)
increment?;
decrement?;
set_if_absent?;
set_if_equals?;
// Worker-private storage (shared across all users)
set_worker?;
let state = get_worker?;
// Public storage (readable by other projects)
set_worker_with_options?;
let price = get_worker_from_project?;
Storage isolation:
- User storage: Isolated per caller (
alice.nearcan't readbob.near's data) - Worker storage: Shared across all users, only accessible from WASM
- Public storage: Cross-project readable (for oracles, shared configs)
Version Migration
// Read data from previous WASM version
let old_data = get_by_version?;
// Clean up old version's data after migration
clear_version?;
Example Project
# Cargo.toml
[]
= "my-outlayer-app"
= "0.1.0"
= "2021"
[[]]
= "my-outlayer-app"
= "src/main.rs"
[]
= "0.1"
= { = "1.0", = ["derive"] }
= "1.0"
[]
= "s"
= true
= true
// src/main.rs
use ;
use ;
Build and test:
|
Documentation
- OutLayer Docs - Full documentation
- Storage Guide - Persistent storage
- WASI Tutorial - Building WASM apps
- Examples - Working examples
License
MIT OR Apache-2.0