Loading...
Loading...
Compare original and translation side by side
MCP 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
MCP工具: 如果你的环境中提供了该工具,也可以查询Sui文档MCP服务器()获取最新答案。可用于验证以及获取这些参考文件未涵盖的细节。https://sui.mcp.kapa.ai
public entrypublic 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) { }entrypublicpublicentrypublic 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());
}ctx.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_liquidityswapborrowdropsui 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,
) { }AdminCapctx: &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,
) { }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 |
| 模式 | 规则 |
|---|---|
| 可见性 | |
| 返回值 | 公共函数返回对象。不要在内部向发送者转移对象。 |
| Entry包装函数 | 单独的 |
| 参数顺序 | 对象 → 能力 → 原始值 → Clock → TxContext |