Run JavaScript
Write custom JavaScript to transform data any way you need — format numbers, sort arrays, calculate values, merge objects, and more. Define a transform(input) function; the result is available as {{nodeId.result.output}}. Runs in a secure sandbox with ES6+ support.
Built-in action Built In
Write custom JavaScript to transform data any way you need — format numbers, sort arrays, calculate values, merge objects, and more. Define a transform(input) function; the result is available as {{nodeId.result.output}}. Runs in a secure sandbox with ES6+ support.
At a Glance
| Field | Value |
|---|---|
| Action ID | code-transform |
| Category | Built In |
| Connector | Not required |
| Requires gas | No |
| Funds movement | None declared |
| Tags | code, transform, javascript, custom, data-processing, compute |
Payload Schema
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Write a 'transform(input)' function. 'input' is whatever you pass in the Input field below. Full ES6+ support, sandboxed (no network/filesystem). |
input | object | Yes | The data passed to your transform(input) function. Whatever you reference here becomes 'input' in your code. For example, if you set this to {{node.result.items}}, then 'input' is that array directly. |
timeout | number | No | Execution timeout in milliseconds (default: 5000ms, max: 10000ms) |
inputType | object | No | Declares the expected input type for validation (optional). Example: {"type": "array"} |
outputType | object | No | Declares the output type for validation and variable suggestions (optional). Example: {"type": "array", "items": {"type": "object", "properties": {"name": {"type": "string"}}}} |
Result Schema
| Field | Type | Required | Description |
|---|---|---|---|
output | string | number | boolean | null | array | object | Yes | The result returned by your transform function. Can be any JSON-serializable value (primitive, object, array, nested structures). The output is available to subsequent workflow actions via {{nodeId.result.output}} or {{nodeId.result.output.field}} for object results. |
executionTimeMs | number | Yes | Code execution time in milliseconds |
language | string | Yes | Language used for execution |
Examples
json{ "type": "code-transform", "payload": { "code": "// When input='{{node.result.exchanges}}' (array), input IS the array:", "input": "{{prevNode.result.items}}" }, "children": []}
bashcurl -X POST "https://api.b3os.org/v1/actions/code-transform/test" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "inputs": { "code": "// When input='{{node.result.exchanges}}' (array), input IS the array:", "input": "{{prevNode.result.items}}" }}'
Payload fields can use workflow expressions such as {{$trigger.body.amount}}, {{$nodes.fetch.result.price}}, and {{$props.asset}} when the value should come from a trigger, prior node, or reusable workflow prop.
