Code organization
Module structure
Organize your modules with clear sections:File organization
Naming conventions
Module names
- Use lowercase with underscores:
my_module - Be descriptive:
token_manager,nft_marketplace - Avoid generic names: Use
sword_gamenotgame
Struct names
- Use PascalCase:
MyStruct,TokenMetadata - Be specific:
AdminCapnotCap - Suffix capability objects:
MintCap,AdminCap,TreasuryCap
Function names
- Use snake_case:
create_token,transfer_admin - Start with verb:
get_value,set_owner,mint_token - Be explicit:
mint_to_addressnotmint
Constants
Security best practices
Authorization checks
Always verify permissions:Input validation
Validate all inputs:Integer overflow protection
Move 2024 has built-in overflow checks, but be explicit:Reentrancy protection
Move’s ownership model prevents most reentrancy, but be careful with shared objects:Performance optimization
Minimize gas costs
Use appropriate data structures
Error handling
Define clear error codes
Use descriptive assertions
Testing best practices
Comprehensive test coverage
Use test constants
Documentation
Document public functions
Document structs
Upgrade patterns
Design for upgradability
Common pitfalls to avoid
- Forgetting to delete UIDs: Always delete UIDs when destroying objects
- Not validating inputs: Check all parameters before processing
- Missing authorization checks: Verify caller has permission
- Inefficient data structures: Choose appropriate collections
- Poor error messages: Use descriptive error codes
- Inadequate testing: Test all code paths and edge cases
- Ignoring gas costs: Optimize for efficiency
- Hardcoding values: Use constants for magic numbers
Next steps
IOTA Move framework
Explore the IOTA framework modules
Testing guide
Learn testing and debugging techniques