Skip to main content

Sui Move CLI

The Sui Move CLI provides several commands for working with Move source code. A typical usage of sui move is to compile and test the Move code, or to generate a new Move project by using sui move new project_name, which creates the needed directories and the Move.toml file.

Commands

Typing sui move --help into your terminal or console displays the following information on available commands.

Usage: sui move [OPTIONS] <COMMAND>

Commands:
build
coverage Inspect test coverage for this package. A previous test run with the `--coverage` flag must have previously been run
disassemble
new Create a new Move package with name `name` at `path`. If `path` is not provided the package will be created in the directory `name`
prove Run the Move Prover on the package at `path`. If no path is provided defaults to current directory. Use `.. prove .. -- <options>` to pass on options to the
prover
test Run Move unit tests in this package
help Print this message or the help of the given subcommand(s)

Options:
-p, --path <PACKAGE_PATH> Path to a package which the command should be run with respect to
-d, --dev Compile in 'dev' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used if this flag is set. This flag is useful for
development of packages that expose named addresses that are not set to a specific value
--test Compile in 'test' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used along with any code in the 'tests' directory
--doc Generate documentation for packages
--abi Generate ABIs for packages
--install-dir <INSTALL_DIR> Installation directory for compiled artifacts. Defaults to current directory
--force Force recompilation of all packages
--fetch-deps-only Only fetch dependency repos to MOVE_HOME
--skip-fetch-latest-git-deps Skip fetching latest git dependencies
--default-move-flavor <DEFAULT_FLAVOR> Default flavor for move compilation, if not specified in the package's config
--default-move-edition <DEFAULT_EDITION> Default edition for move compilation, if not specified in the package's config
--dependencies-are-root If set, dependency packages are treated as root packages. Notably, this will remove warning suppression in dependency packages
-h, --help Print help
-V, --version Print version

Examples

The following examples demonstrate some of the most often used commands.

Create a new Move project

To create a new Move project that automatically adds the necessary dependencies in a Move.toml file, run sui move new [<PROJECT-NAME>].

$ sui move new smart_contract_test
$ ls -l smart_contract_test
Move.toml
Sources

# display the contents of Move.toml file
$ cat smart_contract_test/Move.toml
[package]
name = "smart_contract_test"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

[addresses]
smart_contract_test = "0x0"

Build a Move project

Use sui move build at the root of your Move project to build the package.

$ sui move build
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING smart_contract_test

Run tests in a Move project

Use sui move test to run the tests in a Move package.

$ sui move test      
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING smart_contract_test
Running Move unit tests
Test result: OK. Total tests: 0; passed: 0; failed: 0

Get test coverage for a module

This example uses the nfts example from sui_programmability folder in the Sui repository.

To get the a summary of the test coverage, you must first run the sui move test --coverage command, and then the sui move coverage summary to get a summary of the test coverage in the nfts Move example project.

$ sui move test --coverage
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING NFTs
warning[W09011]: unused constant
┌─ ./tests/cross_chain_airdrop_tests.move:13:11

13 │ const ETOKEN_ID_CLAIMED: u64 = 0;
│ ^^^^^^^^^^^^^^^^^ The constant 'ETOKEN_ID_CLAIMED' is never used. Consider removing it.

= This warning can be suppressed with '#[allow(unused_const)]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[W09009]: unused struct field
┌─ ./tests/cross_chain_airdrop_tests.move:24:9

24 │ id: UID,
│ ^^ The 'id' field of the 'Object' type is unused

= This warning can be suppressed with '#[allow(unused_field)]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[W09011]: unused constant
┌─ ./sources/geniteam.move:20:11

20 │ const EMonsterCollectionNotOwnedByFarm: u64 = 2;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The constant 'EMonsterCollectionNotOwnedByFarm' is never used. Consider removing it.

= This warning can be suppressed with '#[allow(unused_const)]' applied to the 'module' or module member ('const', 'fun', or 'struct')

warning[W09011]: unused constant
┌─ ./sources/geniteam.move:23:11

