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
  • Writing MEM functions
  • Testing in the IDE
  • Optional: adding authentication methods
  • Deploying with the CLI
  • Integrating MEM with your front end
  • Get extra help
  1. Quickstart

Quickstart guide

0 to 1 as fast as possible

PreviousUse-case examplesNextFunction syntax

Last updated 1 year ago

The recommended path to developing an application with MEM is:

  1. in JavaScript, leaning on examples and the syntax spec for guidance

  2. or locally

  3. to the

  4. with your UI using API calls

  5. Get your function whitelisted for mainnet

Writing MEM functions

The fastest and best-documented way to write MEM functions is in JavaScript. The and has plenty you can test and fork for common backend patterns.

Here's the function.js for a counter:

export async function handle(state, action) {
  const input = action.input;

  if (input.function === "increment") {
    state.count += 1;
    return { state };
  }
  if (input.function === "decrement") {
    state.count -= 1;
    return { state };
  }
}
{
  "count": 0,
  "publicFunctions": {
    "increment": [],
    "decrement": []
  }
}

Testing in the IDE

Use the + button for a new blank slate or to choose one of the examples.

Optional: adding authentication methods

By default, functions in MEM are fully public and anonymous.

Deploying with the CLI

Install the CLI:

npm i -g mem-cli-js

Deploy a function:

mem deploy --testnet --src function.js --init-state state.json

Copy the function ID from the CLI once deployed.

Integrating MEM with your front end

async function writeFunction() {
  try {
    const inputs = [
      {
        input: {
          function: "save",
          username: "anon",
          data: "hello world",
        },
      },
    ];
    const functionId = "jBA874p2FtnLhDONzcphPgOp9Nzf5ly620BWQWf9rUI";

    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);
  }
}

Get extra help

Here's its respective state.json, which holds global variables and the :

Counter ( | )

Guestbook ( | )

Name service ()

The is a web playground for you to write and test functions without needing to deploy them live.

Each function consists of a function.js and a state.json -- the state holds global variables and the function , which populates the interaction panel below the function code editor.

The is powered by the package, which you can also run locally.

Developers can add web3 via in-function calls to authentication . These molecules accept a wallet address and a signature and return true/false based on whether the signature can be verifiably attributed to the caller.

.

When you're happy with how the function runs in the IDE, you can use the to deploy it to the .

Mainnet functions must be whitelisted before they will accept interactions. This is a temporary safeguard while MEM is in beta. Use to submit a whitelist request. We recommend developers use the MEM Carbon Testnet by passing the --testnet flag to the CLI.

MEM functions can be and from a front end using the .

Reach out to us on and , or to discuss.

⚡
Write a MEM function
Test in the IDE
Deploy using the CLI
MEM Carbon testnet
Integrate MEM
IDE
examples repo
ABI
code
IDE
code
IDE
code
All examples
MEM IDE
ABI
IDE
mem-testnet
authentication
molecules
Click here for an example of EVM authentication
CLI
MEM Carbon testnet
this form
read
written to
MEM API
Telegram
Discord
book a call