Skip to content

Quickstart

The API documentation for the lotus-script crate can be found here.

We recommend using Visual Studio Code with rust-analyzer.

To create a new project, you need to have Rust installed. If you don’t have it installed, you can install it from rustup.rs. After installing Rust, you need to install the wasm32 target. You can do this by running the following command:

Terminal window
rustup target add wasm32-unknown-unknown

lotus-sc is a CLI tool that helps you develop scripts for LOTUS. You can install it by running the following command:

Terminal window
cargo install lotus-sc

To create a new project, run the following command and replace <project-name> with the name of your project:

Terminal window
cargo new --lib <project-name>

You need to add the following to your Cargo.toml file:

[lib]
crate-type = ["cdylib"]

To add the lotus-script dependency, you can run the following command:

Terminal window
cargo add lotus-script

You can copy the following minimal script to your src/lib.rs file:

use lotus_script::prelude::*;
#[derive(Default)]
pub struct MyScript {}
script!(MyScript);
impl Script for MyScript {
fn init(&mut self) {}
fn tick(&mut self) {}
}

To deploy the script, you first need to create a script.toml file next to your Cargo.toml file. In this file, you need to add the following:

[deploy]
user-id = 1234
sub-id = 5678

Replace the ids with the corresponding ids for the object the script should be attached to. See the script.toml reference for more information.

To deploy the script, you can run the following command:

Terminal window
lotus-sc deploy

To create a release build, you can run the following command:

Terminal window
lotus-sc build --profile release

To debug your script in LOTUS, press F4 to open the debug menu. In the debug menu, activate script-debug. This will open a new window where you can see some information about the script and the script state.

To close this window, deactivate script-debug in the debug menu.

Proper WASM debugging is not yet implemented.