@decentldotland/mem-sdk
JS SDK for MEM Serverless Functions
Build size
dist/index.cjs.js
1.52 kB │ gzip: 0.69 kB
dist/index.umd.js
1.72 kB │ gzip: 0.80 kB
dist/index.es.js
1.95 kB │ gzip: 0.74 kB
Build Locally
git clone https://github.com/decentldotland/mem-sdk.git
cd mem-sdk
npm install && npm run build
Install
npm install mem-sdk
Usage Guide
Import MEM SDK
React, and other frameworks (also check out React Version):
import Mem from "mem-sdk";
const mem : Mem = new Mem();
Node:
const { Mem } = require("mem-sdk");
const mem: Mem = new Mem();
Retrieve a function state
const FUNCTION_ID = "...";
const state = await mem.read(FUNCTION_ID);
Send an interaction (only works on server-side)
const FUNCTION_ID = "...";
const inputs = { function: "test", inputA: "valueA" };
const txid = await mem.write(FUNCTION_ID, inputs);
Deploy a function
const SRC = `export async function handle(state, action) {
const input = action.input;
if (input.function === "save") {
const { username, bio } = input;
ContractAssert(username.trim().length, "ERROR_INVALID_INPUT");
ContractAssert(typeof username === "string" && typeof bio === "string");
state.logs.push ({ username, bio });
return { state }
}
}`;
const INIT_STATE = '{"logs": []}';
const id = await mem.deploy(SRC, INIT_STATE);
License
This repositoy is licensed under the MIT License