β οΈ EDUCATIONAL & DEMONSTRATION PURPOSES ONLY: These samples are created exclusively for learning and demonstration purposes. They are NOT production-ready and should never be used in live applications without significant modifications, proper error handling, and comprehensive security audits.
A collection of educational Sui Move smart contracts demonstrating core concepts and patterns unique to the Sui blockchain ecosystem. Perfect for developers transitioning from other Move implementations (like Aptos) or those new to Sui development.
This repository contains various Move modules showcasing different Sui concepts:
- Multi-module interactions - Cross-module communication and object lifecycle management
- Access control patterns - Object-based permissions and capability systems
- Data structure operations - Vector handling and basic object manipulation
- And more... - Additional samples will be added over time
Each module comes with comprehensive tests demonstrating usage patterns and edge cases for educational purposes.
Coming from Aptos Move? Here are the major differences you'll encounter in these samples:
// β Aptos: Resources stored in global storage
move_to(&signer, MyResource { ... });
// β
Sui: Objects with unique identifiers transferred explicitly
transfer::transfer(MyObject { id: object::new(ctx), ... }, recipient);// β Aptos: Access signer from global context
fun my_function() acquires MyResource {
let signer_addr = signer::address_of(&signer);
}
// β
Sui: Context passed as parameter
fun my_function(ctx: &mut TxContext) {
let sender = tx_context::sender(ctx);
}| Capability | key |
store |
copy |
drop |
key + store |
key + drop |
store + copy |
All Four |
|---|---|---|---|---|---|---|---|---|
| Can be a top-level object | β | β | β | β | β | β | β | β |
| Can be stored inside other objects | β | β | β | β | β | β | β | β |
| Can be copied/duplicated | β | β | β | β | β | β | β | β |
| Auto-destroyed when unused | β | β | β | β | β | β | β | β |
Can use transfer::transfer() |
β * | β | β | β | β * | β * | β | β * |
Can use transfer::public_transfer() |
β | β | β | β | β | β | β | β |
| Can be transferred by external modules | β | β | β | β | β | β | β | β |
| Must be explicitly handled | β | β | β | β | β | β | β | β |
| Can have global storage | β | β | β | β | β | β | β | β |
| Requires UID field | β | β | β | β | β | β | β | β |
- β = Yes/Allowed
- β = No/Not Allowed
- * = Only by the defining module
public struct MyStruct has key {
id: UID,
// ... other fields
}- Can be stored as top-level object: β Yes
- Can be copied: β No (UID prevents copying)
- Storable in objects: β No
- Can be transferred by external modules: β No (only defining module)
- Can use public_transfer: β No
- Auto-destroyed: β No (must be explicitly handled)
public struct MyStruct has store {
// ... fields (no UID)
}- Can be stored as top-level object: β No
- Can be copied: β No (unless all fields have copy)
- Storable in objects: β Yes
- Can be transferred by external modules: β No (not a top-level object)
- Can use public_transfer: β No (needs key)
- Auto-destroyed: β No (must be explicitly handled)
public struct MyStruct has copy {
value: u64, // All fields must have copy
}- Can be stored as top-level object: β No
- Can be copied: β Yes
- Storable in objects: β Yes (copy implies store-like behavior)
- Can be transferred by external modules: β No (not a top-level object)
- Can use public_transfer: β No (needs key)
- Auto-destroyed: β No (unless also has drop)
public struct MyStruct has drop {
// ... fields (all must have drop)
}- Can be stored as top-level object: β No
- Can be copied: β No
- Storable in objects: β Yes (drop implies store-like behavior)
- Can be transferred by external modules: β No (not a top-level object)
- Can use public_transfer: β No (needs key)
- Auto-destroyed: β Yes
public struct MyStruct has key, store {
id: UID,
// ... other fields
}- Can be stored as top-level object: β Yes
- Can be copied: β No (UID prevents copying)
- Storable in objects: β Yes
- Can be transferred by external modules: β Yes (via public_transfer)
- Can use public_transfer: β Yes
- Auto-destroyed: β No (must be explicitly handled)
// β Aptos: Global borrowing from storage
fun read_data(): String acquires MyResource {
let resource = borrow_global<MyResource>(@user);
resource.data
}
fun modify_data() acquires MyResource {
let resource = borrow_global_mut<MyResource>(@user);
resource.data = string::utf8(b"new value");
}
// β
Sui: Objects passed as function parameters
fun read_data(obj: &MyObject): String {
obj.data // Read-only access via reference
}
fun modify_data(obj: &mut MyObject) {
obj.data = string::utf8(b"new value"); // Mutable access via mutable reference
}
fun transfer_object(obj: MyObject, recipient: address) {
transfer::transfer(obj, recipient); // Transfer ownership (consumes object)
}Key Differences:
- Aptos: Uses
borrow_globalandborrow_global_mutto access resources from global storage - Sui: Objects are explicitly passed as function parameters:
*param*: &MyObject- Read-only access (immutable reference)*param*: &mut MyObject- Mutable access for editingmut *param*: MyObject- Mutable access for editing(accessible with &mut) and object operations(transfer, delete, ...)*param*: MyObject- Object operations only(transfer, delete, ...)
- Aptos: Resources live in account storage, accessed via global operators
- Sui: Objects are explicitly transferred between addresses or made shared
sui_samples/
βββ sources/ # Move modules with educational examples
β βββ *.move # Various Sui Move samples
βββ tests/ # Comprehensive test suites
β βββ *_tests.move # Test files for each module
βββ Move.toml # Package configuration
βββ Move.lock # Dependency lock file
- Sui CLI installed
- Basic understanding of Move language concepts
# Build the project
sui move build
# Run all tests
sui move test
# Run specific test module (example)
sui move test --filter <module_name>_tests# Deploy to Sui testnet
sui client publish --gas-budget 20000000Found an issue or want to improve the educational content? PRs are welcome! Please ensure:
- Code remains educational and well-commented for demonstration purposes
- Tests cover new functionality with clear educational examples
- Documentation is updated accordingly
- All contributions maintain the educational/demonstration focus
Happy Learning! π
Remember: All samples in this repository are for educational and demonstration purposes only. They prioritize clarity and learning over production optimization.