
Description
Sui Programmable Transaction Blocks (PTBs). Use when writing, reviewing, or debugging code that composes multiple Sui transaction commands into a single atomic transaction — including TypeScript SDK `Transaction` usage, CLI PTB construction, gas coin handling, sponsored transactions, shared-object inputs, chaining command results, or troubleshooting PTB execution errors.
SKILL.md
Sui Programmable Transaction Blocks (PTBs)
MCP tool: When available in your environment, also query the Sui documentation MCP server (
https://sui.mcp.kapa.ai) for up-to-date answers. Use it for verification and for details not covered by these reference files.
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/sui/transactions/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.
Reference files
fundamentals — PTB data model
Path: fundamentals.mdLoad when: explaining what a PTB is, talking about Input, Argument, NestedResult, GasCoin, owned vs shared vs immutable vs receiving object references, pure-input BCS rules, command chaining semantics, or execution ordering / atomicity.
Covers: PTB structure, Input (CallArg) and ObjectArg variants, pure input types, Argument enum, result chaining, execution semantics (borrow rules, move/copy, hot potato cliques, end-of-tx constraints), protocol limits.
commands — Command reference
Path: commands.mdLoad when: writing or reviewing any specific command — MoveCall, SplitCoins, MergeCoins, TransferObjects, MakeMoveVec, Publish, Upgrade — or debugging argument-type mismatches and return-value shape.
Covers: signature, argument rules, return shape, and common pitfalls for each of the seven commands.
building — TypeScript SDK Transaction class
Path: building.mdLoad when: writing TS/JS code that constructs a PTB with @mysten/sui/transactions, configuring gas, building for wallets, serializing across services, or sending PTBs between app ↔ wallet ↔ sponsor.
Covers: Transaction API (tx.moveCall, tx.splitCoins, tx.mergeCoins, tx.transferObjects, tx.makeMoveVec, tx.publish, tx.upgrade, tx.balance, tx.coin, tx.add, tx.object, tx.pure, tx.gas, tx.setSender/setGasPrice/setGasBudget/setGasPayment/setGasOwner), Inputs.*Ref helpers, result destructuring, build({ onlyTransactionKind: true }), Transaction.from / fromKind, sponsored transaction flow, signing & executing.
cli — Building PTBs from the CLI
Path: cli.mdLoad when: constructing PTBs from the command line using sui client ptb, scripting transactions without TypeScript, merging coins from the CLI, or teaching CLI-based workflows.
Covers: sui client ptb syntax, chaining commands, common CLI PTB patterns (transfers, coin merges, Move calls), gas budget, previewing before execution.
troubleshooting — Common errors
Path: troubleshooting.mdLoad when: diagnosing a failing PTB — any ServerError, UnusedValueWithoutDrop, VMVerificationOrDeserializationError, No valid gas coins, InsufficientGas, shared-object congestion, or cryptic "transaction failed" output.
Covers: each error category with the Move/PTB-level cause and concrete fix.
Routing 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 |
Skill Content
Key concepts
- A PTB is the transaction. Every Sui transaction is a PTB — even a single
moveCallis a one-command PTB. There is no non-PTB execution path. - Inputs vs commands.
inputsare values fed in from outside (objects and BCS-encoded "pure" bytes).commandsoperate on those inputs and on each other's results. Commands reference values via theArgumentenum:Input(i),GasCoin,Result(i),NestedResult(cmd, result). - Chaining. Each command produces an array of results. The next command can consume any result (by
NestedResult(cmd, idx)or, when a command has exactly one return,Result(cmd)). The TS SDK surfaces this as destructurable values: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-
dropvalue 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.
Rules
tx.gasmust be used by reference, except intransferObjects. To get an ownedCoin<SUI>from the gas coin, useSplitCoins(tx.gas, [amount])first.- Leave gas config to the wallet when possible. Do not hardcode
setGasBudget/setGasPrice/setGasPaymentin 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. - In app code that hands a PTB to a wallet, use
await tx.toJSON()(nottx.build()). The wallet must perform gas logic and coin selection itself; building bytes in app code preempts that. - Use
Transaction.fromKind(kindBytes)for sponsored flows. Build in app withtx.build({ client, onlyTransactionKind: true }), send the kind-only bytes to the sponsor service, rehydrate there withfromKind, thensetSender,setGasOwner,setGasPayment. 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. - Every non-
dropvalue must be consumed. IfmoveCallreturns a value you don't need, pass it totransferObjects(if it haskey + store), topublic_transfer, or to a destructor.UnusedValueWithoutDropis the PTB-level error. - Shared objects cannot be transferred, frozen, or consumed by value if passed as read-only (
mutable: false). If you need mutable access, mark them mutable when building the input. - Types coming from Move calls cannot be references.
MoveCallresults are values; if a Move function returns&T, it cannot be called from a PTB. - For multi-return Move calls, use destructuring or array indexing.
const [a, b] = tx.moveCall(...)orconst r = tx.moveCall(...); r[0]; r[1];. Do not assume single-return shape. - Cite the docs when unsure. Canonical sources above. Legacy
/develop/transactions/ptbs/*URLs still render but prefer/concepts/transactions/prog-txn-blocksand/guides/developer/sui-101/building-ptb.
Common mistakes
- Calling
tx.pure(value)without a type. Untyped pure values fail at input resolution. Use typed helpers:tx.pure.u64(n),tx.pure.address(addr),tx.pure.string(s), or the generictx.pure('u64', n). - Passing a string object ID to
moveCallarguments withouttx.object(...). Mixed-type arguments require explicittx.object(id)wrapping; otherwise the SDK can't distinguish pure from object. - 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
transferObjects. Note that consuming a shared object by value permanently marks its hot-potato clique as "hot", which blocks subsequent non-publicentrycalls on any entangled value in that clique. - Forgetting to
setSenderon offline builds. When callingtx.build()without signing through a signer that sets the sender, the sender field stays empty and the build fails. - Treating multi-return
moveCallresults as single values. The return is a vector; index or destructure. - Using
transfer::transfer/transfer::share_objecton generic types from a PTB. Those entries require a module-private type param. From a PTB, usetransfer::public_transfer/transfer::public_share_object, which require the type to havestore. - 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
result.$kind !== 'FailedTransaction'before treating an operation as successful. The tx digest alone does not mean the effects were applied. - Looping in app code to submit N individual transactions. Batch into one PTB (up to 1,024 ops). One PTB is cheaper and atomic.
More skills from the skills repository
View all 20 skillsaccessing-data
read data from the Sui network
Jul 16Data AnalysisSuiWeb3composable-move-functions
design composable Sui Move functions
Jul 16API DevelopmentSmart ContractsSuiWeb3frontend-apps
build Sui dApps with dapp-kit
Jul 16FrontendReactSuiSvelte +2generate-sui-agent-config
generate configuration files for Sui projects
Jul 16ConfigurationDocumentationSuimodern-move-syntax
write Move 2024 edition code for Sui
Jul 16EngineeringSmart ContractsSuiWeb3move-unit-testing
write unit tests for Sui Move contracts
Jul 16QASmart ContractsSuiTesting +1
More from Sui (Mysten Labs)
View publishermove-bytecode-comprehension
analyze and disassemble Move bytecode
sui
Jul 16Code AnalysisEngineeringSuiofficial-sui-skills
access official Sui development resources
sui
Jul 16DocumentationSuisui-and-move-tools
disassemble Sui Move bytecode
sui
Jul 16Code AnalysisEngineeringSuisui-move-security-review
audit Sui Move smart contracts
sui
Jul 16Code ReviewSecuritySmart ContractsSuimemwal
integrate Walrus Memory SDK
MemWal
Jul 16AgentsMemorySDKnaming-conventions
apply Sui Move naming conventions
skills
Jul 16Best PracticesSmart ContractsSuiWeb3