Search…
⌃K

Function Standard

EXM uses the SmartWeave standard created by the Arweave team.

Handler

The handler is known as the entry point for your EXM function. This handler is a method named handle in the language you are writing your EXM function in. A few examples are shown below:
Javascript
AssemblyScript
export async function handle(state, action) {}
import { JSON, JSONEncoder } from "assemblyscript-json";
export function handle(state: JSON.Obj, action: JSON.Obj): JSONEncoder {}

State Upgrades

For a write operation to be able to change the state of the function, it needs to return an object with state property in it.
export async function handle(state, action) {
return { state: /* state */ }
}
In the example above, an array of objects (users) is returned inside the state property, this means, the new state of the function is equal to users.
It is not mandatory to return JSON objects or arrays but anything can be returned for the state of the function.

One-time Responses

A write operation can execute code and return it in the same way a serverless function would. To do this, you can return an object with the property result
export async function handle(state, action) {
return { result: ' Some Value' }
}

Considerations

  • A function can return state without result
  • A function can return result without state (No updates will be made to the state)
  • A function can return both result and state