TransactionBody
- class cometa.transaction_body.transaction_body.TransactionBody(ptr)[source]
Bases:
objectRepresents the body of a Cardano transaction.
The transaction body encapsulates the core details of a transaction including: - Inputs: The UTXOs being spent - Outputs: Where the funds are being sent - Fee: The transaction fee in lovelace - TTL: Optional time-to-live (slot number after which tx is invalid) - Various optional fields for certificates, withdrawals, minting, etc.
- classmethod new(inputs, outputs, fee, ttl=None)[source]
Creates a new TransactionBody.
- Parameters:
inputs (TransactionInputSet | List[TransactionInput]) – The set of transaction inputs (UTXOs being spent). Can be a TransactionInputSet or a Python list of TransactionInput.
outputs (TransactionOutputList | List[TransactionOutput]) – The list of transaction outputs. Can be a TransactionOutputList or a Python list of TransactionOutput.
fee (int) – The transaction fee in lovelace.
ttl (int | None) – Optional time-to-live slot number.
- Returns:
A new TransactionBody instance.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> # Using Python lists directly >>> input1 = TransactionInput.from_hex(tx_hash, 0) >>> output1 = TransactionOutput.new(address, 1000000) >>> body = TransactionBody.new([input1], [output1], 200000)
- classmethod from_cbor(reader)[source]
Deserializes a TransactionBody from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the transaction body data.
- Returns:
A new TransactionBody deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
Note
The original CBOR encoding is cached internally to preserve the exact representation and avoid invalidating signatures when re-serializing.
- to_cbor(writer)[source]
Serializes the transaction body to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
Note
If this transaction body was created from CBOR, the cached original encoding is used to preserve the exact representation.
- clear_cbor_cache()[source]
Clears the cached CBOR representation.
After calling this, to_cbor will serialize the transaction body fresh rather than using the cached original encoding.
- Return type:
None
- to_cip116_json(writer)[source]
Serializes this transaction body to CIP-116 JSON format.
CIP-116 defines a standard JSON representation for Cardano transactions.
- Parameters:
writer – A JsonWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
Example
>>> from cometa.json import JsonWriter >>> body = TransactionBody.new(inputs, outputs, 200000) >>> writer = JsonWriter() >>> body.to_cip116_json(writer) >>> json_str = writer.encode()
- property hash: Blake2bHash
The Blake2b-256 hash of the transaction body.
This hash is used for signing and uniquely identifies the transaction.
- Returns:
The transaction body hash.
- property inputs: TransactionInputSet
The set of transaction inputs (UTXOs being spent).
- Returns:
The TransactionInputSet containing all inputs.
- property outputs: TransactionOutputList
The list of transaction outputs.
- Returns:
The TransactionOutputList containing all outputs.
- property fee: int
The transaction fee in lovelace.
- Returns:
The fee amount.
- property invalid_after: int | None
The TTL (time-to-live) slot number.
The transaction is invalid if not included in a block by this slot.
- Returns:
The TTL slot number, or None if not set.
- property invalid_before: int | None
The validity start slot number.
The transaction is invalid before this slot.
- Returns:
The validity start slot number, or None if not set.
- property certificates: CertificateSet | None
The set of certificates included in the transaction.
- Returns:
The CertificateSet if present, None otherwise.
- property withdrawals: WithdrawalMap | None
The stake rewards withdrawals in this transaction.
- Returns:
The WithdrawalMap if present, None otherwise.
- property update: Update | None
The protocol parameter update proposal.
- Returns:
The Update if present, None otherwise.
- property aux_data_hash: Blake2bHash | None
The hash of the auxiliary data.
- Returns:
The auxiliary data hash if present, None otherwise.
- property mint: MultiAsset | None
The multi-asset minting/burning operations.
- Returns:
The MultiAsset representing minting operations, None if not present.
- property script_data_hash: Blake2bHash | None
The hash of the script data (redeemers + datums + cost models).
- Returns:
The script data hash if present, None otherwise.
- property collateral: TransactionInputSet | None
The collateral inputs for Plutus script execution.
- Returns:
The TransactionInputSet of collateral inputs, None if not present.
- property required_signers: Blake2bHashSet | None
The set of required signers (key hashes).
- Returns:
The Blake2bHashSet of required signers, None if not present.
- property network_id: NetworkId | None
The explicit network ID for this transaction.
- Returns:
The NetworkId if set, None otherwise.
- property collateral_return: TransactionOutput | None
The collateral return output (change from collateral).
- Returns:
The TransactionOutput for collateral return, None if not present.
- property total_collateral: int | None
The total collateral amount in lovelace.
- Returns:
The total collateral, or None if not set.
- property reference_inputs: TransactionInputSet | None
The reference inputs (read-only, not consumed).
- Returns:
The TransactionInputSet of reference inputs, None if not present.
- property voting_procedures: VotingProcedures | None
The voting procedures for governance actions.
- Returns:
The VotingProcedures if present, None otherwise.
- property proposal_procedures: ProposalProcedureSet | None
The proposal procedures for governance actions.
- Returns:
The ProposalProcedureSet if present, None otherwise.
- property treasury_value: int | None
The treasury value for this transaction.
- Returns:
The treasury value in lovelace, or None if not set.
- property donation: int | None
The donation amount to the treasury.
- Returns:
The donation amount in lovelace, or None if not set.