Loading...
Loading...
Use when writing Move code on Sui to ensure 2024 edition syntax is used. Applies to method calls, string literals, vector operations, option handling, loops, and struct unpacking. Use whenever writing Move code to avoid legacy function-call syntax patterns.
npx skill4agent add mystenlabs/skills modern-move-syntaxMCP tool: When available in your environment, also query the Sui documentation MCP server () for up-to-date answers. Use it for verification and for details not covered by these reference files.https://sui.mcp.kapa.ai
// WRONG — legacy function-call syntax
let value = coin::value(&payment);
let balance = coin::into_balance(payment);
balance::join(&mut pool.reserve, balance);
let coin = coin::from_balance(balance::split(&mut pool.reserve, amount), ctx);
// CORRECT — method syntax
let value = payment.value();
let balance = payment.into_balance();
pool.reserve.join(balance);
let coin = coin::from_balance(pool.reserve.split(amount), ctx);
// BEST — chained method calls
let balance = payment.split(amount, ctx).into_balance();// WRONG
tx_context::sender(ctx)
// CORRECT
ctx.sender()// WRONG
object::delete(id);
// CORRECT
id.delete();std::string::utf8()// WRONG
use std::string;
let s = string::utf8(b"hello");
// ALSO WRONG — unnecessary conversion
let s = b"hello".to_string();
// CORRECT — direct string literals (2024 edition)
let s = "hello"; // String (UTF-8)
let ascii = "hello"; // also works for ASCII strings
let s = b"hello".to_string(); // still valid but prefer quoted form
let ascii = b"hello".to_ascii_string(); // explicit ASCII when needed// WRONG
let mut v = vector::empty();
vector::push_back(&mut v, 10);
let first = vector::borrow(&v, 0);
let len = vector::length(&v);
// CORRECT
let mut v = vector[10];
let first = &v[0];
let len = v.length();
v.push_back(20);// WRONG
let val = vec_map::get(&map, &key);
// CORRECT
let val = &map[&key];is_somedestroy_some// WRONG
if (opt.is_some()) {
let value = opt.destroy_some();
call_function(value);
};
// CORRECT
opt.do!(|value| call_function(value));// WRONG
let value = if (opt.is_some()) { opt.destroy_some() } else { default };
// CORRECT
let value = opt.destroy_or!(default);// WRONG — manual counter loop
let mut i = 0;
while (i < 32) {
do_action();
i = i + 1;
};
// CORRECT — do! macro
32u8.do!(|_| do_action());// Iterate over a numeric range
let mut sum = 0;
10u64.do!(|i| { sum = sum + i }); // i goes 0..9
// With index for more complex logic
let mut results = vector[];
5u64.do!(|i| results.push_back(i * i)); // [0, 1, 4, 9, 16]// WRONG
let mut i = 0;
while (i < vec.length()) {
call_function(&vec[i]);
i = i + 1;
};
// CORRECT
vec.do_ref!(|e| call_function(e));// WRONG
let mut v = vector[];
let mut i = 0;
while (i < 32) { v.push_back(i); i = i + 1; };
// CORRECT
let v = vector::tabulate!(32, |i| i);// fold
let sum = source.fold!(0, |acc, v| { acc + v });
// filter (requires T: drop)
let filtered = source.filter!(|e| e > 10);....// WRONG
let MyStruct { id, field_1: _, field_2: _, field_3: _ } = value;
// CORRECT
let MyStruct { id, .. } = value;// WRONG — deprecated, renamed
dynamic_field::exists_(&id, key)
// CORRECT
dynamic_field::exists(&id, key)// Named fields (traditional)
public struct Wrapper has copy, drop, store { value: u64 }
// Positional fields (2024 edition)
public struct Wrapper(u64) has copy, drop, store;
// Access by position
let w = Wrapper(42);
let val = w.0;naming-conventionspublicpublic// Fields visible only within this module
struct Config has key { id: UID, admin: address }
// Fields visible to other modules
public struct Token has key, store { id: UID, value: u64 }publicpublic enum Color {
Red,
Green,
Blue,
Custom(u8, u8, u8),
}
public fun is_red(c: &Color): bool {
match (c) {
Color::Red => true,
_ => false,
}
}matchkey| Legacy Pattern | Modern 2024 Syntax |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |