ptbs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSui Programmable Transaction Blocks (PTBs)
Sui Programmable Transaction Blocks (PTBs)
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
A PTB is one Sui transaction that batches up to 1,024 commands — Move calls, coin splits/merges, object transfers, vector construction, package publish/upgrade — executed in order, atomically (one command fails ⇒ whole block fails), sharing inputs and chaining results. PTBs are the only way to execute transactions on Sui; there is no "single call" mode.
This skill routes to focused reference files. Load only the ones relevant to the current task.
All patterns in this skill are derived from:
- https://docs.sui.io/concepts/transactions/prog-txn-blocks
- https://docs.sui.io/develop/transactions/ptbs/building-ptb
- https://docs.sui.io/references/ptb-commands
- https://sdk.mystenlabs.com/typescript/transaction-building/basics
- https://docs.sui.io/references/cli/client (CLI )
sui client ptb
If unsure about any API, method signature, or error message, fetch the relevant page before answering. Do not guess or extrapolate from Ethereum, Solana, or other chains — PTBs have no direct analog.
MCP工具提示: 当你的环境支持时,也可查询Sui文档MCP服务器()获取最新答案。可用于验证信息以及获取本参考文件未涵盖的细节。https://sui.mcp.kapa.ai
PTB是一种Sui交易,可批量处理最多1024条命令——包括Move调用、代币拆分/合并、对象转移、向量构建、包发布/升级——按顺序执行且具有原子性(任一命令失败则整个交易块失败),支持输入共享和结果链式调用。PTBs是在Sui上执行交易的唯一方式;不存在“单次调用”模式。
本技能会引导至针对性的参考文件。仅加载与当前任务相关的文件即可。
本技能中的所有模式均源自:
- https://docs.sui.io/concepts/transactions/prog-txn-blocks
- https://docs.sui.io/develop/transactions/ptbs/building-ptb
- https://docs.sui.io/references/ptb-commands
- https://sdk.mystenlabs.com/typescript/transaction-building/basics
- https://docs.sui.io/references/cli/client(CLI )
sui client ptb
若对任何API、方法签名或错误信息不确定,请先获取相关页面内容再作答。请勿基于Ethereum、Solana或其他链的经验猜测或推断——PTBs没有直接的类似概念。
Reference files
参考文件
fundamentals — PTB data model
fundamentals — PTB数据模型
Path:
Load when: explaining what a PTB is, talking about , , , , owned vs shared vs immutable vs receiving object references, pure-input BCS rules, command chaining semantics, or execution ordering / atomicity.
Covers: PTB structure, (CallArg) and variants, pure input types, enum, result chaining, execution semantics (borrow rules, move/copy, hot potato cliques, end-of-tx constraints), protocol limits.
fundamentals.mdInputArgumentNestedResultGasCoinInputObjectArgArgument路径:
加载场景: 解释PTB是什么、讨论、、、、自有对象/共享对象/不可变对象/接收对象引用的区别、纯输入BCS规则、命令链式调用语义,或执行顺序/原子性相关内容。
涵盖内容: PTB结构、(CallArg)和变体、纯输入类型、枚举、结果链式调用、执行语义(借用规则、移动/复制、热土豆 clique、交易结束约束)、协议限制。
fundamentals.mdInputArgumentNestedResultGasCoinInputObjectArgArgumentcommands — Command reference
commands — 命令参考
Path:
Load when: writing or reviewing any specific command — , , , , , , — or debugging argument-type mismatches and return-value shape.
Covers: signature, argument rules, return shape, and common pitfalls for each of the seven commands.
commands.mdMoveCallSplitCoinsMergeCoinsTransferObjectsMakeMoveVecPublishUpgrade路径:
加载场景: 编写或评审任何特定命令——、、、、、、——或调试参数类型不匹配和返回值格式问题。
涵盖内容: 七个命令各自的签名、参数规则、返回格式及常见陷阱。
commands.mdMoveCallSplitCoinsMergeCoinsTransferObjectsMakeMoveVecPublishUpgradebuilding — TypeScript SDK Transaction
class
Transactionbuilding — TypeScript SDK Transaction
类
TransactionPath:
Load when: writing TS/JS code that constructs a PTB with , configuring gas, building for wallets, serializing across services, or sending PTBs between app ↔ wallet ↔ sponsor.
Covers: API (, , , , , , , , , , ), helpers, result destructuring, , / , sponsored transaction flow, signing & executing.
building.md@mysten/sui/transactionsTransactiontx.moveCalltx.splitCoinstx.mergeCoinstx.transferObjectstx.makeMoveVectx.publishtx.upgradetx.objecttx.puretx.gastx.setSender/setGasPrice/setGasBudget/setGasPayment/setGasOwnerInputs.*Refbuild({ onlyTransactionKind: true })Transaction.fromfromKind路径:
加载场景: 使用编写TS/JS代码构建PTB、配置Gas、为钱包构建交易、跨服务序列化,或在应用↔钱包↔赞助方之间传递PTBs。
涵盖内容: API(、、、、、、、、、、)、辅助工具、结果解构、、 / 、赞助交易流程、签名与执行。
building.md@mysten/sui/transactionsTransactiontx.moveCalltx.splitCoinstx.mergeCoinstx.transferObjectstx.makeMoveVectx.publishtx.upgradetx.objecttx.puretx.gastx.setSender/setGasPrice/setGasBudget/setGasPayment/setGasOwnerInputs.*Refbuild({ onlyTransactionKind: true })Transaction.fromfromKindcli — Building PTBs from the CLI
cli — 通过CLI构建PTBs
Path:
Load when: constructing PTBs from the command line using , scripting transactions without TypeScript, merging coins from the CLI, or teaching CLI-based workflows.
Covers: syntax, chaining commands, common CLI PTB patterns (transfers, coin merges, Move calls), gas budget, previewing before execution.
cli.mdsui client ptbsui client ptb路径:
加载场景: 使用从命令行构建PTBs、无需TypeScript编写交易脚本、通过CLI合并代币,或教授基于CLI的工作流。
涵盖内容: 语法、命令链式调用、常见CLI PTB模式(转移、代币合并、Move调用)、Gas预算、执行前预览。
cli.mdsui client ptbsui client ptbtroubleshooting — Common errors
troubleshooting — 常见错误
Path:
Load when: diagnosing a failing PTB — any , , , , , shared-object congestion, or cryptic "transaction failed" output.
Covers: each error category with the Move/PTB-level cause and concrete fix.
troubleshooting.mdServerErrorUnusedValueWithoutDropVMVerificationOrDeserializationErrorNo valid gas coinsInsufficientGas路径:
加载场景: 诊断执行失败的PTB——包括任何、、、、、共享对象拥堵,或模糊的“交易失败”输出。
涵盖内容: 每个错误类别对应的Move/PTB层面原因及具体修复方案。
troubleshooting.mdServerErrorUnusedValueWithoutDropVMVerificationOrDeserializationErrorNo valid gas coinsInsufficientGasRouting guide
路由指南
| Task | Load |
|---|---|
| "What is a PTB?" / conceptual explanation | fundamentals |
| Writing a new PTB in TypeScript | building + commands |
| Writing a new PTB from the CLI | cli + commands |
| Reviewing a PTB for correctness | fundamentals + commands + building |
| A specific command fails type checking | commands |
| Sponsored / gasless transactions | building |
| Debugging a failing PTB | troubleshooting + (fundamentals if execution-semantics related) |
| Publishing or upgrading a package in a PTB | commands |
| Building PTB bytes across services (app/wallet/sponsor) | building |
| Merging coins or simple operations from the CLI | cli |
| Full code review | all reference files |
| 任务 | 加载文件 |
|---|---|
| “什么是PTB?” / 概念性解释 | fundamentals |
| 使用TypeScript编写新的PTB | building + commands |
| 通过CLI编写新的PTB | cli + commands |
| 评审PTB的正确性 | fundamentals + commands + building |
| 特定命令类型检查失败 | commands |
| 赞助/无Gas交易 | building |
| 调试执行失败的PTB | troubleshooting +(若涉及执行语义则加fundamentals) |
| 在PTB中发布或升级包 | commands |
| 跨服务(应用/钱包/赞助方)构建PTB字节 | building |
| 通过CLI合并代币或执行简单操作 | cli |
| 完整代码评审 | 所有参考文件 |
Skill Content
技能内容
Key concepts
核心概念
- A PTB is the transaction. Every Sui transaction is a PTB — even a single is a one-command PTB. There is no non-PTB execution path.
moveCall - Inputs vs commands. are values fed in from outside (objects and BCS-encoded "pure" bytes).
inputsoperate on those inputs and on each other's results. Commands reference values via thecommandsenum:Argument,Input(i),GasCoin,Result(i).NestedResult(cmd, result) - Chaining. Each command produces an array of results. The next command can consume any result (by or, when a command has exactly one return,
NestedResult(cmd, idx)). The TS SDK surfaces this as destructurable values:Result(cmd).const [coin] = tx.splitCoins(tx.gas, [tx.pure.u64(100)]); - Atomicity. Commands execute in order. Any failure reverts the entire block; no partial effects.
- End-of-tx constraints. Every non-value produced during execution must be consumed (transferred, destroyed, or fed into another command). Shared objects have exactly two legal endings: re-share or delete — they cannot be transferred or frozen. Gas coin is returned to its owner with unused gas refunded.
drop
- PTB即为交易:每一笔Sui交易都是一个PTB——即使是单次也是一个单命令PTB。不存在非PTB的执行路径。
moveCall - 输入 vs 命令:是从外部传入的值(对象和BCS编码的“纯”字节)。
inputs基于这些输入和彼此的结果进行操作。命令通过commands枚举引用值:Argument、Input(i)、GasCoin、Result(i)。NestedResult(cmd, result) - 链式调用:每个命令会生成一个结果数组。下一个命令可以消费任意结果(通过,或当命令仅有一个返回值时使用
NestedResult(cmd, idx))。TypeScript SDK将其体现为可解构的值:Result(cmd)。const [coin] = tx.splitCoins(tx.gas, [tx.pure.u64(100)]); - 原子性:命令按顺序执行。任何失败都会回滚整个交易块;不会产生部分效果。
- 交易结束约束:执行过程中产生的所有非值必须被消费(转移、销毁或传入另一个命令)。共享对象仅有两种合法结局:重新共享或删除——无法被转移或冻结。Gas币会返还给所有者,未使用的Gas将被退还。
drop
Rules
规则
- must be used by reference, except in
tx.gas. To get an ownedtransferObjectsfrom the gas coin, useCoin<SUI>first.SplitCoins(tx.gas, [amount]) - Leave gas config to the wallet when possible. Do not hardcode /
setGasBudget/setGasPricein app code that will be signed by a user wallet — the wallet dry-runs and selects coins correctly. Only set them for backend-signed flows.setGasPayment - In app code that hands a PTB to a wallet, use (not
tx.serialize()). The wallet must perform gas logic and coin selection itself; building bytes in app code preempts that.tx.build() - Use for sponsored flows. Build in app with
Transaction.fromKind(kindBytes), send the kind-only bytes to the sponsor service, rehydrate there withtx.build({ client, onlyTransactionKind: true }), thenfromKind,setSender,setGasOwner. The user (or either party) should submit the fully-signed transaction directly to a full node — not back through the sponsor service — to avoid censorship.setGasPayment - Every non-value must be consumed. If
dropreturns a value you don't need, pass it tomoveCall(if it hastransferObjects), tokey + store, or to a destructor.public_transferis the PTB-level error.UnusedValueWithoutDrop - Shared objects cannot be transferred, frozen, or consumed by value if passed as read-only (). If you need mutable access, mark them mutable when building the input.
mutable: false - Types coming from Move calls cannot be references. results are values; if a Move function returns
MoveCall, it cannot be called from a PTB.&T - For multi-return Move calls, use destructuring or array indexing. or
const [a, b] = tx.moveCall(...). Do not assume single-return shape.const r = tx.moveCall(...); r[0]; r[1]; - Cite the docs when unsure. Canonical sources above. Legacy URLs still render but prefer
/develop/transactions/ptbs/*and/concepts/transactions/prog-txn-blocks./guides/developer/sui-101/building-ptb
- 必须通过引用使用,
tx.gas除外。要从Gas币中获取自有transferObjects,需先使用Coin<SUI>。SplitCoins(tx.gas, [amount]) - 尽可能将Gas配置交给钱包处理。在将由用户钱包签名的应用代码中,不要硬编码/
setGasBudget/setGasPrice——钱包会进行试运行并正确选择代币。仅在后端签名流程中设置这些参数。setGasPayment - 在将PTB交给钱包的应用代码中,使用(而非
tx.serialize())。钱包必须自行执行Gas逻辑和代币选择;在应用代码中构建字节会抢占这一流程。tx.build() - 赞助流程使用。在应用中使用
Transaction.fromKind(kindBytes)构建,将仅包含交易类型的字节发送给赞助服务,在服务端使用tx.build({ client, onlyTransactionKind: true })重新构建,然后设置fromKind、setSender、setGasOwner。用户(或任意一方)应直接将完全签名的交易提交给全节点——而非通过赞助服务返回——以避免审查。setGasPayment - 所有非值必须被消费。如果
drop返回了你不需要的值,可将其传入moveCall(若该值具有transferObjects)、key + store,或销毁函数。public_transfer是PTB层面的错误。UnusedValueWithoutDrop - 共享对象若以只读方式传入(),则无法被转移、冻结或按值消费。如果需要可变访问权限,在构建输入时标记其为可变。
mutable: false - 来自Move调用的类型不能是引用。的结果是值;如果Move函数返回
MoveCall,则无法从PTB中调用该函数。&T - 对于多返回值的Move调用,使用解构或数组索引。或
const [a, b] = tx.moveCall(...)。不要假设返回值为单一值。const r = tx.moveCall(...); r[0]; r[1]; - 不确定时参考官方文档:上述权威来源。旧版URL仍可访问,但优先使用
/develop/transactions/ptbs/*和/concepts/transactions/prog-txn-blocks。/guides/developer/sui-101/building-ptb
Common mistakes
常见错误
- Calling without a type. Untyped pure values fail at input resolution. Use typed helpers:
tx.pure(value),tx.pure.u64(n),tx.pure.address(addr), or the generictx.pure.string(s).tx.pure('u64', n) - Passing a string object ID to arguments without
moveCall. Mixed-type arguments require explicittx.object(...)wrapping; otherwise the SDK can't distinguish pure from object.tx.object(id) - Transferring or freezing a shared object. Shared objects cannot be transferred or frozen — but they can be deleted. The two legal endings for a shared object in a PTB are re-share or delete. Do not include shared objects in . Note that consuming a shared object by value permanently marks its hot-potato clique as "hot", which blocks subsequent non-public
transferObjectscalls on any entangled value in that clique.entry - Forgetting to on offline builds. When calling
setSenderwithout signing through a signer that sets the sender, the sender field stays empty and the build fails.tx.build() - Treating multi-return results as single values. The return is a vector; index or destructure.
moveCall - Using /
transfer::transferon generic types from a PTB. Those entries require a module-private type param. From a PTB, usetransfer::share_object/transfer::public_transfer, which require the type to havetransfer::public_share_object.store - Setting a gas budget that's too tight. A tx that exceeds budget aborts but still charges the gas coin. Prefer the SDK's dry-run-based auto-budget.
- Not checking execution status. A transaction can be accepted by validators but fail at the Move level (assertion, out of gas, etc.). Always check before treating an operation as successful. The tx digest alone does not mean the effects were applied.
result.effects.status.status === 'success' - Looping in app code to submit N individual transactions. Batch into one PTB (up to 1,024 ops). One PTB is cheaper and atomic.
- 调用时未指定类型:无类型的纯值会在输入解析阶段失败。请使用类型化辅助函数:
tx.pure(value)、tx.pure.u64(n)、tx.pure.address(addr),或泛型tx.pure.string(s)。tx.pure('u64', n) - 将字符串对象ID直接传入参数而未使用
moveCall包装:混合类型参数需要显式使用tx.object(...)包装;否则SDK无法区分纯值和对象。tx.object(id) - 转移或冻结共享对象:共享对象无法被转移或冻结——但可以被删除。PTB中共享对象的两种合法结局是重新共享或删除。请勿将共享对象包含在中。注意,按值消费共享对象会永久标记其热土豆clique为“热”,这会阻止后续对该clique中任何关联值的非公开
transferObjects调用。entry - 离线构建时忘记:当调用
setSender但未通过签名者设置发送方时,发送方字段会保持为空,导致构建失败。tx.build() - 将多返回值的结果视为单一值:返回值是一个向量;需使用索引或解构。
moveCall - 在PTB中对泛型类型使用/
transfer::transfer:这些入口函数需要模块私有类型参数。在PTB中,请使用transfer::share_object/transfer::public_transfer,它们要求类型具有transfer::public_share_object属性。store - 设置的Gas预算过低:超过预算的交易会中止,但仍会扣除Gas币。优先使用SDK基于试运行的自动预算功能。
- 未检查执行状态:交易可能被验证节点接受,但在Move层面失败(断言错误、Gas不足等)。在确认操作成功前,务必检查。仅交易摘要并不意味着效果已生效。
result.effects.status.status === 'success' - 在应用代码中循环提交N笔独立交易:应批量合并为一个PTB(最多1024个操作)。单个PTB成本更低且具有原子性。