Skip to main content

Class: TransactionBuilder

A builder for creating transactions. Use finish to finalize the transaction data.

Extends​

  • UniffiAbstractObject

Implements​

Constructors​

Constructor​

new TransactionBuilder(sender): TransactionBuilder;

Create a new transaction builder and initialize its elements to default.

Parameters​

sender​

AddressLike

Returns​

TransactionBuilder

Overrides​

UniffiAbstractObject.constructor

Properties​

[destructorGuardSymbol]​

readonly [destructorGuardSymbol]: UniffiGcObject;

[pointerLiteralSymbol]​

readonly [pointerLiteralSymbol]: bigint;

[uniffiTypeNameSymbol]​

readonly [uniffiTypeNameSymbol]: "TransactionBuilder" = "TransactionBuilder";

Methods​

authorizeUpgrade()​

authorizeUpgrade(
upgradeCapability,
upgradePolicy,
digest,
upgradeTicketName
): TransactionBuilderLike;

Authorize a package upgrade by calling 0x2::package::authorize_upgrade.

The result assigned to upgrade_ticket_name is the UpgradeTicket expected by TransactionBuilder::upgrade(). The digest is the digest of the package being upgraded to (MovePackageData::digest()).

For the standard upgrade flow, use TransactionBuilder::upgrade_package() instead.

Parameters​

upgradeCapability​

PtbArgumentLike

upgradePolicy​

UpgradePolicyLike

digest​

DigestLike

upgradeTicketName​

string

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.authorizeUpgrade


commitUpgrade()​

commitUpgrade(upgradeCapability, upgradeReceipt): TransactionBuilderLike;

Commit a package upgrade by calling 0x2::package::commit_upgrade, consuming the UpgradeReceipt returned by TransactionBuilder::upgrade().

Parameters​

upgradeCapability​

PtbArgumentLike

upgradeReceipt​

PtbArgumentLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.commitUpgrade


divideCoin()​

divideCoin(
coin,
count,
coinType?
): TransactionBuilderLike;

Divide a coin into count coins of equal value, all kept by the sender.

Unlike split_coins, the new coins are transferred to the sender by 0x2::pay::divide_and_keep itself, so no transfer command is needed for them. In exchange they are not available as command results and cannot be used by later commands in the same transaction.

The coin defaults an IOTA coin. For any other coin type, set it with coin_type, which is the T of 0x2::coin::Coin<T>.

count - 1 new coins are created, each holding value / count, and the divided coin keeps its own share plus the remainder of the division. The transaction aborts if count is zero or larger than the coin's value.

The coin is passed by reference, so the gas coin (PTBArgument::Gas) can be divided as well, as long as it retains enough balance to pay for the transaction.

Parameters​

coin​

PtbArgumentLike

count​

bigint

coinType?​

TypeTagLike | undefined = undefined

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.divideCoin


executeWithGasStation()​

executeWithGasStation(
gasStation,
signer,
asyncOpts_?
): Promise<TransactionDigestLike>;

Execute the transaction with its gas paid by gas_station, returning the transaction digest.

Parameters​

gasStation​

GasStationLike

signer​

TransactionSignerLike

asyncOpts_?​
signal​

AbortSignal

Returns​

Promise<TransactionDigestLike>

Implementation of​

TransactionBuilderLike.executeWithGasStation


expiration()​

expiration(epoch): TransactionBuilderLike;

Set the expiration of the transaction to be a specific epoch.

Parameters​

epoch​

bigint

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.expiration


finish()​

finish(): TransactionLike;

Convert this builder into a transaction.

Returns​

TransactionLike

Implementation of​

TransactionBuilderLike.finish


gas()​

gas(objectRefs): TransactionBuilderLike;

Add gas coins that will be consumed. Optional.

Parameters​

objectRefs​

ObjectReference[]

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.gas


gasBudget()​

gasBudget(budget): TransactionBuilderLike;

Set the gas budget for the transaction.

Parameters​

budget​

bigint

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.gasBudget


gasPrice()​

gasPrice(price): TransactionBuilderLike;

Set the gas price for the transaction.

Parameters​

price​

bigint

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.gasPrice


makeMoveVec()​

makeMoveVec(
elements,
typeTag,
name
): TransactionBuilderLike;

Make a move vector from a list of elements. The elements must all be of the type indicated by type_tag.

Parameters​

elements​

MoveArgLike[]

typeTag​

