Why Move?
Move was designed from the ground up to address common security issues in smart contracts:Resource Safety
Assets cannot be copied or accidentally destroyed
Type Safety
Strong typing prevents many classes of bugs
Formal Verification
Code can be mathematically proven correct
Modular Design
Reusable modules and clear dependencies
Move on Sui
Sui extends Move with object-centric features:Objects vs Resources
While traditional Move uses “resources”, Sui uses “objects” with unique IDs:Every Sui object must have
id: UID as its first field. The UID type ensures global uniqueness.Basic Syntax
Module Structure
Primitive Types
Move supports several primitive types:- Integers
- Booleans
- Addresses
- Vectors
Variables and Mutability
References
Move uses explicit references:Immutable Reference
&T - Read-only access to valueMutable Reference
&mut T - Can modify the valueControl Flow
Conditionals
Loops
Functions
Function Visibility
Function Parameters and Return Values
Structs
Defining Structs
Creating and Using Structs
Generics
Move supports generic programming:Common Patterns
The Witness Pattern
What is a Witness?
What is a Witness?
A witness is a struct that proves you own the module it’s defined in. The
init function receives an instance of the witness exactly once, at module publication. This ensures certain operations (like creating a currency) can only happen once.Capability Pattern
Error Handling
Testing
Best Practices
Use descriptive names
Use descriptive names
Validate inputs
Validate inputs
Use constants for magic numbers
Use constants for magic numbers
Document public functions
Document public functions
Related Topics
Move Modules
Learn about module organization
Move Functions
Deep dive into functions
Move Abilities
Understand type abilities