Documentation
Guides and reference for OutLayer verifiable compute and agent custody.
Docs navigation
NEAR Integration
Call OutLayer from your NEAR smart contract to execute off-chain WASM code and receive the result via callback. You stay in full control — no need to grant special access or delegate permissions to workers.
For Web2 projects (web apps, mobile apps, APIs) see Web2 Integration — call OutLayer via HTTPS without blockchain transactions.
Method: request_execution#
Call outlayer.testnet (testnet) or outlayer.near (mainnet)
Parameters (all fields):
source: ExecutionSource (required)
Names a published .wasm by its sha256; the worker refuses a file whose bytes do not match the hash. Two variants:
Variant 1: Project (registered project, the normal case)
project_id: Project ID (e.g., "alice.near/my-app")version_key: Optional. A version's wasm hash (null = active version)
Use Project for registered apps with persistent storage. Automatically uses project secrets if available.
Variant 2: WasmUrl (direct run of a published file)
url:https://URL of the WASM file on the default port (e.g., a FastFS URL fromoutlayer upload)hash: SHA256 of the WASM filebuild_target: "wasm32-wasip1" or "wasm32-wasip2"
A project version's source is always a WasmUrl.
resource_limits: ResourceLimits (required)
Maximum resources to allocate. Always pass it, even as {}: a request without it runs nothing. A field left out takes its default:
max_instructions: u64 (default: 1 billion, max: 500 billion)max_memory_mb: u32 (default: 128 MB, max 4096)max_execution_seconds: u64 (default: 60s, max: 180s)
input_data: String (optional)
JSON string passed to WASM as stdin. Your code reads it via std::io::stdin()
Example: {"min":1,"max":100}
secrets_ref: SecretsReference (optional)
Reference to encrypted secrets stored on-chain
profile: Profile name (e.g., "production", "staging")account_id: Account that owns the secrets
Worker decrypts secrets and injects as environment variables accessible via std::env::var()
Secrets can be bound to a project OR to a WASM hash. When using WasmUrl, secrets bound to the hash are automatically matched.
response_format: ResponseFormat (optional)
How to parse WASM stdout (default: Text)
Text: Return raw stdout as string (default)Json: Parse stdout as JSON valueBytes: Return raw bytes
payer_account_id: AccountId (optional)
Who receives the refund for unused resources:
- None (default): Sender pays and receives refund
- Some(user_account): Charge end user, refund to user
Useful for contracts that want users to pay for their own executions
params: ExecutionParams (optional)
Advanced execution control parameters:
attached_usd: U128 (optional) - Payment to the project owner in stablecoin minimal units (1_000_000 = $1), deducted from your stablecoin balance in the contract. Project source only.use_bound_identity: bool (default: false) - Run the guest under the caller's bound account name. See Running a job under the bound name.
What You Get Back (Callback)#
OutLayer reads stdout from your WASM code and returns it to your contract's callback. You can write anything to stdout — a number, text, JSON object — and parse it however you want.
- Success case: Your stdout output (parsed according to response_format: Text/Json/Bytes)
- Failure case: Error information (WASM hash mismatch, timeout, etc.)
- Resource metrics: Actual instructions used, execution time
- Automatic refund: Unused deposit sent to payer_account_id
Important: You stay in full control. OutLayer just executes your code and returns stdout — no special permissions needed on your contract. You decide what to do with the results in your callback logic.
Example Contract Call#
use near_sdk::{near, env, Promise, Gas};
use serde_json::json;
#[near(contract_state)]
pub struct Contract {}
#[near]
impl Contract {
pub fn call_outlayer(&mut self, city: String) -> Promise {
// Call OutLayer with a project
Promise::new("outlayer.near".parse().unwrap())
.function_call(
"request_execution".to_string(),
json!({
"source": {
"Project": {
"project_id": "alice.near/weather-api"
}
},
"input_data": json!({"city": city}).to_string(),
"resource_limits": {
"max_instructions": 1_000_000_000,
"max_execution_seconds": 30
}
}).to_string().into_bytes(),
env::attached_deposit(),
Gas::from_tgas(100)
)
.then(
Self::ext(env::current_account_id())
.with_static_gas(Gas::from_tgas(10))
.on_outlayer_result()
)
}
#[private]
pub fn on_outlayer_result(&mut self) {
// Handle the result from OutLayer
match env::promise_result(0) {
near_sdk::PromiseResult::Successful(data) => {
let result: String = String::from_utf8(data).unwrap();
env::log_str(&format!("Weather result: {}", result));
}
_ => {
env::log_str("OutLayer execution failed");
}
}
}
}Pricing & Payment#
Attach NEAR tokens when calling request_execution. Cost is calculated dynamically based on resources used:
- Base fee + (instructions used × per-instruction fee) + (execution time × per-millisecond fee)
- Unused funds automatically refunded to
payer_account_id - A failed execution is charged for the resources it used; the rest of the deposit is refunded
- Query
estimate_execution_cost(resource_limits, input_len)before calling: the compute estimate plus, for aninput_datalonger than 32 KB, 0.00001 NEAR per byte above that, held while the request is pending and returned at settlement
Performance Tips#
Execution time: Depends on your code — from milliseconds to minutes based on complexity and resource limits
FastFS Workflow#
Build the WASM yourself, publish it on FastFS, and deploy it as a project version:
cargo build --target wasm32-wasip2 --release
outlayer upload target/wasm32-wasip2/release/my-app.wasm
# prints SHA256 and: FastFS URL: https://main.fastfs.io/<you>/outlayer.near/<sha256>.wasm
outlayer deploy my-app <FastFS URL> # creates the project or adds a version, activates itCall it with the Project source, or run the file directly with WasmUrl and the same URL and hash. Testnet uses test.fastfs.io and the receiver outlayer.testnet. Any https URL works for outlayer deploy; FastFS is the default.
Why a hash: A version is a file named by its hash, so what a caller runs and pays for cannot change under that version afterwards — a repository can change under the same name and commit history can be rewritten.
TEE Attestation#
Every execution produces a cryptographic attestation from Intel TDX proving:
- Code integrity — Exact WASM binary that ran (SHA256 hash)
- Input integrity — Exact input data received
- Output integrity — Result was produced by that code with that input
- Worker identity — Registered TEE worker with verified measurements
View attestations at /executions → "View Attestation". Learn more: TEE Attestation Documentation
Related Documentation
- Projects & Storage - Version management, persistent storage
- Secrets - Store API keys for your WASM code
- Pricing - Cost calculation and resource limits
- Examples - Working code examples