Skip to content

TxBuilder

Extends: RefCounted

Description

The TxBuilder, which is a balanced and evaluated transaction that can be subsequently signed and submitted.

The TxBuilder, which is a balanced and evaluated transaction that can be subsequently signed and submitted.

Constants Descriptions

TxBuilderStatus

enum TxBuilderStatus{SUCCESS = 0, BAD_PROTOCOL_PARAMETERS = 1, QUANTITY_EXCEEDS_MAXIMUM = 2, DESERIALIZE_ERROR = 3, BYRON_ADDRESS_UNSUPPORTED = 4, COULD_NOT_GET_KEY_HASH = 5, UNKNOWN_REDEEMER_INDEX = 6, UNEXPECTED_COLLATERAL_AMOUNT = 7, OTHER_ERROR = 8, CREATE_ERROR = 9, INVALID_DATA = 10, NO_UTXOS = 11, NO_CHANGE_ADDRESS = 12, COMPLETE_ERROR = 13}

Method Descriptions

_init

func _init(provider: Provider, builder: _TxBuilder) -> TxBuilder

You should not create a TxBuilder).

set_slot_config

func set_slot_config(start_time: int, start_slot: int, slot_length: int) -> TxBuilder

Set the slot configuration. This is automatically done on initialization, do not use unless you know what you are doing.

set_cost_models

func set_cost_models(cost_models: CostModels) -> TxBuilder

Set the cost models. This is automatically done on initialization, do not use unless you know what you are doing.

pay_to_address

func pay_to_address(address: Address, coin: BigInt, assets: MultiAsset = null, datum: PlutusData = null, script_ref: PlutusScript = null, hash_datum: bool = false) -> TxBuilder

Pay to a given [param address]. [param coin] specifies the quantity of lovelace to transfer, while the optional parameter [param assets] specifies any additional assets to transfer.[br] May optionally include a [param datum] and [param script_ref], and a flag [param hash_datum] determining whether the provided datum should be inline. NOTE: If [param assets] contains ADA it will be added to the amount set by [param coin].

pay_to_address_with_datum_hash

func pay_to_address_with_datum_hash(address: Address, coin: BigInt, assets: MultiAsset, datum: PlutusData, script_ref: PlutusScript = null) -> TxBuilder

Similar to [method pay_to_address], but it also takes a [param datum] argument that will be used to embed the datum hash in the transaction. [param datum] should be convertable to PlutusData.

mint_assets

func mint_assets(minting_policy_source: PlutusScriptSource, tokens: Array[MintToken], redeemer: PlutusData) -> TxBuilder

Mint tokens with the given [param minting_policy] and using the a list of specs defined in [param tokens]. A [param redeemer] is also required for the minting policy.

mint_cip68_pair

func mint_cip68_pair(redeemer: PlutusData, conf: Cip68Config) -> TxBuilder

Mint a pair of CIP68 user and reference tokens using the given [param redeemer] and minting configuration in [param conf].

mint_cip68_user_tokens

func mint_cip68_user_tokens(redeemer: PlutusData, conf: Cip68Config, quantity: BigInt = null) -> TxBuilder

Mint user tokens for a given [param conf]. This should generally be used for fungible tokens after the initial mint has been performed by [method mint_cip68_pair].

pay_cip68_ref_token

func pay_cip68_ref_token(address: Address, conf: Cip68Config) -> TxBuilder

Pay the CIP68 reference token specified by [param minting_policy] and [param conf] to the given [param address].

pay_cip68_user_tokens

func pay_cip68_user_tokens(address: Address, conf: Cip68Config, quantity: BigInt = null) -> TxBuilder

Pay the CIP68 user tokens specified by [param minting_policy] and [param conf] to the given [param address].

pay_cip68_user_tokens_with_datum

func pay_cip68_user_tokens_with_datum(address: Address, datum: PlutusData, conf: Cip68Config, quantity: BigInt = null) -> TxBuilder

Pay the CIP68 user tokens specified by [param minting_policy] and [param conf] to the given [param address]. The output will contain a [param datum].

collect_from

func collect_from(utxos: Array[Utxo]) -> TxBuilder

Consume all the [param utxos] specified.

collect_from_script

func collect_from_script(plutus_script_source: PlutusScriptSource, utxos: Array[Utxo], redeemer: PlutusData) -> TxBuilder

Consume all the [param utxos] locked by the [param plutus_script_source] using the provided [param redeemer].

set_change_address

func set_change_address(change_address: Address) -> TxBuilder

When the transaction is balanced (usually when [method complete] is called), send any change to the provided [param change_address].

set_wallet

func set_wallet(wallet: OnlineWallet) -> TxBuilder

Use the provided [param wallet] for balancing. This automatically sets the change address to that wallet's address.

valid_after

func valid_after(time: int) -> TxBuilder

Set the time in POSIX seconds after which the transaction is valid

valid_before

func valid_before(time: int) -> TxBuilder

Set the time in POSIX seconds before which the transaction is valid

add_required_signer

func add_required_signer(pub_key_hash: PubKeyHash) -> TxBuilder

Add a required signer constraint to the transaction.

add_reference_input

func add_reference_input(utxo: Utxo) -> TxBuilder

Add a [param utxo] as a reference input. This input will not be consumed but will be available in the script evaluation context.

balance

func balance(utxos: Array[Utxo] = null) -> BalanceResult

Only balance the transaction and return the result.[br]The resulting transaction will not have been evaluated and will have inaccurate script execution units, which may cause the transaction to fail at submission and potentially consume the provided collateral.[br][br]Do not use this function unless you know what you are doing.

complete

func complete(utxos: Array[Utxo] = null) -> CompleteResult

Attempts to balance and evaluate the transaction. The provided [param utxos] can be used for balancing the transaction.

create (static)

func create(provider: Provider) -> CreateResult

TODO: This probably shouldn't be exposed. Create a TxBuilder object from a Provider. You should use [method Provider.new_tx] instead of this method, since that one will make sure to initialize other necessary fields.

Sub-classes

CreateResult

Property Descriptions

value

var value: TxBuilder
  • Getter: @value_getter

WARNING: This function may fail! First match on tag or call is_ok.

error

var error: String
  • Getter: @error_getter

WARNING: This function may fail! First match on tag or call is_err.

Method Descriptions

_init

func _init(provider: Provider, res: _Result) -> CreateResult

BalanceResult

Property Descriptions

value

var value: Transaction
  • Getter: @value_getter

WARNING: This function may fail! First match on tag or call is_ok.

error

var error: String
  • Getter: @error_getter

WARNING: This function may fail! First match on tag or call is_err.

Method Descriptions

_init

func _init(res: _Result) -> BalanceResult

CompleteResult

Property Descriptions

value

var value: TxComplete
  • Getter: @value_getter

WARNING: This function may fail! First match on tag or call is_ok.

error

var error: String
  • Getter: @error_getter

WARNING: This function may fail! First match on tag or call is_err.

Method Descriptions

_init

func _init(provider: Provider, res: _Result, wallet: OnlineWallet = null, input_utxos: Array[Utxo] = null) -> CompleteResult

MintToken

Method Descriptions

_init

func _init(asset_name: AssetName, quantity: BigInt) -> MintToken