Transaction

class cometa.transaction.transaction.Transaction(ptr)[source]

Bases: object

Represents a complete Cardano transaction.

A transaction is a record of value transfer between addresses on the network. It consists of: - Body: The core transaction data (inputs, outputs, fees, etc.) - Witness set: Cryptographic signatures and other witness data - Auxiliary data: Optional metadata - Is valid: Flag indicating expected Plutus script validation result

__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Transaction

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod new(body, witness_set, auxiliary_data=None)[source]

Creates a new Transaction.

Parameters:
  • body (TransactionBody) – The transaction body containing inputs, outputs, and fees.

  • witness_set (WitnessSet) – The witness set containing signatures and other witness data.

  • auxiliary_data (AuxiliaryData | None) – Optional auxiliary data (metadata, governance info).

Returns:

A new Transaction instance.

Raises:

CardanoError – If creation fails.

Return type:

Transaction

classmethod from_cbor(reader)[source]

Deserializes a Transaction from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the transaction data.

Returns:

A new Transaction deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

Transaction

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 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 was created from CBOR, the cached original encoding is used to preserve the exact representation.

serialize_to_cbor()[source]

Serializes the transaction to a CBOR hex string.

Returns:

A hex string representing the serialized CBOR data.

Raises:

CardanoError – If serialization fails.

Return type:

str

Note

If this transaction was created from CBOR, the cached original encoding is used to preserve the exact representation.

serialize_to_json()[source]

Serializes the transaction to a JSON string.

Returns:

A JSON string representing the transaction.

Raises:

CardanoError – If serialization fails.

Return type:

str

to_dict()[source]

Converts the transaction to a dictionary representation (follows CIP-116).

Returns:

A dictionary representing the transaction.

Raises:

CardanoError – If serialization fails.

Return type:

dict

clear_cbor_cache()[source]

Clears the cached CBOR representation.

After calling this, to_cbor will serialize the transaction fresh rather than using the cached original encoding.

Warning

This may change the binary representation and alter the transaction hash, invalidating any existing signatures.

Return type:

None

to_cip116_json(writer)[source]

Serializes this transaction 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
>>> tx = Transaction.new(body, witness_set)
>>> writer = JsonWriter()
>>> tx.to_cip116_json(writer)
>>> json_str = writer.encode()
property id: Blake2bHash

The transaction ID (Blake2b-256 hash of the transaction body).

This hash uniquely identifies the transaction on the blockchain.

Returns:

The transaction ID as a Blake2bHash.

property body: TransactionBody

The transaction body containing core transaction data.

Returns:

The TransactionBody.

property witness_set: WitnessSet

The witness set containing signatures and witness data.

Returns:

The WitnessSet.

property auxiliary_data: AuxiliaryData | None

The optional auxiliary data (metadata, governance info).

Returns:

The AuxiliaryData if present, None otherwise.

property is_valid: bool

Whether the transaction is expected to pass Plutus script validation.

A transaction with this flag set to False is expected to fail validation, but can still be submitted to the blockchain.

Returns:

True if expected to pass validation, False otherwise.

has_script_data()[source]

Checks if this transaction contains script data.

Script data includes redeemers or datums required for transactions involving Plutus scripts.

Returns:

True if the transaction contains script data, False otherwise.

Return type:

bool

apply_vkey_witnesses(vkey_witnesses)[source]

Applies verification key witnesses to this transaction.

Parameters:

vkey_witnesses – A VkeyWitnessSet containing the witnesses to apply.

Raises:

CardanoError – If applying witnesses fails.

Return type:

None

get_unique_signers(resolved_inputs=None)[source]

Extracts the unique set of public key hashes required to sign this transaction.

This method computes the required signers by analyzing the transaction body and an optional list of resolved input UTxOs.

Parameters:

resolved_inputs (Optional['UtxoList']) – An optional UtxoList containing the resolved UTxOs that are spent by the transaction. If None or empty, the function won’t resolve signers from inputs or collateral inputs. If provided, they must account for all inputs and collateral inputs in the transaction or the function will fail.

Returns:

A Blake2bHashSet containing the unique public key hashes (signers) required to authorize the transaction.

Raises:

CardanoError – If computing the unique signers fails.

Return type:

Blake2bHashSet

Example

>>> from cometa import Transaction, UtxoList, CborReader
>>> tx = Transaction.from_cbor(CborReader.from_hex(tx_cbor_hex))
>>> signers = tx.get_unique_signers(resolved_utxos)
>>> for signer in signers:
...     print(signer.to_hex())