export interface Tx {
addSignature(
signature: Signature,
verify?: boolean
): Tx
addSignatures(
signatures: Signature[],
verify?: boolean
): Tx
body: TxBody
calcMinCollateral(
params: NetworkParams,
recalcMinBaseFee?: boolean
): bigint
calcMinFee(params: NetworkParams): bigint
calcSize(forFeeCalculation?: boolean): number
clearMetadata(): Tx
dump(): any
hasValidationError: undefined
| string
| false
| UplcRuntimeError
id(): TxId
isSmart(): boolean
isValid(): boolean
isValidSlot(slot: bigint): boolean
kind: "Tx"
metadata: undefined | TxMetadata
recover(network: {getUtxo(id: TxOutputId): Promise<TxInput<SpendingCredential>>}): Promise<void>
toCbor(forFeeCalculation?: boolean): number[]
validate(
params: NetworkParams,
options?: TxValidationOptions
): void
validateSignatures(): void
validateUnsafe(
params: NetworkParams,
options?: TxValidationOptions
): Tx
witnesses: TxWitnesses
}
Represents a Cardano transaction. For transaction-building, see
TxBuilder instead.
Properties
addSignature
addSignature(
signature: Signature,
verify?: boolean
): Tx
Adds a signature created by a wallet. Only available after the transaction has been finalized.
Optionally verifies that the signature is correct (defaults to true)
addSignatures
addSignatures(
signatures: Signature[],
verify?: boolean
): Tx
Adds multiple signatures at once. Only available after the transaction has been finalized.
Optionally verifies each signature is correct (defaults to true)
body
body: TxBody
calcMinCollateral
calcMinCollateral(
params: NetworkParams,
recalcMinBaseFee?: boolean
): bigint
Returns a quantity in lovelace
calcMinFee
calcMinFee(params: NetworkParams): bigint
Returns a quantity in lovelace
calcSize
calcSize(forFeeCalculation?: boolean): number
Number of bytes of CBOR encoding of Tx
Is used for two things:
- tx fee calculation
- tx size validation
clearMetadata(): Tx
Creates a new Tx without the metadata for client-side signing where the client can't know the metadata before tx-submission.
dump
hasValidationError
hasValidationError: undefined
| string
| false
| UplcRuntimeError
Indicates if a built transaction has passed all consistency checks.
null
if the transaction hasn't been validated yet
false
when the transaction is valid
- a
string
with the error message if any validation check failed
- a UplcRuntimeError in case of any UPLC script failure
id(): TxId
isSmart
isValid
Indicates if the necessary signatures are present and valid
isValidSlot
isValidSlot(slot: bigint): boolean
Used by emulator to check if tx is valid.
kind
metadata: undefined | TxMetadata
recover
recover(network: {getUtxo(id: TxOutputId): Promise<TxInput<SpendingCredential>>}): Promise<void>
Restores input information after deserializing a CBOR-encoded transaction
A serialized tx throws away input information
This must be refetched from the network if the tx needs to be analyzed
toCbor
toCbor(forFeeCalculation?: boolean): number[]
Serializes a transaction.
Note: Babbage still follows Alonzo for the Tx size fee.
According to
https://github.com/IntersectMBO/cardano-ledger/blob/cardano-ledger-spec-2023-04-03/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs#L316,
the
isValid
field is omitted when calculating the size of the tx for fee calculation. This is to stay compatible with Mary (?why though, the txFeeFixed could've been changed instead?)
validate
validate(
params: NetworkParams,
options?: TxValidationOptions
): void
Throws an error if the tx isn't valid
Checks that are performed:
- size of tx <= params.maxTxSize
- body.fee >= calculated min fee
- value is conserved (minus what is burned, plus what is minted)
- enough collateral if smart
- no collateral if not smart
- all necessary scripts are attached
- no redundant scripts are attached (only checked if strict=true)
- each redeemer must have enough ex budget
- total ex budget can't exceed max tx ex budget for either mem or cpu
- each output contains enough lovelace (minDeposit)
- the assets in the output values are correctly sorted (only checked if strict=true, because only needed by some wallets)
- inputs are in the correct order
- ref inputs are in the correct order
- minted assets are in the correct order
- staking withdrawals are in the correct order
- metadatahash corresponds to metadata
- metadatahash is null if there isn't any metadata
- script data hash is correct
Checks that aren't performed:
- all necessary signatures are included (must done after tx has been signed)
- validity time range, which can only be checked upon submission
validateSignatures
validateSignatures(): void
Throws an error if all necessary signatures haven't yet been added
Separate from the other validation checks
If valid: this.valid is mutated to true
validateUnsafe
validateUnsafe(
params: NetworkParams,
options?: TxValidationOptions
): Tx
Validates the transaction without throwing an error if it isn't valid
If the transaction doesn't validate, the tx's
validationError
will be set
witnesses
witnesses: TxWitnesses