Fee

cometa.transaction_builder.fee.compute_transaction_fee(transaction, resolved_ref_inputs=None, protocol_params=None)[source]

Compute the minimum transaction fee.

This function computes the minimum required transaction fee for the provided transaction, based on the resolved inputs and protocol parameters. The calculated fee considers factors such as the transaction size, execution units consumed by Plutus scripts, and size of included reference scripts.

Parameters:
  • transaction (Transaction) – The transaction to compute the fee for.

  • resolved_ref_inputs (Optional[Union['UtxoList', List['Utxo']]]) – Resolved UTXOs that will be referenced by the transaction.

  • protocol_params (Optional['ProtocolParameters']) – Protocol parameters for fee calculation.

Returns:

The computed transaction fee in lovelace.

Raises:

CardanoError – If fee computation fails.

Return type:

int

Example

>>> from cometa import Transaction
>>> from cometa.transaction_builder import compute_transaction_fee
>>> tx = Transaction.from_cbor(...)
>>> fee = compute_transaction_fee(tx, resolved_ref_inputs, params)

cometa.transaction_builder.fee.compute_min_ada_required(output, coins_per_utxo_byte)[source]

Compute the minimum ADA required for a transaction output.

This function calculates the minimum amount of ADA (in lovelace) that must be present in a UTXO, based on its size and the coins_per_utxo_byte parameter from the protocol.

Parameters:
  • output (TransactionOutput) – The transaction output to calculate minimum ADA for.

  • coins_per_utxo_byte (int) – Protocol parameter specifying cost in lovelace per byte.

Returns:

The minimum ADA required in lovelace.

Raises:

CardanoError – If computation fails.

Return type:

int

Example

>>> from cometa.transaction_body import TransactionOutput
>>> from cometa.transaction_builder import compute_min_ada_required
>>> output = TransactionOutput.new(address, 0)
>>> min_ada = compute_min_ada_required(output, 4310)

cometa.transaction_builder.fee.compute_min_script_fee(transaction, prices, resolved_reference_inputs=None, coins_per_ref_script_byte=None)[source]

Compute the minimum fee required for a transaction with Plutus scripts.

This function calculates the minimum fee required for a transaction that contains Plutus scripts. The fee is based on execution units, prices, and reference script sizes.

Parameters:
  • transaction (Transaction) – The transaction to calculate script fee for.

  • prices (ExUnitPrices) – Prices for execution units (memory and steps).

  • resolved_reference_inputs (Optional[Union['UtxoList', List['Utxo']]]) – Resolved UTXOs used by transaction reference inputs.

  • coins_per_ref_script_byte (Optional['UnitInterval']) – Cost per byte of reference scripts.

Returns:

The minimum script fee in lovelace.

Raises:

CardanoError – If computation fails.

Return type:

int


cometa.transaction_builder.fee.compute_min_fee_without_scripts(transaction, min_fee_constant, min_fee_coefficient)[source]

Compute the minimum fee for a transaction without considering script costs.

The fee is computed as:

min_fee = min_fee_constant + (min_fee_coefficient * tx_size)

where tx_size is the size of the transaction in bytes.

Parameters:
  • transaction (Transaction) – The transaction to calculate fee for.

  • min_fee_constant (int) – The constant fee factor (A) from protocol parameters.

  • min_fee_coefficient (int) – The fee-per-byte coefficient (B) from protocol parameters.

Returns:

The minimum fee in lovelace.

Raises:

CardanoError – If computation fails.

Return type:

int

Example

>>> fee = compute_min_fee_without_scripts(tx, 155381, 44)

cometa.transaction_builder.fee.compute_script_ref_fee(resolved_reference_inputs, coins_per_ref_script_byte)[source]

Compute the script reference fee for transaction inputs.

This function calculates the fee component contributed by reference scripts on the inputs of a transaction.

Parameters:
  • resolved_reference_inputs (Union['UtxoList', List['Utxo']]) – Resolved reference inputs containing reference scripts.

  • coins_per_ref_script_byte (UnitInterval) – Fee cost per byte of reference script data.

Returns:

The reference script fee in lovelace.

Raises:

CardanoError – If computation fails.

Return type:

int


cometa.transaction_builder.fee.get_total_ex_units_in_redeemers(redeemers)[source]

Compute the total execution units from a list of redeemers.

This function aggregates the total execution units consumed by all redeemers. Execution units include both memory and CPU units.

Parameters:

redeemers (RedeemerList) – The list of redeemers to aggregate.

Returns:

The total execution units (memory and CPU).

Raises:

CardanoError – If computation fails.

Return type:

ExUnits

Example

>>> total_units = get_total_ex_units_in_redeemers(redeemer_list)
>>> print(f"Memory: {total_units.mem}, Steps: {total_units.steps}")

cometa.transaction_builder.fee.get_serialized_coin_size(lovelace)[source]

Compute the serialized size of a given amount of lovelace.

Parameters:

lovelace (int) – The amount of lovelace.

Returns:

The size in bytes required to serialize the lovelace amount.

Raises:

CardanoError – If computation fails.

Return type:

int


cometa.transaction_builder.fee.get_serialized_output_size(output)[source]

Compute the serialized size of a transaction output.

Parameters:

output (TransactionOutput) – The transaction output.

Returns:

The size in bytes required to serialize the output.

Raises:

CardanoError – If computation fails.

Return type:

int


cometa.transaction_builder.fee.get_serialized_script_size(script)[source]

Compute the serialized size of a script.

Parameters:

script (Script) – The script object.

Returns:

The size in bytes required to serialize the script.

Raises:

CardanoError – If computation fails.

Return type:

int


cometa.transaction_builder.fee.get_serialized_transaction_size(transaction)[source]

Compute the serialized size of a transaction.

Parameters:

transaction (Transaction) – The transaction object.

Returns:

The size in bytes required to serialize the transaction.

Raises:

CardanoError – If computation fails.

Return type:

int

Example

>>> tx_size = get_serialized_transaction_size(tx)
>>> print(f"Transaction size: {tx_size} bytes")

cometa.transaction_builder.fee.get_serialized_transaction_size(transaction)[source]

Compute the serialized size of a transaction.

Parameters:

transaction (Transaction) – The transaction object.

Returns:

The size in bytes required to serialize the transaction.

Raises:

CardanoError – If computation fails.

Return type:

int

Example

>>> tx_size = get_serialized_transaction_size(tx)
>>> print(f"Transaction size: {tx_size} bytes")