OutLayer Documentation
Contents
Getting Started
What is OutLayer?#
OutLayer lets you run any off-chain code (random numbers, HTTP requests, AI models, heavy computations) and get the result back in your NEAR smart contract using NEAR's yield/resume mechanism.
You don't need to build infrastructure, manage workers, or deal with access control. Just write your code, push to GitHub, and call it from your contract. OutLayer handles compilation, execution, and returning results.
How Yield/Resume Works on NEAR#
NEAR Protocol's yield/resume feature allows smart contracts to pause execution, wait for external computation to complete, then resume with the result - all within a single logical transaction.
π― Key benefit: From the user's perspective, it's still ONE transaction. They click once, wait a few seconds, and get the final result. No manual follow-up transactions needed.
Why OutLayer Makes This Easy#
β No infrastructure setup - We run the workers, you just write code
β No access control headaches - Your contract stays in control. We just return results, you decide what to do with them in your callback
β No worker delegation - You don't give us permissions on your contract. We can't do anything except call your callback with results
β GitHub-based deployment - Push code to GitHub, reference the repo in your contract call. We compile and execute automatically
β Encrypted secrets support - Need API keys? Store them encrypted on-chain with access control, we inject them as environment variables during execution
Quick Start: 4 Steps#
1οΈβ£ Write WASI Code
Create Rust project that compiles to WebAssembly. Read input from stdin, write output to stdout.
π Follow the Developer Guide for step-by-step tutorial
π‘ See Working Examples for inspiration
2οΈβ£ Push to GitHub
Make your repo public (or private with access tokens). OutLayer will clone and compile it on-demand.
3οΈβ£ Call from Your Contract or Testnet
Option A: Test directly from CLI (no contract needed)
near call outlayer.testnet request_execution '\
{"code_source": {"repo": "github.com/you/project", "commit": "main"}, \
"input_data": "{\"param\":123}"}' \
--accountId you.testnet --deposit 0.1Option B: Integrate in your smart contract
π Contract Integration Guide - See all parameters and callback handling
4οΈβ£ Receive Result in Callback
Your contract receives the result automatically. You control what happens next - no external permissions needed.
Excess payment automatically refunded. Payment based on actual resources used (instructions + time).
Need API Keys or Secrets?#
Store encrypted secrets on-chain with access control (whitelists, NEAR balance checks, NFT ownership, etc). OutLayer workers decrypt and inject them as environment variables - your WASM code accesses them via std::env::var().
π‘ Use the Dashboard: Manage Secrets - Encrypt API keys client-side, store on-chain, use in any execution
Payment & Pricing#
Attach NEAR tokens when calling request_execution. Cost = base fee + (actual instructions used Γ price) + (execution time Γ price).
- Unused deposit automatically refunded
- Users can pay for their own executions (set
payer_account_id) - Or contracts can sponsor execution costs
- Query
estimate_execution_cost()to see pricing before calling