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.

1
User→Contract
2
Contract→OutLayer
request_execution(repo, input_data, limits, secrets)
⏸️ YIELD - Transaction paused
3
OutLayer→Worker
πŸ”¨ Off-chain work:
β€’ Clone from GitHub
β€’ Compile code (10 sec+)
β€’ Execute WASM (<1 sec - few min)
β€’ Read stdout output
4
Worker→OutLayer
Return execution output
5
OutLayer→Contract
▢️ RESUME - Process result in callback
βœ… Transaction Complete!
User receives final result

🎯 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.1

Option 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

Ready to Build?#