Function syntax
Function source code specification
For a valid MEM function, it is crucial to follow the specifications used by Warp and SmartWeave protocols.
Source code guidelines
The source must be written in the supported programming languages.
The source must include a function named
handle
which can be either synchronous or asynchronous depending on your code logic. Also, it must have two arguments:state
andaction
.The
state
argument represents the current state of the function.The
action
argument must include theinput
field and it holds the arguments passed along with the function interaction
The
input
field may contain the function property and any additional data required for the operation (depending on your logic).
Exiting the handle
function
handle
functionThe handle
function must exit by either returning a result or state or by throwing an error.
Returning
{ state: new_state }
to update the function state.Returning
{ result: new_result }
. to return a result.Throwing an
ContractError("ERROR_TEXT")
exception.
Throwing errors
When an error is thrown in MEM, it immediately terminates the execution of the current function and any subsequent code within that function.
Error statements
throw new ContractError("ERROR_TEXT")
which is equivalent tothrow new Error(""
) in JavaScriptContractAssert(condition)
which is equivalent to theassert
statement innode:assert
Function example
function.js
state.json
Last updated