The MEM SDK is now live

The MEM SDK is now live

January 22, 2024

The first version of the MEM SDK is now live, making it easier than ever to read and write web3 serverless functions in your server-side or front end code.

MEM is on a mission to make it as simple as possible for developers to build that run on web3 rails with web2 UX. We recently launched the MEM Carbon Testnet — a permissionless way to deploy and test functions before going live.

The next most requested feature: the MEM SDK. The SDK is a fully-featured shortcut to build client and server-side applications that deploy, write and read from MEM functions.

Let’s dive into everything you need to know to install and use the SDK.

Installation

npm i mem-sdk

Simple usage example

Import and instantiate MEM in your project:

import { Mem } from "mem-sdk";
const mem : Mem = new Mem();

Send an interaction:

const inputs = { function: "test", inputA: "valueA" };
const txid = await mem.write(FUNCTION_ID, inputs);

A test interaction you can run to hit a counter function with increment:

const FUNCTION_ID = 'M00VT7jvkQuBdHY4BIYuXdQywb39ciYuD59pPh8_aZw'
const inputs = '{ function: "increment" }'
const txid = await mem.write(FUNCTION_ID, inputs);

Read the function’s state to see the counter increment:

const state = await mem.read(FUNCTION_ID);

An example with Next.js

read

Reading function state is possible from anywhere inside a Next.js app.

write

Clone the code these snippets were adapted from to get started! -> The mem-sdk repo has a fully-working Next.js example app using the SDK with a local API in the examples/nextjs folder.

Note: as of v0.0.3, the MEM SDK supports read, write and deploy for mainnet MEM, and provides TypeScript interfaces for MEM function inputs and MEMResponseObject.