Cardano.TxContext

Context available to the Tx builder to create redeemers and datums. Very similar to the Plutus script context, but available offchain.

type alias TxContext =
{ fee : Natural
, validityRange :
{ start : Maybe Int
, end : Maybe Natural
}
, inputs : List ( OutputReference, Output )
, referenceInputs : List ( OutputReference, Output )
, outputs : List Output
, mint : MultiAsset Integer
, certificates : List Certificate
, withdrawals : List ( StakeAddress, Natural )
, votes : List ( Voter, List ( ActionId, VotingProcedure ) )
, proposals : List ProposalProcedure
, requiredSigners : List (Bytes CredentialHash)
, redeemers : List Redeemer
, currentTreasuryValue : Maybe Natural
, treasuryDonation : Maybe Natural
}

Some context available to the Tx builder to create redeemers and datums.

The contents of the TxContext are very similar to those of the Plutus script context. This is because the goal is to help pre-compute offchain elements that will make onchain code more efficient.

For example, you could pre-compute indexes of elements in inputs list, or the redeemers list in the script context for faster onchain lookups. For this reason, lists in this TxContext are ordered the same as in the Plutus script context.

new : TxContext

Empty TxContext for initializations.

fromTx : RefDict Output -> Transaction -> TxContext

Create a TxContext from a pre-existing transaction.

WARNING: currently, this function makes the assumption that all List fields in the transaction are already sorted correctly. This assumption is valid within the Tx builder.

{ preSelectedInputs : RefDict Output
, preCreatedOutputs :
TxContext
-> { sum : Value
, outputs : List Output
}
}
-> { selectedUtxos : RefDict Output
, changeOutputs : List Output
}
-> TxContext
-> TxContext

Helper function to update the TxContext inputs and outputs after coin selection.

Reference inputs do not change with UTxO selection, only spent inputs. Inputs are sorted by output ref.