Practicing with Programmable Transaction Blocks
Hands-on Guide to PTBs
💡 Goals of This Chapter
- Learn how to construct and execute PTBs (Programmable Transaction Blocks).
- Understand how to group multiple Move function calls into one transaction.
- Visualize and execute PTBs using ptb.wal.app.
1. Preparation
- Ensure that your Managed Token package from the previous chapter is deployed.
- Open the Owner Objects Explorer and confirm that you own a
TreasuryCap<...::MANAGED>
object. - Connect the Sui Extension or CLI to the Testnet.
2. Running from the Sui Extension
- Open Package Explorer.
- Select the
mint
function and provide arguments (treasury_cap
,amount
,recipient
). - Click Execute → A new
Coin<MANAGED>
object is created.
💡 This is the simplest way to call Move functions directly from VS Code.
3. Running in PTB Builder
Open PTB Builder.
Add a new node:
moveCall → managed::mint
.Set arguments:
object(treasuryCapId)
pure.u64(amount)
pure.address(recipient)
Click Run to execute the transaction and view the Transaction Digest.
⚡️ PTB Builder automatically generates TypeScript code for your transaction. Use Export or Copy to reuse it directly in your project.
4. Using the Web Version (ptb.wal.app)
You can also use the browser-based PTB Builder at 👉 https://ptb.wal.app
Main Features
- Drag & Drop interface for building and executing PTBs.
- Input a tx digest to visualize existing transactions.
- Export PTBs as
.json
files. - Convert PTBs into TypeScript code for reuse.
5. Converting to TypeScript
ts
import { Transaction } from "@mysten/sui/transactions";
const tx = new Transaction();
const treasuryCap = tx.object("0x123...");
const amount = tx.pure.u64(100);
const recipient = tx.pure.address("0xabc...");
tx.moveCall({
target: "0xPACKAGE::managed::mint",
arguments: [treasuryCap, amount, recipient],
});
✅ This TypeScript code can be executed directly with the Sui SDK.
💡 You now understand how to construct, execute, and convert PTBs. Next, you’ll learn how to create a single transaction containing multiple commands for advanced use cases.