Assembly Script
import { JSON, JSONEncoder } from "assemblyscript-json";
export function handle(state: JSON.Obj): JSONEncoder {
const counter: JSON.Integer | null = state.getInteger("counter");
let encoder = new JSONEncoder();
encoder.pushObject(null);
if (counter === null) {
encoder.setInteger("counter", 0);
} else {
encoder.setInteger("counter", (counter.valueOf() + 1) as i64);
}
encoder.popObject();
return encoder;
}
asc function.ts --runtime stub --converge -O --noAssert --trapMode clamp --transform ../transform -o function.wasm
Deployments concepts can be found at https://docs.exm.dev/trustless-serverless-functions/deploying-functions
$ exm function:deploy --src function.wasm --init-state "{"counter": 0}" --token MY_EXM_TOKEN
$ exm function:write [functionId] --input '{}' --token MY_EXM_TOKEN
// { state: { counter: 1 } }
Last modified 8mo ago