Loading...
Loading...
Use when writing Move functions on Sui, especially public APIs. Applies to function visibility (public vs entry), parameter ordering, and return patterns. Use whenever designing function signatures or deciding whether functions should transfer objects or return them.
npx skill4agent add mystenlabs/skills composable-move-functionsMCP 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
public entrypublicentrypublic entry// WRONG — public entry is redundant and limits composability
public entry fun do_something() { }
// CORRECT — public for composable functions that return values
public fun mint(ctx: &mut TxContext): NFT { }
// CORRECT — entry for intentionally non-composable endpoints
entry fun mint_and_keep(ctx: &mut TxContext) { }entrypublicctx.sender()// WRONG — couples minting with transfer, can't compose
public fun mint_and_transfer(ctx: &mut TxContext) {
let nft = NFT { id: object::new(ctx) };
transfer::transfer(nft, ctx.sender());
}
// CORRECT — returns the object, caller decides
public fun mint(ctx: &mut TxContext): NFT {
NFT { id: object::new(ctx) }
}
// If you need a convenience entry point, add a separate entry wrapper:
entry fun mint_and_keep(ctx: &mut TxContext) {
let nft = mint(ctx);
transfer::transfer(nft, ctx.sender());
}dropsui client callUnusedValueWithoutDropsui client ptb--assign--transfer-objectssui client ptb \
--move-call @pkg::module::create_thing --assign thing \
--transfer-objects "[thing]" @senderentryadd_liquidityremove_liquidityswapborrowAdminCapctx: &mut TxContext// WRONG — cap before object, primitives mixed in
public fun authorize_action(
cap: &AdminCap,
value: u8,
app: &mut App,
ctx: &mut TxContext,
) { }
// CORRECT — object first, cap second, primitives third, ctx last
public fun authorize_action(
app: &mut App,
cap: &AdminCap,
value: u8,
ctx: &mut TxContext,
) { }Clockctxpublic fun timed_action(
app: &mut App,
cap: &AppCap,
value: u8,
clock: &Clock,
ctx: &mut TxContext,
) { }| Pattern | Rule |
|---|---|
| Visibility | |
| Returns | Public functions return objects. Don't transfer to sender internally. |
| Entry wrappers | Separate |
| Param order | Object → Capability → Primitives → Clock → TxContext |