Full documentation on the OutLayer dashboard.
Simple WASM binary for testing NEAR OutLayer platform with WASI support.
Generates a random number in the specified range using rand crate with WASI random source.
Reads input from stdin and writes output to stdout.
{
"min": 0,
"max": 100
}{
"random_number": 42
}# Add WASI target
rustup target add wasm32-wasip1
# Build
cargo build --release --target wasm32-wasip1
# Output: target/wasm32-wasip1/release/random-ark.wasm (~111KB)# Test with wasmtime
echo '{"min":1,"max":100}' | wasmtime target/wasm32-wasip1/release/random-ark.wasm
# Expected output: {"random_number":42} (some number between 1-100)-
Push this code to a GitHub repository (e.g., https://github.com/zavodil/random-ark)
-
Call
request_executionon the OffchainVM contract:
near call outlayer.testnet request_execution '{
"code_source": {
"repo": "https://github.com/zavodil/random-ark",
"commit": "main",
"build_target": "wasm32-wasip1"
},
"resource_limits": {
"max_instructions": 10000000,
"max_memory_mb": 128,
"max_execution_seconds": 60
},
"input_data": "{\"min\":1,\"max\":100}"
}' --accountId your-account.testnet --deposit 0.1- Worker will:
- Compile the WASM in sandboxed Docker container
- Execute with wasmi (WASI P1) or wasmtime (WASI P2)
- Return the random number as readable text (not bytes!)
- Show result in NEAR explorer
cargo test