TypeTagLike

name​

string

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.makeMoveVec


mergeCoins()​

mergeCoins(primaryCoin, consumedCoins): TransactionBuilderLike;

Merge multiple coins into one.

This method combines the balances of multiple coins of the same coin type into a single coin. The primary_coin will receive the balances from all consumed_coins. After merging, the consumed_coins will be consumed and no longer exist.

Parameters​

primaryCoin​

PtbArgumentLike

consumedCoins​

PtbArgumentLike[]

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.mergeCoins


moveCall()​

moveCall(
package_,
module,
function_,
moveArguments?,
typeArgs?,
names?
): TransactionBuilderLike;

Call a Move function with the given arguments.

Parameters​

package_​

AddressLike

module​

IdentifierLike

function_​

IdentifierLike

moveArguments?​

PtbArgumentLike[] = []

typeArgs?​

TypeTagLike[] = []

names?​

string[] = []

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.moveCall


pay()​

pay(coins, payments): TransactionBuilderLike;

Send coins to multiple recipients, each paired with the amount to send.

The amounts specify quantities in the coins' smallest unit (NANOS for IOTA coins, where 1 IOTA equals 1_000_000_000 NANOS).

The coins are merged into the first one, the amounts are split off it in a single command, and each split coin is transferred to its corresponding recipient, with one transfer command per unique recipient. The remainder stays in the first coin.

All provided coins must have the same coin type. Mixing coins of different types will result in an error.

To pay IOTA directly from the gas coin, use TransactionBuilder::pay_iota() instead.

For a single recipient, consider using TransactionBuilder::send_coins() or TransactionBuilder::send_iota() instead.

Parameters​

coins​

PtbArgumentLike[]

payments​

Payment[]

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.pay


payIota()​

payIota(payments): TransactionBuilderLike;

Send IOTA to multiple recipients, each paired with the amount to send.

The amounts specify quantities in NANOS, where 1 IOTA equals 1_000_000_000 NANOS. They are split off the gas coin in a single command, and each split coin is transferred to its corresponding recipient, with one transfer command per unique recipient.

To pay with specific coins, or with a coin type other than IOTA, use TransactionBuilder::pay(). For a single recipient, consider using TransactionBuilder::send_iota() instead.

Parameters​

payments​

Payment[]

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.payIota


publishPackage()​

publishPackage(packageData, upgradeCapName): TransactionBuilderLike;

Publish a list of modules with the given dependencies. The result assigned to upgrade_cap_name is the 0x2::package::UpgradeCap Move type. Note that the upgrade capability needs to be handled after this call:

  • transfer it to the transaction sender or another address
  • burn it
  • wrap it for access control
  • discard the it to make a package immutable

The arguments required for this command are:

  • modules: is the modules' bytecode to be published
  • dependencies: is the list of IDs of the transitive dependencies of the package

Parameters​

packageData​

MovePackageDataLike

upgradeCapName​

string

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.publishPackage


sendCoins()​

sendCoins(
coins,
recipient,
amount?
): TransactionBuilderLike;

Transfer some coins to a recipient address. If multiple coins are provided then they will be merged.

The amount parameter specifies the quantity in NANOS, where 1 IOTA equals 1_000_000_000 NANOS. If amount is provided, that amount is split from the provided coins and sent. If amount is None, the entire coins are transferred.

All provided coins must have the same coin type. Mixing coins of different types will result in an error.

If you intend to transfer all provided coins to another address in a single transaction, consider using TransactionBuilder::transfer_objects() instead.

Parameters​

coins​

PtbArgumentLike[]

recipient​

AddressLike

amount?​

PtbArgumentLike | undefined = undefined

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.sendCoins


sender()​

sender(sender): TransactionBuilderLike;

Set the sender address.

Parameters​

sender​

AddressLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.sender


sendIota()​

sendIota(recipient, amount): TransactionBuilderLike;

Send IOTA to a recipient address.

The amount parameter specifies the quantity in NANOS, where 1 IOTA equals 1_000_000_000 NANOS. That amount is split from the gas coin and sent.

Parameters​

recipient​

AddressLike

amount​

PtbArgumentLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.sendIota


splitCoins()​

splitCoins(
coin,
amounts,
names?
): TransactionBuilderLike;

Split a coin by the provided amounts.

Parameters​

coin​

PtbArgumentLike

amounts​

PtbArgumentLike[]

names?​

string[] = []

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.splitCoins


