TransactionBuilderProtocol
TransactionBuilderProtocol Objects
class TransactionBuilderProtocol(typing.Protocol)
A builder for creating transactions. Use finish to finalize the transaction data.
authorize_upgrade
def authorize_upgrade(upgrade_capability: PtbArgument,
upgrade_policy: UpgradePolicy, digest: Digest,
upgrade_ticket_name: str) -> TransactionBuilder
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.
commit_upgrade
def commit_upgrade(upgrade_capability: PtbArgument,
upgrade_receipt: PtbArgument) -> TransactionBuilder
Commit a package upgrade by calling 0x2::package::commit_upgrade, consuming the
UpgradeReceipt returned by TransactionBuilder::upgrade().
divide_coin
def divide_coin(
coin: PtbArgument,
count: int,
coin_type: typing.Union[object, typing.Optional[TypeTag]] = _DEFAULT
) -> TransactionBuilder
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.
execute_with_gas_station
async def execute_with_gas_station(
gas_station: GasStation,
signer: TransactionSigner) -> TransactionDigest
Execute the transaction with its gas paid by gas_station, returning the transaction
digest.
expiration
def expiration(epoch: int) -> TransactionBuilder
Set the expiration of the transaction to be a specific epoch.
finish
def finish() -> Transaction
Convert this builder into a transaction.
gas
def gas(object_refs: typing.List[ObjectReference]) -> TransactionBuilder
Add gas coins that will be consumed. Optional.
gas_budget
def gas_budget(budget: int) -> TransactionBuilder
Set the gas budget for the transaction.
gas_price
def gas_price(price: int) -> TransactionBuilder
Set the gas price for the transaction.
make_move_vec
def make_move_vec(elements: typing.List[MoveArg], type_tag: TypeTag,
name: str) -> TransactionBuilder
Make a move vector from a list of elements. The elements must all be of the type indicated
by type_tag.
merge_coins
def merge_coins(
primary_coin: PtbArgument,
consumed_coins: typing.List[PtbArgument]) -> TransactionBuilder
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.
move_call
def move_call(
package: Address,
module: Identifier,
function: Identifier,
arguments: typing.Union[object, typing.List[PtbArgument]] = _DEFAULT,
type_args: typing.Union[object, typing.List[TypeTag]] = _DEFAULT,
names: typing.Union[object, typing.List[str]] = _DEFAULT
) -> TransactionBuilder
Call a Move function with the given arguments.
pay
def pay(coins: typing.List[PtbArgument],
payments: typing.List[Payment]) -> TransactionBuilder
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.
pay_iota
def pay_iota(payments: typing.List[Payment]) -> TransactionBuilder
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.
publish_package
def publish_package(package_data: MovePackageData,
upgrade_cap_name: str) -> TransactionBuilder
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 publisheddependencies: is the list of IDs of the transitive dependencies of the package
send_coins
def send_coins(
coins: typing.List[PtbArgument],
recipient: Address,
amount: typing.Union[object, typing.Optional[PtbArgument]] = _DEFAULT
) -> TransactionBuilder
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.
send_iota
def send_iota(recipient: Address, amount: PtbArgument) -> TransactionBuilder
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.
sender
def sender(sender: Address) -> TransactionBuilder
Set the sender address.
split_coins
def split_coins(
coin: PtbArgument,
amounts: typing.List[PtbArgument],
names: typing.Union[object, typing.List[str]] = _DEFAULT
) -> TransactionBuilder
Split a coin by the provided amounts.
sponsor
def sponsor(sponsor: Address) -> TransactionBuilder
Set the sponsor of the transaction.
stake
def stake(stake: PtbArgument,
validator_address: Address) -> TransactionBuilder
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.
transfer_objects
def transfer_objects(recipient: Address,
objects: typing.List[PtbArgument]) -> TransactionBuilder
Transfer a list of objects to the given address, without producing any result.
unstake
def unstake(staked_iota: PtbArgument) -> TransactionBuilder
Withdraw stake from a validator's staking pool.
upgrade
def upgrade(
package_id: ObjectId,
package_data: MovePackageData,
upgrade_ticket: PtbArgument,
name: typing.Union[object, typing.Optional[str]] = _DEFAULT
) -> TransactionBuilder
Upgrade a Move package.
modules: is the modules' bytecode for the modules to be publisheddependencies: is the list of IDs of the transitive dependencies of the package to be upgradedpackage: is the ID of the current package being upgradedticket: 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().
upgrade_package
def upgrade_package(package_id: ObjectId, package_data: MovePackageData,
upgrade_capability: PtbArgument,
upgrade_policy: UpgradePolicy) -> TransactionBuilder
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.
with_graphql_client
def with_graphql_client(client: GraphQlClient) -> GraphQlTransactionBuilder
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.
with_grpc_client
def with_grpc_client(client: GrpcClient) -> GrpcTransactionBuilder
Use a gRPC 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.