Skip to content

MEM Carbon is a testnet network with temporal states storage

License

Notifications You must be signed in to change notification settings

decentldotland/mem-carbon-testnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@decentldotland/mem-carbon-testnet

MEM Carbon is a testnet network with temporary state storage

Build & Run Locally

git pull https://github.com/decentldotland/mem-carbon-testnet.git

npm install && npm run start

Self Hosted Vs Served Endpoint

To keep your application data private, it's recommended to operate a local testnet instance. This will also enhance scalability and testing speed.

Nevertheless, the MEM team provides a publicly accessible endpoint. It's crucial to note that the testnet data is strictly temporary and is purged within a 1-2 day timeframe:

Testnet Methods

Deploy a function

  • POST /deploy
import * as fs from 'fs';
import axios from 'axios';

const TESTNET_ENDPOINT = "https://mem-testnet.xyz/deploy";

async function deploy() {
  try {
    const sourceCode = fs.readFileSync("./func.js", { encoding: "utf8" }); // the src code of the function
    const initState = fs.readFileSync("./state.json", { encoding: "utf8" }); // the JSON initial function state
    
    const body = {
      src: sourceCode,
      state: initState,
    };
    
    const function_id = (await axios.post(TESTNET_ENDPOINT, body))?.data
      ?.function_id;
    console.log(function_id);
    return function_id;
  } catch (error) {
    console.log(error);
  }
}

Send a transaction

  • POST /write
import axios from 'axios';

const TESTNET_ENDPOINT = "https://mem-testnet.xyz/write";

async function write() {
  try {
    const input = '{"function": "something"}'; // example: '{"function": "increment"}'
    const function_id = "your_function_id";

    const body = {
      input,
      function_id,
    };
    const result = (await axios.post(TESTNET_ENDPOINT, body))?.data;
    console.log(result);
    return result;
  } catch (error) {
    console.log(error);
  }
}

Get function state

  • GET /state/:function_id

Get function data (state, source code, and exmContext)

  • GET /data/function/:function_id

Get all testnet deployed functions

  • GET /functions

Local Testing

You can use existing testing code snippets from this repository as follow:

npm run test-deploy

Grab the new function id, update the ./tests/write.js file constant value of FUNCTION_ID, then run the following command

npm run test-write

License

This repository is licensed under the MIT License