Skip to main content

TxBody

Note: inputs, minted assets, and withdrawals need to be sorted in order to form a valid transaction

export interface TxBody {
  allScriptHashes: ScriptHash<unknown>[]
  collateral: TxInput<SpendingCredential>[]
  collateralReturn: undefined | TxOutput<SpendingCredential>
  countUniqueSigners(): number
  dcerts: DCert[]
  dump(): any
  encodingConfig: TxBodyEncodingConfig
  fee: bigint
  firstValidSlot: undefined | number
  getValidityTimeRange(params: NetworkParams): TimeRange
  hash(): number[]
  inputs: TxInput<SpendingCredential>[]
  isValidSlot(slot: IntLike): boolean
  kind: "TxBody"
  lastValidSlot: undefined | number
  metadataHash: undefined | number[]
  minted: Assets
  outputs: TxOutput<SpendingCredential>[]
  recover(network: {getUtxo(id: TxOutputId): Promise<TxInput<SpendingCredential>>}): Promise<void>
  refInputs: TxInput<SpendingCredential>[]
  scriptDataHash: undefined | number[]
  signers: PubKeyHash[]
  sortOutputs(): void
  sumInputAndMintedAssets(): Assets
  sumInputAndMintedValue(): Value
  sumInputValue(): Value
  sumOutputAssets(): Assets
  sumOutputValue(): Value
  toCbor(): number[]
  totalCollateral: bigint
  toTxInfo(
    params: NetworkParams,
    redeemers: TxRedeemer[],
    datums: UplcData[],
    txId: TxId
  ): TxInfo
  withdrawals: [StakingAddress<StakingCredential>, bigint][]
}

Properties

allScriptHashes

Used to validate if all the necessary scripts are included TxWitnesses (and that there are not redundant scripts)

txBody.allScriptHashes satisfies ScriptHash<unknown>[]

collateral

txBody.collateral satisfies TxInput<SpendingCredential>[]

collateralReturn

txBody.collateralReturn satisfies undefined | TxOutput<SpendingCredential>

countUniqueSigners

Calculates the number of dummy signatures needed to get precisely the right tx size.

txBody.countUniqueSigners satisfies () => number

dcerts

txBody.dcerts satisfies DCert[]

dump

txBody.dump satisfies () => any

encodingConfig

txBody.encodingConfig satisfies TxBodyEncodingConfig

fee

txBody.fee satisfies bigint

firstValidSlot

txBody.firstValidSlot satisfies undefined | number

getValidityTimeRange

txBody.getValidityTimeRange satisfies (params: NetworkParams) => TimeRange

hash

The bytes that form the TxId

txBody.hash satisfies () => number[]

inputs

txBody.inputs satisfies TxInput<SpendingCredential>[]

isValidSlot

Used by (indirectly) by emulator to check if slot range is valid. Note: firstValidSlot == lastValidSlot is allowed

txBody.isValidSlot satisfies (slot: IntLike) => boolean

kind

txBody.kind satisfies "TxBody"

lastValidSlot

txBody.lastValidSlot satisfies undefined | number

metadataHash

txBody.metadataHash satisfies undefined | number[]

minted

Internally the assets must be sorted by mintingpolicyhash Minting redeemers must point to the sorted minted assets

txBody.minted satisfies Assets

outputs

txBody.outputs satisfies TxOutput<SpendingCredential>[]

recover

A serialized tx throws away input information This must be refetched from the network if the tx needs to be analyzed This must be done for the regular inputs because the datums are needed for correct budget calculation and min required signatures determination This must be done for the reference inputs because they impact the budget calculation This must be done for the collateral inputs as well, so that the minium required signatures can be determined correctly

txBody.recover satisfies (network: {getUtxo(id: TxOutputId): Promise<TxInput<SpendingCredential>>}) => Promise<void>

refInputs

txBody.refInputs satisfies TxInput<SpendingCredential>[]

scriptDataHash

txBody.scriptDataHash satisfies undefined | number[]

signers

txBody.signers satisfies PubKeyHash[]

sortOutputs

Not done in the same routine as sortInputs(), because balancing of assets happens after redeemer indices are set

txBody.sortOutputs satisfies () => void

sumInputAndMintedAssets

Excludes lovelace

txBody.sumInputAndMintedAssets satisfies () => Assets

sumInputAndMintedValue

Throws error if any part of the sum is negative (i.e. more is burned than input)

txBody.sumInputAndMintedValue satisfies () => Value

sumInputValue

txBody.sumInputValue satisfies () => Value

sumOutputAssets

Excludes lovelace

txBody.sumOutputAssets satisfies () => Assets

sumOutputValue

txBody.sumOutputValue satisfies () => Value

toCbor

txBody.toCbor satisfies () => number[]

totalCollateral

txBody.totalCollateral satisfies bigint

toTxInfo

Returns the on-chain Tx representation

txBody.toTxInfo satisfies (
  params: NetworkParams,
  redeemers: TxRedeemer[],
  datums: UplcData[],
  txId: TxId
) => TxInfo

withdrawals

Withdrawals must be sorted by address Stake rewarding redeemers must point to the sorted withdrawals

txBody.withdrawals satisfies [StakingAddress<StakingCredential>, bigint][]