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
  1. Examples

Pastebin clone

Build a basic CRUD dApp

PreviousKey-Value Storage (KVS)NextQuery onchain data

Last updated 1 year ago

A simple pastebin clone should allow anonymous users to easily publish and share plain text publicly, and browse text uploaded by others.

Building this on MEM has several advantages:

  • No need to deploy and manage API servers

  • Application state and all content is stored for free on Arweave forever

  • Web3-ready - plug in authentication, encryption, token-gating and more

Pastebin MEM function

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

  if (input.function === "save") {
    const { username, data } = input;
    ContractAssert(
      username.trim().length && data.trim().length,
      "ERROR_INVALID_INPUT",
    );
    ContractAssert(typeof username === "string" && typeof data === "string");
    state.logs.push({ username, data });
    return { state };
  }
}
state.json
{ "logs": [] }

UI: writing a paste

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

UI: reading pastes

Optional features supported by MEM

  • Private pastes using encryption (coming soon)

  • Self-destruct using encryption (coming soon)

Add the option to using a wallet

🧩
View this example on GitHub
https://api.mem.tech/api/state/jBA874p2FtnLhDONzcphPgOp9Nzf5ly620BWQWf9rUI
authenticate