Overview
PTBs enable:- Composability: Chain multiple Move calls in one transaction
- Efficiency: Batch operations to save gas
- Atomicity: All operations succeed or fail together
- Flexibility: Build complex transaction logic
Basic Usage
Simple Transfer Example
- Splits 1000 nanos from gas coin
- Assigns result to variable
new_coin - Transfers
new_cointo recipient
PTB Commands
transfer-objects
Transfer objects to a recipient:Example
split-coins
Split coins into new coins:Examples
merge-coins
Merge coins into a single coin:Example
move-call
Call a Move function:Examples
make-move-vec
Create a Move vector:Example
publish
Publish a Move package:Example
upgrade
Upgrade a Move package:Example
assign
Assign result to a variable:gas-budget
Set gas budget:Complex Examples
Multi-Step Transfer
Split coins and transfer to multiple recipients:Swap Operations
Chain multiple Move calls:Batch Minting
Mint and distribute NFTs:Publish and Initialize
Publish package and initialize in one transaction:Coin Operations
Complex coin manipulation:Variables and References
Result Variables
Commands return results that can be assigned:Multiple Results
Some commands return multiple values:Special Variables
gas- The gas payment coin@0xADDRESS- Address literals0xOBJECT_ID- Object references
Gas Management
Gas Budget
Set maximum gas to spend:Gas Payment
Use specific coins for gas:Gas Coin Operations
The gas coin can be split and used:Type Arguments
Generic Functions
Specify type arguments for generic functions:Multiple Type Arguments
Transaction Options
Dry Run
Simulate without executing:Serialize
Get transaction bytes:Custom Sender
Override sender address:JSON Output
Get JSON formatted output:Advanced Patterns
Conditional Operations
Use Move functions for conditional logic:Loops (via Move)
Batch operations using Move vectors:Object Creation and Transfer
Package Management
Best Practices
1. Minimize Operations
Batch operations efficiently:2. Handle Errors
Use dry run to test:3. Optimize Gas
Estimate gas before execution:4. Use Variables
Make PTBs readable with variables:5. Atomic Operations
Group related operations:Troubleshooting
Error: Invalid argument
Issue: Incorrect argument format Solution:Error: Variable not found
Issue: Referencing undefined variable Solution:Error: Type mismatch
Issue: Wrong type arguments Solution:Error: Insufficient gas
Issue: Gas budget too low Solution:Error: Object not owned
Issue: Trying to use object you don’t own Solution:Examples Library
Simple Transfer
Split and Transfer
Multi-Recipient Transfer
Merge and Use
Publish and Initialize
NFT Mint and List
DeFi Swap
Next Steps
Client Commands
Learn more client operations
Move Commands
Build Move packages
Testing
Test your transactions