23 │ const EInventoryNotOwnedByPlayer: u64 = 3;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^ The constant 'EInventoryNotOwnedByPlayer' is never used. Consider removing it.

= This warning can be suppressed with '#[allow(unused_const)]' applied to the 'module' or module member ('const', 'fun', or 'struct')

Running Move unit tests
[ PASS ] 0x0::chat_tests::test_chat
[ PASS ] 0x0::discount_coupon_tests::test_mint_then_transfer
[ PASS ] 0x0::devnet_nftTests::mint_transfer_update
[ PASS ] 0x0::cross_chain_airdrop_tests::test_claim_airdrop
[ PASS ] 0x0::shared_auction_tests::simple_auction_test
[ PASS ] 0x0::auction_tests::simple_auction_test
[ PASS ] 0x0::cross_chain_airdrop_tests::test_double_claim
Test result: OK. Total tests: 7; passed: 7; failed: 0

$ sui move coverage --summary
+-------------------------+
| Move Coverage Summary |
+-------------------------+
Module 0000000000000000000000000000000000000000000000000000000000000000::auction_lib
>>> % Module coverage: 84.68
Module 0000000000000000000000000000000000000000000000000000000000000000::auction
>>> % Module coverage: 89.09
Module 0000000000000000000000000000000000000000000000000000000000000000::chat
>>> % Module coverage: 60.00
Module 0000000000000000000000000000000000000000000000000000000000000000::erc721_metadata
>>> % Module coverage: 59.09
Module 0000000000000000000000000000000000000000000000000000000000000000::cross_chain_airdrop
>>> % Module coverage: 91.43
Module 0000000000000000000000000000000000000000000000000000000000000000::devnet_nft
>>> % Module coverage: 87.76
Module 0000000000000000000000000000000000000000000000000000000000000000::discount_coupon
>>> % Module coverage: 54.55
Module 0000000000000000000000000000000000000000000000000000000000000000::typed_id
>>> % Module coverage: 0.00
Module 0000000000000000000000000000000000000000000000000000000000000000::geniteam
>>> % Module coverage: 0.00
Module 0000000000000000000000000000000000000000000000000000000000000000::marketplace
>>> % Module coverage: 0.00
Module 0000000000000000000000000000000000000000000000000000000000000000::num
>>> % Module coverage: 0.00
Module 0000000000000000000000000000000000000000000000000000000000000000::shared_auction
>>> % Module coverage: 82.86
+-------------------------+
| % Move Coverage: 40.36 |
+-------------------------+

Help

Each command has its own help section. For example sui move build –help displays the following prompt:

$ sui move build --help    
Usage: sui move build [OPTIONS]

Options:
-p, --path <PACKAGE_PATH> Path to a package which the command should be run with respect to
--with-unpublished-dependencies Include the contents of packages in dependencies that haven't been published (only relevant when dumping bytecode as base64)
-d, --dev Compile in 'dev' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used if this flag is set. This flag is useful for development
of packages that expose named addresses that are not set to a specific value
--dump-bytecode-as-base64 Whether we are printing in base64
--generate-struct-layouts If true, generate struct layout schemas for all struct types passed into `entry` functions declared by modules in this package These layout
schemas can be consumed by clients (e.g., the TypeScript SDK) to enable serialization/deserialization of transaction arguments and events
--test Compile in 'test' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used along with any code in the 'tests' directory
--doc Generate documentation for packages
--lint If `true`, enable linters
--abi Generate ABIs for packages
--install-dir <INSTALL_DIR> Installation directory for compiled artifacts. Defaults to current directory
--force Force recompilation of all packages
--fetch-deps-only Only fetch dependency repos to MOVE_HOME
--skip-fetch-latest-git-deps Skip fetching latest git dependencies
--default-move-flavor <DEFAULT_FLAVOR> Default flavor for move compilation, if not specified in the package's config
--default-move-edition <DEFAULT_EDITION> Default edition for move compilation, if not specified in the package's config
--dependencies-are-root If set, dependency packages are treated as root packages. Notably, this will remove warning suppression in dependency packages
-h, --help Print help