sponsor(sponsor): TransactionBuilderLike;

Set the sponsor of the transaction.

Parameters​

AddressLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.sponsor


stake()​

stake(stake, validatorAddress): TransactionBuilderLike;

Add stake to a validator's staking pool.

This is a high-level function which will split the provided stake amount from the gas coin and then stake using the resulting coin.

Parameters​

stake​

PtbArgumentLike

validatorAddress​

AddressLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.stake


toDebugString()​

toDebugString(): string;

Returns​

string


toString()​

toString(): string;

Returns a string representation of an object.

Returns​

string


transferObjects()​

transferObjects(recipient, objects): TransactionBuilderLike;

Transfer a list of objects to the given address, without producing any result.

Parameters​

recipient​

AddressLike

objects​

PtbArgumentLike[]

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.transferObjects


uniffiDestroy()​

uniffiDestroy(): void;

Explicitly tell Rust to destroy the native peer that backs this object.

Once this method has been called, any following method calls will throw an error.

Can be called more than once.

Returns​

void

Overrides​

UniffiAbstractObject.uniffiDestroy


uniffiUse()​

uniffiUse<T>(block): T;

A convenience method to use this object, then destroy it after its use.

Type Parameters​

T​

T

Parameters​

block​

(obj) => T

Returns​

T

Inherited from​

UniffiAbstractObject.uniffiUse


unstake()​

unstake(stakedIota): TransactionBuilderLike;

Withdraw stake from a validator's staking pool.

Parameters​

stakedIota​

PtbArgumentLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.unstake


upgrade()​

upgrade(
packageId,
packageData,
upgradeTicket,
name?
): TransactionBuilderLike;

Upgrade a Move package.

  • modules: is the modules' bytecode for the modules to be published
  • dependencies: is the list of IDs of the transitive dependencies of the package to be upgraded
  • package: is the ID of the current package being upgraded
  • ticket: is the upgrade ticket

To get the ticket, use TransactionBuilder::authorize_upgrade(). The result assigned to name is the UpgradeReceipt expected by TransactionBuilder::commit_upgrade().

Parameters​

packageId​

ObjectIdLike

packageData​

MovePackageDataLike

upgradeTicket​

PtbArgumentLike

name?​

string | undefined = undefined

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.upgrade


upgradePackage()​

upgradePackage(
packageId,
packageData,
upgradeCapability,
upgradePolicy
): TransactionBuilderLike;

Upgrade a Move package.

This is a high-level function which chains TransactionBuilder::authorize_upgrade(), TransactionBuilder::upgrade() and TransactionBuilder::commit_upgrade() using the digest from the provided MovePackageData. Use the individual functions for custom upgrade flows.

Parameters​

packageId​

ObjectIdLike

packageData​

MovePackageDataLike

upgradeCapability​

PtbArgumentLike

upgradePolicy​

UpgradePolicyLike

Returns​

TransactionBuilderLike

Implementation of​

TransactionBuilderLike.upgradePackage


withGraphqlClient()​

withGraphqlClient(client): GraphQlTransactionBuilderLike;

Use a GraphQL client to automatically resolve the transaction inputs.

The builder takes a snapshot of the client's configuration; set_* calls made on the client afterwards do not affect it.

Parameters​

client​

GraphQlClientLike

Returns​

GraphQlTransactionBuilderLike

Implementation of​

TransactionBuilderLike.withGraphqlClient


fromProgrammableTransaction()​

static fromProgrammableTransaction(ptb): TransactionBuilderLike;

Create a transaction builder from a programmable transaction.

The returned builder has the original inputs and commands but no sender, gas payment, sponsor, or expiration; the sender defaults to the zero address and must be set via sender before finish is called.

Returns an error if a command refers to an input the transaction does not have or to the result of a command that does not come before it.

Parameters​

ptb​

ProgrammableTransactionLike

Returns​

TransactionBuilderLike


fromTransaction()​

static fromTransaction(transaction): TransactionBuilderLike;

Reconstruct a transaction builder from a finalized transaction. Calling finish on the returned builder produces a transaction equal to the input.

Only programmable transactions are supported; other transaction kinds will return an error.

Parameters​

transaction​

TransactionLike

Returns​

TransactionBuilderLike


instanceOf()​

static instanceOf(obj_): obj_ is TransactionBuilder;

Parameters​

obj_​

any

Returns​

obj_ is TransactionBuilder