There are two options to deploy a function to the MEM Carbon Testnet -- with the CLI or with a custom script.
Option A: Testnet deployment with the CLI
mem deploy --testnet --src ./function.js --init-state ./state.json
Option B: Testnet deployment with a script
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);
}
}