Overview
To maintain consistency and security, all Stratus functions are validated before they are saved. This guide explains the required syntax, module restrictions, and best practices to help you create functions that pass validation.
Module Export & Handler Function
Single Handler Export
Your code must export exactly one handler function.
Exporting multiple handler definitions or not exporting a handler at all will
cause validation to fail.
// ❌ Incorrect – no exported handler:
const handler = async ( input , output ) => { ... };
Always export your handler as a property of module.exports.
// ✅ Correct:
module . exports . handler = async ( input , output ) => {
// Function body...
}
The exported handler must be a function. Assigning non-function values (e.g.,
a string) will trigger an error.
Handler Function Parameters & Behavior
Parameter Requirements
The handler function must accept exactly two parameters:
input – holds input data
output – provides methods for setting and building the function’s output
module . exports . handler = async ( input , output ) => { ... };
Using output.setResult
Inside your handler, you must call output.setResult to set the result object.
// ❌ Incorrect:
module . exports . handler = async ( input , output ) => {
// Missing call to output.setResult
return output . buildOutput ()
}
Calling output.buildOutput()
The handler must return the result of output.buildOutput(). Omitting this
call is not allowed.
// ✅ Correct:
module . exports . handler = async ( input , output ) => {
output . setResult ({ message: 'Hello' })
return output . buildOutput ()
}
If the handler does not accept exactly two parameters, validation will fail
with a message similar to: “The ‘handler’ function must accept exactly two
parameters: ‘input’ and ‘output’.”
Module Import Requirements
Allowed Modules
You may include external modules via require(), but only approved packages are allowed:
axios
lodash
viem and its approved subpath viem/chains
const axios = require ( 'axios' )
Disallowed Modules
The following are not allowed:
Modules not on the approved list (e.g., Node’s fs)
Unapproved subpaths from approved packages
Dynamic requires (using variables for module names)
// ❌ Incorrect:
const mod = 'axios'
const axios = require ( mod ) // Dynamic require not allowed
Adding extra properties to module.exports (aside from the handler) is allowed and will not affect validation:
module . exports . extra = 'some extra value'
module . exports . handler = async ( input , output ) => {
output . setResult ({ message: 'Hello' })
return output . buildOutput ()
}
JavaScript Syntax
Valid JavaScript
Your code must be syntactically valid JavaScript. Common syntax errors include:
Missing closing braces
Unmatched parentheses
Invalid syntax
// ❌ Example of Syntax Error:
module . exports . handler = async ( input , output ) => {
output . setResult ({ message: "Hello" })
return output . buildOutput (; // Error: Unmatched parenthesis
};
Common Validation Error Messages
You may encounter the following validation errors:
"Module 'unknown/chains' is not approved"
"User code must export exactly one handler function"
"Invalid dynamic require detected"
"Failed to validate user code: ..."
"The 'handler' property must be assigned to a function"
"Multiple handler definitions found"
"The 'handler' function must accept exactly two parameters: 'input' and 'output'"
"The 'handler' function must use output.setResult"
"The 'handler' function must call output.buildOutput()"
Examples
Valid Stratus Function with External Module
const axios = require ( 'axios' )
module . exports . handler = async ( input , output ) => {
const response = await axios . get ( 'https://example.com' )
output . setResult ({ data: response . data })
return output . buildOutput ()
}
Valid Function Without External Modules
module . exports . handler = async ( input , output ) => {
output . setResult ({ message: 'Hello World!' })
return output . buildOutput ()
}
Common Mistakes
// ❌ Incorrect: Multiple handler definitions
module . exports . handler = async ( input , output ) => { ... };
module . exports . handler = async ( input , output ) => { ... };
// ❌ Incorrect: Missing output.setResult
module . exports . handler = async ( input , output ) => {
return output . buildOutput ();
};
// ❌ Incorrect: Dynamic require
const mod = 'axios' ;
const axios = require ( mod );
Summary
To ensure your Stratus function passes syntax validation:
Export one handler function using the correct module export syntax
Ensure the handler is asynchronous and accepts exactly two parameters: input and output
Call both output.setResult and output.buildOutput() within your handler
Import only approved modules using string literals (no dynamic requires)
Write valid JavaScript with correct syntax