Write operations

Interact with a MEM function

Interacting with a MEM function is a straightforward process that involves submitting a POST request to the REST base endpoint. By constructing the request with the appropriate parameters and payload, developers can communicate with the MEM network and execute desired actions on the function.

Using curl

curl --location --request POST 'https://api.mem.tech/api/transactions' \
--header 'Content-Type: application/json' \
--data-raw '{
    "functionId": "$YOUR_FUNCTION_ID",
    "inputs": [{
        "input": {"$key": "$value" }
    }]
}'

Using Axios

async function writeFunction() {
  try {
    const inputs = ["input": {"$key": "value" }];
    const functionId = "...";
    
    const req = await axios.post(
      "https://api.mem.tech/api/transactions",
      {
        functionId: functionId,
        inputs: inputs,
      },
      {
        headers: {
          "Content-Type": "application/json",
        },
      },
    );
    console.log(req?.data);
    return req?.data;
  } catch (error) {
    console.log(error);
  }
}

Write Operation Returned Object

The object returned from a write operation in MEM is intentionally designed to be fully compatible with the EXM counterpart. This approach ensures backward compatibility with existing deployed EXM functions.

{
  status: 'SUCCESS',
  data: {
    pseudoId: '...',
    execution: {
      state: [Object],
      result: any,
      errors: {}
    }
  }
}

Write operations in MEM return an optimistic version of the state, which becomes available for read operations once it reaches finality. These optimistic results are based on the latest finalized version of the data.

  • data.pseudoId: Represents a pseudo ID generated during the operation, which may take time to reach finality.

  • data.execution.state: Reflects the optimistic evaluation of the operation or batch of operations sent during the write action.

  • data.execution.result: Holds the value of the result property, if present.

  • data.execution.errors: Thrown errors by the function, if present.

Last updated

mem.tech ยฉ 2023