Skip to main content
The TransactionBuilder provides a high-level API for constructing Sui transaction blocks. It’s available through sui.transaction_builder().

Overview

The TransactionBuilder wraps the lower-level transaction building logic and provides convenience methods for common operations:

Building Transactions

The TransactionBuilder is defined in the sui-transaction-builder crate and provides methods from the sui_transaction_builder::TransactionBuilder struct.

Accessing the Builder

The transaction builder requires a DataReader implementation (provided by ReadApi) to fetch necessary on-chain data while building transactions.

Common Transaction Patterns

Transfer Objects

Split and Transfer Coins

Move Calls

Working with Programmable Transaction Blocks

Sui’s programmable transaction blocks allow composing multiple operations:

Gas Management

Selecting Gas Coins

Use the CoinReadApi to select appropriate gas coins:

Getting Gas Price

Signing Transactions

After building the transaction data, sign it:

Complete Example: Transfer SUI

DataReader Trait

The TransactionBuilder uses the DataReader trait to fetch on-chain data:
The ReadApi implements this trait, enabling the builder to automatically fetch necessary data.

Best Practices

  1. Gas Estimation: Always dry-run transactions to estimate gas costs:
  2. Error Handling: Check object ownership and versions before building:
  3. Gas Budget: Set appropriate gas budgets based on transaction complexity
  4. Programmable Transactions: Use PTBs to batch multiple operations efficiently