TxBuilder

scalus.cardano.txbuilder.TxBuilder
See theTxBuilder companion object
case class TxBuilder(env: Environment, context: Context, evaluator: PlutusScriptEvaluator, diffHandlerOpt: Option[DiffHandler] = ..., steps: Seq[TransactionBuilderStep] = ..., attachedScripts: Map[ScriptHash, Script] = ..., attachedData: Map[DataHash, Data] = ..., changeAddressOpt: Option[Address] = ..., providerOpt: Option[Provider] = ...)

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def attach(script: Script): TxBuilder

Attaches a script to the transaction witness set.

Attaches a script to the transaction witness set.

Use this method to make scripts available for spending script-locked UTXOs or minting tokens. The script will be included in the transaction's witness set.

Value parameters

script

the script to attach

Attributes

def attach(data: Data): TxBuilder

Attaches datum data to the transaction witness set.

Attaches datum data to the transaction witness set.

Use this method when sending to an address with a datum hash (via payTo). The datum will be included in the transaction's witness set and can be referenced by its hash.

Value parameters

data

the datum to attach

Attributes

def build(): TxBuilder
def changeTo(address: Address): TxBuilder
def collaterals(utxo: Utxo, rest: Utxo*): TxBuilder

Adds the specified utxos to the list of collateral inputs.

Adds the specified utxos to the list of collateral inputs.

Collateral inputs are used to cover transaction fees if script execution fails. They are only consumed if a script fails validation.

Attributes

def collaterals(utxos: Utxos): TxBuilder

Adds the specified utxos to the list of collateral inputs.

Adds the specified utxos to the list of collateral inputs.

Collateral inputs are used to cover transaction fees if script execution fails. They are only consumed if a script fails validation.

Attributes

def metadata(auxiliaryData: AuxiliaryData): TxBuilder

Adds transaction metadata (auxiliary data).

Adds transaction metadata (auxiliary data).

Metadata is optional data attached to a transaction that does not affect validation but can be used for off-chain purposes.

Value parameters

auxiliaryData

the auxiliary data to attach

Attributes

def minFee(minFee: Coin): TxBuilder
def mint[T : ToData](redeemer: T, policyId: PolicyId, assets: Map[AssetName, Long]): TxBuilder
def mint[T : ToData](redeemer: T, assets: Map[AssetName, Long], script: PlutusScript): TxBuilder

Adds the specified output to the list of transaction outputs.

Adds the specified output to the list of transaction outputs.

Use this method for fine-grained control over output construction. For simpler cases, use payTo.

Value parameters

output

the transaction output to add

Attributes

def payTo(address: Address, value: Value): TxBuilder

Sends the specified value to the given address without a datum.

Sends the specified value to the given address without a datum.

Value parameters

address

recipient address

value

amount to send

Attributes

def payTo[T : ToData](address: Address, value: Value, datum: T): TxBuilder

Sends the specified value to the given address with an inline datum.

Sends the specified value to the given address with an inline datum.

Value parameters

address

recipient address

datum

inline datum to attach to the output

value

amount to send

Attributes

def payTo(address: Address, value: Value, datumHash: DataHash): TxBuilder

Sends the specified value to the given address with a datum hash.

Sends the specified value to the given address with a datum hash.

Make sure to call attach with the corresponding datum data before calling build.

Value parameters

address

recipient address

datumHash

hash of the datum (the actual datum must be attached via attach)

value

amount to send

Attributes

def references(utxo: Utxo, rest: Utxo*): TxBuilder

Adds the specified utxos to the list of reference inputs.

Adds the specified utxos to the list of reference inputs.

Reference inputs allow scripts to read UTXOs without consuming them.

Attributes

def sign(signer: TransactionSigner, rest: TransactionSigner*): Either[Throwable, TxBuilder]
def spend(utxo: Utxo): TxBuilder

Adds the specified pubkey utxo to the list of inputs, thus spending it.

Adds the specified pubkey utxo to the list of inputs, thus spending it.

If the sum of outputs exceeds the sum of spent inputs, the change is going to be handled according to changeTo or diffHandler.

Value parameters

utxo

utxo to spend

Attributes

Note

use spend with utxo and redeemer to spend script protected utxos. Otherwise, build throws.

def spend(utxos: Utxos): TxBuilder

Adds the specified pubkey utxos to the list of inputs, thus spending them.

Adds the specified pubkey utxos to the list of inputs, thus spending them.

If the sum of outputs exceeds the sum of spent inputs, the change is going to be handled according to changeTo or diffHandler.

Value parameters

utxos

utxos to spend

Attributes

Note

use spend with utxo and redeemer to spend script protected utxos. Otherwise, build throws.

def spend[T : ToData](utxo: Utxo, redeemer: T): TxBuilder

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set.

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set.

Make sure to also call attach with the script that locks these utxos. If the script that protects the utxo fails with the specified redeemer, build is going to throw.

If the sum of outputs exceeds the sum of spent inputs, the change is going to be handled according to changeTo or diffHandler.

Value parameters

redeemer

redeemer to pass to the script to unlock the inputs

utxo

utxo to spend

Attributes

def spend(utxo: Utxo, redeemerBuilder: Transaction => Data): TxBuilder
def spend[T : ToData](utxo: Utxo, redeemer: T, script: PlutusScript): TxBuilder

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set.

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set.

If the specified script fails with the specified redeemer`, build is going to throw.

If the sum of outputs exceeds the sum of spent inputs, the change is going to be handled according to changeTo or diffHandler.

Value parameters

redeemer

redeemer to pass to the script to unlock the inputs

script

script that protects the utxo

utxo

utxo to spend

Attributes

def spend[T : ToData](utxo: Utxo, redeemer: T, script: PlutusScript, additionalSigners: Set[AddrKeyHash]): TxBuilder

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set, with additional required signers.

Adds the specified script protected utxo to the list of inputs and the specified redeemer to the witness set, with additional required signers.

Use this method when the validator script requires specific signatures beyond the spender. The public key hashes in additionalSigners will be added to the transaction's required signers field.

If the specified script fails with the specified redeemer, build is going to throw.

If the sum of outputs exceeds the sum of spent inputs, the change is going to be handled according to changeTo or diffHandler.

Value parameters

additionalSigners

set of public key hashes that must sign the transaction

redeemer

redeemer to pass to the script to unlock the inputs

script

script that protects the utxo

utxo

utxo to spend

Attributes

def validFrom(from: Instant): TxBuilder
def validTo(to: Instant): TxBuilder

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product