No Possible Meaning

    TypeScript icon, indicating that this package has built-in type declarations

    0.4.5 • Public • Published

    mo-dev  npm version GitHub license PRs Welcome

    A live reload development server for Motoko smart contracts.

    mo-dev is a flexible command-line tool for speeding up your Motoko development workflow.

    Try Online

    Get started with a full-stack Vite + React + Motoko project directly in your browser:

    Open in Gitpod

    Quick Start

    Make sure that Node.js >= 16.x is installed on your system, and then run the following command:

    npm i -g mo-dev

    View the available command-line options by passing the --help flag:

    mo-dev --help

    Check out the Vite + React + Motoko starter project for an example of how to integrate mo-dev into a modern full-stack webapp.

    Basic Features

    Regenerate type declarations on Motoko file change (--generate or -g):

    mo-dev --generate

    Deploy canisters on Motoko file change (--deploy or -d):

    mo-dev --deploy

    Automatically respond "yes" to reinstall prompts (--yes or -y; may clear canister state):

    mo-dev --deploy -y

    Run an arbitrary command on Motoko file change (--exec or -x):

    mo-dev --exec 'npm run my-reload-script'

    Specify the working directory (--cwd or -c; should contain a dfx.json file):

    mo-dev --cwd path/to/dfx_project

    Advanced Features

    Show additional debug output in the console (--verbose or -v):

    mo-dev -v # more verbose
    mo-dev -vv # extra verbose

    Programmatically start mo-dev using JavaScript:

    import devServer from 'mo-dev';
    // Default settings
    // Custom settings
        directory: '.',
        port: 7700,
        verbosity: 0,
        // ...

    Experimental Features

    Enable the Motoko VM hot module replacement (HMR) server (--hot-reload):

    mo-dev --hot-reload

    Run the HMR server on a specified port (--port or -p; default is 7700):

    mo-dev --hot-reload --port 7700

    Hot module replacement makes it possible to preserve a Motoko actor's state between code changes. This feature is powered by the Motoko VM, a work-in-progress Motoko interpreter written in Rust.

    For most use cases, ic0 is the simplest way to try this feature in a JavaScript environment:

    import { devCanister } from 'ic0';
    const backend = devCanister('backend'); // Use the canister named "backend" from your `dfx.json` config file
    const result ='echo', 123); // Call the `echo` method with 123 as input
    console.log(result); // => 123

    If you are using a different programming language or want lower-level access to this functionality, the following example illustrates how you can interact with a Motoko VM canister using the REST API.

    Let's say that you have a Motoko actor named "backend" in your dfx.json file, and you just added a method named echo to this actor. Calling echo(x) will return the original input value x.

    If you want to immediately run the new echo method without redeploying the canister using dfx deploy, you can call the following API endpoint (served by mo-dev):

    POST http://localhost:7700/call/{dfx_canister_alias}/{method}

    For our specific example:

    POST http://localhost:7700/call/backend/echo

    In the body of the request, provide a JSON object with an array for the args key. For example, {"args":[123]} would pass 123 as the input value.

    If successful, you will receive a corresponding JSON response such as {"value":123}. Otherwise, you will most likely encounter a 400 (invalid request) or 500 (evaluation error) response code from the API.

    mo-dev is early in development. Please feel free to report a bug, ask a question, or request a feature on the project's GitHub issues page.


    npm i mo-dev

    DownloadsWeekly Downloads






    Unpacked Size

    2.35 MB

    Total Files


    Last publish


    • rvanasa