Search
⌃K

Complex Actions

Given that EXM uses the SmartWeave Standard, the entry point of your EXM Function is a method called handle. This method has two parameters: state and action .
  • state: Contains the current state of the application
  • action: Object with path to write operation.
action itself does not contain the write operation. The data of the write information is found inside action.input.

Example

Initial State:

{ "users": [] }

EXM Function:

export function handle(state, action) {
state.users.push(action.input.name);
return { state }
}

Raw Write Operation

{
"name": "Tom Holland"
}

CLI Write Operation

$ exm function:write <functionId> --input '{"name": "Tom Holland"}' --token MY_EXM_TOKEN

SDK Write Operation

JS SDK
const { Exm } = require('@execution-machine/sdk');
const exmInstance = new Exm({ token: 'MY_EXM_TOKEN' });
exmInstance.functions.write('<functionId>', {
name: "Tom Holland"
});

REST

$ curl --location --request POST 'https://api.exm.dev/api/transactions?token=MY_EXM_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"functionId": "<functionId>",
"inputs": [{"input":"{\"name\":\"Tom Holland\"}"}]
}'