Cover photo

Sui Move Lecture #2 Project Architecture

Following the introduction of lecture #1, let’s dive into the details of Sui Move language.

Sui Project Architecture

Move VS Solidity

Move is a programming language designed specifically for the Libra blockchain, whereas Solidity is primarily used for developing smart contracts on the Ethereum blockchain. While both languages serve a similar purpose, their underlying blockchain platforms have different architectures and designs, which may impact the way developers use the languages.

Move and Solidity have different approaches to implementing smart contract functionality. Move uses resource types, which are special types of values that can only be owned by one account at a time. Solidity, on the other hand, uses an account-based model where each account has an associated balance and can perform actions on behalf of that account. This fundamental difference impacts the way smart contracts are designed and implemented in each language.

Sui Modules and Packages

  • A Sui module is a set of functions and types packed together which the developer publishes under a specific address

  • The Sui standard library is published under the 0x2 address, while user-deployed modules are published under a pseudorandom address assigned by the Sui Move VM

  • Module starts with the module keyword, which is followed by module name and curly braces - inside them module contents are placed:

    Example from explorer:

    https://suiexplorer.com/object/0x2eeaab737b37137b94bfa8f841f92e36a153641119da3456dec1926b9960d9be?module=pool_script

    module hello_world {
        // module contents
    }
    
  • Published modules are immutable objects in Sui; an immutable object is an object that can never be mutated, transferred or deleted. Because of this immutability, the object is not owned by anyone, and hence it can be used by anyone

  • A Move package is just a collection of modules with a manifest file called Move.toml. Example:

Initializing a Sui Move Package

Use the following Sui CLI command to start a skeleton Sui package:

sui move new <PACKAGE NAME>

For our example in this unit, we will start a Hello World project:

sui move new hello_world

This creates:

  • the project root folder hello_world

  • the Move.toml manifest file

  • the sources subfolder which will contain Sui Move smart contract source files

post image

Move.toml Manifest Structure

Move.toml is the manifest file of a package and is automatically generated in the project root folder.

Move.toml consists of three sections:

  • [package] Defines the name and version number of the package

  • [dependencies] Defines other packages that this package depends on, such as the Sui standard library; other third-party dependencies should be added here as well

  • [addresses] Defines aliases for addresses in the package source code

    Sample Move.toml File

    This is the Move.toml generated by the Sui CLI with the package name hello_world:

[package]
name = "hello_world"
version = "0.0.1"

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

[addresses]
hello_world =  "0x0"
sui =  "0000000000000000000000000000000000000000000000000000000000000002"

We see that the Sui standard library dependency here is defined using a GitHub repo, but it can also point to a local binary using its relative or absolute file path, for example:

[dependencies]
Sui = { local = "../sui/crates/sui-framework/packages/sui-framework" }

Sui Module and Package Naming

Sui Move module and package naming convention uses snake casing, i.e. this_is_snake_casing.

A Sui module name uses the Rust path separator :: to divide the package name and the module name, examples:

unit_one::hello_world - hello_world module in unit_one package

capy::capy - capy module in capy package

For more information on Move naming conventions, please check the style section of the Move book.

Examples from explorer:

post image

Reference:

https://github.com/sui-foundation/sui-move-intro-course/blob/main/unit-one/lessons/2_sui_project_structure.md