MEM
WebsiteLabsGuides
  • โš—๏ธMolecular Execution Machine
  • ๐Ÿ‘‹Introduction
    • What is MEM?
    • MEM features
    • MEM vs alternatives
    • Technical architecture
    • Use-case examples
  • โšกQuickstart
    • Quickstart guide
  • ๐Ÿ“–MEM Specifications
    • Function syntax
    • Function specs
    • Transaction specs
    • Supported languages
    • About MIPs
  • โš›๏ธMolecules
    • Overview
    • Multichain authentication
    • Using APIs
    • API reference
  • ๐ŸงชMEM IDE
    • Overview
    • Function ABI
  • โš’๏ธMEM Carbon Testnet
    • Overview
    • Deploy to testnet
    • Interact with testnet functions
  • โš™๏ธMEM SDK
    • SDK Usage
  • ๐Ÿ–ฅ๏ธMEM CLI
    • Function deployment
    • Function interaction
  • ๐Ÿ—๏ธMEM API
    • Overview
    • Write operations
    • Read operations
  • โš›๏ธ3EM-MEM
    • Overview
    • EXM API
    • Key-Value Storage (KVS)
  • ๐ŸงฉExamples
    • Pastebin clone
    • Query onchain data
Powered by GitBook

mem.tech ยฉ 2023

On this page
  • Using curl
  • Using Axios
  • Write Operation Returned Object
  1. MEM API

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.

PreviousOverviewNextRead operations

Last updated 1 year ago

๐Ÿ—๏ธ