The Move Language: The Ultimate Aptos Move Style Guide

Moncayo Labs
2 min readNov 4, 2023

--

Follow these guidelines to deliver industry-level high-impact Aptos/SUI Move code.

Photo by Markus Spiske on Unsplash

Move is still in its infancy and yet it is a Rust child of divorced parents: SUI-Move and Aptos-Move. Hence, it is not straightforward to find answers to coding conventions you might want to follow to upgrade your coding style.

No need to worry, we have collected all the rules for your personal reference down below.

How to structure your Move smart contract:

A typical smart contract structure:

module publisher::module_name_same_as_filename {
// imports
// friend modules this module is interacting with
// Error constants
// Global Constants
// Structs
// Public view functions
// Public Entrypoint functions
// Public functions
// Private/Internal functions
// Optional: unit tests/ test only functions
}

There is no linter for Aptos Move yet, unlike for Python .pylintrc or Solidity solhint . However, we have summarised everything you need to know to write industry-level Aptos Move code down below:

Naming Conventions:

Data Structures

Use snake_case for:

  • Module names
  • Function names
  • Variable names:

Some Aptos developers distinguish variables taken from global storage depending on whether they are a mutable reference (my_var_mut) or an immutable reference (my_var). But this is largely personal preference.

  • Constants (PascalCase for non-error values, e.g., MIN_STAKE)
  • Error codes (start with E, e.g., EZERO_ADDRESS)
  • File Names: Module and Script file names

Use PascalCase for:

  • Custom Type Names (e.g. struct names, MyAmazingDogeCoin)
  • Generic Data Types (usually match module name)

Getters

  • Access structs with the has key ability, either using the variable name var() or get_var() .
  • All view functions (non-state-changing) should have the decorator #[view].

Return Statements

  • Use explicit return statements where possible for clarity.
  • Remember to omit the ; if it’s a return statement.

Spacing

  • Four-space indentation, except for script and address blocks.
  • Maximum line length: 100 characters.

Natspec

Use a Natspec similar to Solidity. For example to add comments to a function signature, use:

/// @notice Deposits APT to the pool. (Describes what this function does.)
/// @param Immutable reference to the signer of the account that wants to deposit to the pool.
/// @param Amount to be deposited by the user.
/// @param Amount of LP tokens transferred to user wallet.
fun deposit_to_pool(arg1: &signer, amount: u64): u64 {
// function body
}

Don’t forget to leave a show of hands if you find this information helpful! 👏

Please follow for more Aptos/SUI content 🙌

Further Reading:

Learn about Structs in Aptos Move.

References:

--

--

Moncayo Labs

Active Supporter of the Aptos Move Movement | Web3 Move Development Tutorials