sui-transaction-building
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSui Transaction Building Skill
Sui 交易构建技能
Overview
概述
Transaction building is a core functionality of Sui blockchain development. The Sui TypeScript SDK provides the class, allowing developers to create, serialize, sign, and execute blockchain transactions using a fluent builder pattern. This skill helps Claude Code understand how to assist users in building various types of transactions on Sui.
Transaction交易构建是Sui区块链开发的核心功能。Sui TypeScript SDK提供了类,允许开发者使用流畅的构建器模式创建、序列化、签名和执行区块链交易。本技能帮助Claude Code理解如何协助用户在Sui上构建各类交易。
TransactionQuick Start
快速开始
Installation and Import
安装与导入
typescript
// Import Transaction class
import { Transaction } from '@mysten/sui/transactions';
// Create new transaction
const tx = new Transaction();typescript
// Import Transaction class
import { Transaction } from '@mysten/sui/transactions';
// Create new transaction
const tx = new Transaction();Basic Example: Sending SUI
基础示例:发送SUI
typescript
import { Transaction } from '@mysten/sui/transactions';
const tx = new Transaction();
// Split 100 units of SUI from gas coin
const [coin] = tx.splitCoins(tx.gas, [100]);
// Transfer the split coin to specified address
tx.transferObjects([coin], '0xSomeSuiAddress');
// Execute transaction using signAndExecuteTransaction
const result = await client.signAndExecuteTransaction({
signer: keypair,
transaction: tx
});typescript
import { Transaction } from '@mysten/sui/transactions';
const tx = new Transaction();
// Split 100 units of SUI from gas coin
const [coin] = tx.splitCoins(tx.gas, [100]);
// Transfer the split coin to specified address
tx.transferObjects([coin], '0xSomeSuiAddress');
// Execute transaction using signAndExecuteTransaction
const result = await client.signAndExecuteTransaction({
signer: keypair,
transaction: tx
});Core Components
核心组件
Transaction Class
Transaction类
Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/Transaction.tsThe Transaction class is the core of transaction building, providing the following key features:
- Builder Pattern: Fluent interface supporting method chaining
- Command Support: Supports all Sui transaction commands (Move calls, transfers, merges, etc.)
- Plugin System: Supports transaction parsing plugins
- Serialization Capability: Built-in BCS serialization support
- Async Support: Supports automatic resolution of async transaction thunks
代码位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/Transaction.tsTransaction类是交易构建的核心,具备以下关键特性:
- 构建器模式:支持方法链式调用的流畅接口
- 命令支持:支持所有Sui交易命令(Move调用、转账、合并等)
- 插件系统:支持交易解析插件
- 序列化能力:内置BCS序列化支持
- 异步支持:支持自动解析异步交易thunk
TransactionDataBuilder Class
TransactionDataBuilder类
Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/TransactionData.tsHandles transaction data structure and serialization:
- Transaction data validation and serialization
- BCS serialization for blockchain compatibility
- Gas configuration and budget management
- Input and command management
代码位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/TransactionData.ts负责处理交易数据结构与序列化:
- 交易数据验证与序列化
- 适配区块链的BCS序列化
- Gas配置与预算管理
- 输入与命令管理
Commands Module
命令模块
Location:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/Commands.tsDefines all available transaction operations:
- MoveCall: Execute Move smart contract functions
- TransferObjects: Transfer objects between addresses
- SplitCoins: Split a coin into multiple amounts
- MergeCoins: Merge multiple coins
- Publish: Deploy new Move modules
- Upgrade: Upgrade existing Move modules
- MakeMoveVec: Create Move vectors
代码位置:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/Commands.ts定义所有可用的交易操作:
- MoveCall:执行Move智能合约函数
- TransferObjects:在地址间转移对象
- SplitCoins:将一个代币拆分为多个金额
- MergeCoins:合并多个代币
- Publish:部署新的Move模块
- Upgrade:升级现有Move模块
- MakeMoveVec:创建Move向量
Detailed Documentation
详细文档
This skill follows a progressive disclosure pattern. The main file provides an overview and quick start, while detailed information is available in the reference directory.
本技能采用渐进式披露模式。主文件提供概述与快速开始内容,详细信息可参考参考目录。
Transaction Commands
交易命令
For detailed information about transaction commands including SplitCoins, MergeCoins, TransferObjects, MoveCall, MakeMoveVec, and Publish, see Transaction Commands.
关于SplitCoins、MergeCoins、TransferObjects、MoveCall、MakeMoveVec和Publish等交易命令的详细信息,请查看交易命令。
Input Types
输入类型
Learn about different input types including pure values, object references, and transaction results in Input Types.
了解纯值、对象引用和交易结果等不同输入类型,请查看输入类型。
Gas Configuration
Gas配置
Understand gas coin usage, price setting, budget configuration, and optimization in Gas Configuration.
了解Gas代币使用、价格设置、预算配置与优化,请查看Gas配置。
Transaction Serialization
交易序列化
Details about building transaction bytes, deserialization, and offline building in Transaction Serialization.
关于交易字节构建、反序列化和离线构建的详细信息,请查看交易序列化。
Advanced Features
高级功能
Explore transaction intents, sponsored transactions, plugin system, and async support in Advanced Features.
探索交易意图、代付交易、插件系统和异步支持,请查看高级功能。
Usage Patterns
使用模式
Common patterns for transaction building, signing, execution, testing, and error handling in Usage Patterns.
交易构建、签名、执行、测试和错误处理的常见模式,请查看使用模式。
Integration Points
集成要点
Integration with SuiClient, BCS, keypairs, wallets, and external systems in Integration Points.
与SuiClient、BCS、密钥对、钱包及外部系统的集成,请查看集成要点。
Workflows
工作流
Complete end-to-end workflows for common scenarios including SUI transfers, NFT minting, and offline building in Workflows.
常见场景的完整端到端工作流,包括SUI转账、NFT铸造和离线构建,请查看工作流。
Best Practices
最佳实践
Performance optimization, error handling, security considerations, and code quality guidelines in Best Practices.
性能优化、错误处理、安全注意事项和代码质量指南,请查看最佳实践。
Related Skills
相关技能
- sui-bcs: Understand BCS serialization usage in transactions
- sui-transaction-executors: Understand advanced usage of transaction executors
- sui-keypair-cryptography: Understand transaction signing and key management
- sui-client: Understand complete SuiClient API
- sui-bcs:了解交易中的BCS序列化用法
- sui-transaction-executors:了解交易执行器的高级用法
- sui-keypair-cryptography:了解交易签名与密钥管理
- sui-client:了解完整的SuiClient API
References
参考资料
- Official Documentation: https://sdk.mystenlabs.com/typescript/transaction-building
- Source Code:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/ - Test Cases:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/__tests__/ - TypeScript Type Definitions:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/types.ts
This skill helps Claude Code understand Sui transaction building, providing practical code examples and usage guidelines. When users need to build Sui blockchain transactions, referencing this skill can provide accurate TypeScript code and best practices.
- 官方文档:https://sdk.mystenlabs.com/typescript/transaction-building
- 源代码:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/ - 测试用例:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/__tests__/ - TypeScript类型定义:
https://github.com/MystenLabs/ts-sdks/tree/main/packages/typescript/src/transactions/types.ts
本技能帮助Claude Code理解Sui交易构建,提供实用代码示例与使用指南。当用户需要构建Sui区块链交易时,参考本技能可获取准确的TypeScript代码与最佳实践。