Skip to main content

Tx

Represents a balanced transaction.

Associated functions​

from_data​

Tx::from_data(data: Data) -> Tx

new​

Construct a Tx instance.

Tx::new(
inputs: []TxInput,
ref_inputs: []TxInput,
outputs: []TxOutput,
fee: Value,
minted: Value,
dcerts: []DCert,
withdrawals: Map[StakingCredential]Int,
time_range: TimeRange,
signatories: []PubKeyHash,
redeemers: Map[ScriptPurpose]AnyType,
datums: Map[DatumHash]AnyType,
id: TxId
) -> Tx

Note: the value type of the redeemers and datums fields can be any type when instantiating a new Tx instance. But when getting the redeemers and the datums the value type is actually Data (see redeemers and datums).

Getters​

inputs​

Returns the list of TxInputs of the transaction.

tx.inputs -> []TxInput

ref_inputs​

Returns the list of reference inputs (as []TxInput) of the transaction.

tx.ref_inputs -> []TxInput

outputs​

Returns the list of TxOutputs of the transaction.

tx.outputs -> []TxOutput

fee​

Returns the fee Value paid for the transaction.

tx.fee -> Value

minted​

Returns the Value minted by the transaction.

tx.minted -> Value

dcerts​

Returns the list of DCerts of the transaction (i.e. list of staking certifying actions).

tx.dcerts -> []DCert

withdrawals​

Returns a map of staking reward withdrawals. The map value Ints are lovelace quantities.

tx.withdrawals -> Map[StakingCredential]Int

time_range​

Returns the valid TimeRange of the transaction. This TimeRange must contain the current time.

tx.time_range -> TimeRange

Note: we can't access the current time from within the validator script because it would lead to differing evaluation results as the tx propagates across the network. Instead we can use tx.time_range as an approximation of the current time.

signatories​

Returns the list of explicit transaction signers as []PubKeyHash.

tx.signatories -> []PubKeyHash

redeemers​

Returns all the redeemers of the transaction as a map with ScriptPurpose keys, and Data values. This allows more complex interactions between different scripts being used in the same transaction.

tx.redeemers -> Map[ScriptPurpose]Data

datums​

Returns a Map of DatumHashes to raw Data. This can be used to get the datum content of any TxInput that doesn't use inline datums.

tx.datums -> Map[DatumHash]Data

id​

Returns the hash of the current transaction as TxId.

tx.id -> TxId

Operators​

==

Tx == Tx -> Bool

!=​

Tx != Tx -> Bool

Methods​

serialize​

tx.serialize() -> ByteArray

is_signed_by​

Returns true if the transaction was signed by the given pubkeyhash.

tx.is_signed_by(pubkeyhash: PubKeyHash) -> Bool

find_datum_hash​

Returns the DatumHash of datum data used in one the UTxO inputs.

tx.find_datum_hash(data: AnyType) -> ByteArray

get_datum_data​

Returns the datum Data of a TxOutput. Throws an error if no datum is attached to the output.

tx.get_datum_data(output: TxOutput) -> Data

outputs_sent_to​

Returns the TxOutputs sent to a regular payment address.

tx.outputs_sent_to(pkh: PubKeyHash) -> []TxOutput

outputs_sent_to_datum​

Returns the TxOutputs sent to a regular payment address tagged with the given datum (datum tagging can be used to prevent double satisfaction exploits).

tx.outputs_sent_to_datum(
pkh: PubKeyHash,
datum: AnyType,
is_inline: Bool
) -> []TxOutput

outputs_locked_by​

Returns the TxOutputs being locked at the given script address.

tx.outputs_locked_by(script_hash: ValidatorHash) -> []TxOutput

outputs_locked_by_datum​

Returns the TxOutputs being locked at the given script address with the given datum.

tx.outputs_locked_by_datum(
script_hash: ValidatorHash,
datum: AnyType,
is_inline: Bool
) -> []TxOutput

value_paid_to​

Returns the output Value sent to a generic payment address, with a specific inline datum.

tx.value_paid_to[InlineDatumDataType](
address: Address,
datum: InlineDatumDataType
) -> Value

value_sent_to​

Returns the output Value sent to a regular payment address.

tx.value_sent_to(addr: PubKeyHash) -> Value

value_sent_to_datum​

Returns the output Value sent to a regular payment address tagged with the given datum (datum tagging can be used to prevent double satisfaction exploits).

tx.value_sent_to_datum(
addr: PubKeyHash,
datum: AnyType,
is_inline: Bool
) -> Value

value_locked_by​

Returns the output Value being locked at the given script address.

tx.value_locked_by(script_hash: ValidatorHash) -> Value

value_locked_by_datum​

Returns the output Value being locked at the given script address with the given datum.

tx.value_locked_by_datum(
script_hash: ValidatorHash,
datum: AnyType,
is_inline: Bool
) -> Value