Sub Transaction Builder¶
-
typedef struct cardano_sub_tx_builder_t cardano_sub_tx_builder_t¶
High-Level Sub Transaction Builder for Cardano Blockchain.
The
cardano_sub_tx_builder_ttype is the interface a party of a CIP-118 batch uses to construct its sub transaction programmatically. A sub transaction is an intent: independent parties each build and sign one, and a batcher aggregates the finished sub transactions into a top level transaction that pays the fee and posts the collateral for the whole batch. The ledger checks value conservation over the whole batch, not over each sub transaction.Key Features:
Modular Design: Incrementally add inputs, outputs, minting operations, metadata, native and PlutusV4 scripts, guards, direct deposits, account balance intervals, withdrawals, certificates, votes and governance proposals.
Never Balances: The builder does not select inputs, does not add change outputs and does not compute fees. The sub transaction carries exactly the inputs and outputs that were added, and its imbalance (see cardano_compute_sub_transaction_imbalance) is the intent the batcher matches against the rest of the batch.
Sub Transaction Fields Only: Fees, collateral and starting account balance intervals only exist on a top level transaction, so this builder has no functions for them.
Native Scripts, PlutusV4 Scripts and Key Witnesses: PlutusV1, PlutusV2 and PlutusV3 scripts can not run inside a sub transaction and are rejected. PlutusV4 scripts are accepted: an input locked by a PlutusV4 script can be spent, a PlutusV4 policy can mint, a PlutusV4 script account can withdraw, a PlutusV4 script credential can publish certificates or vote, a PlutusV4 guardrails script can validate parameter change and treasury withdrawals proposals, and a script hash guard can be satisfied, each with a redeemer. The builder computes the execution units of those redeemers with the native evaluator when the sub transaction is built, before the parties sign it. A redeemer can also be produced by a callback when the sub transaction is built, so that it can carry indices that are local to the body of the sub transaction.
-
cardano_sub_tx_builder_t *cardano_sub_tx_builder_new(cardano_protocol_parameters_t *params, const cardano_slot_config_t *slot_config)¶
Creates a new sub transaction builder instance.
This function initializes a new sub transaction builder (
cardano_sub_tx_builder_t) using the supplied protocol parameters and slot configuration. The builder enables incremental construction of a CIP-118 sub transaction.The slot configuration provides time/slot conversion rules needed for unix time to slot conversions.
- Usage Example:
cardano_protocol_parameters_t* protocol_params = ...; // Initialized protocol parameters cardano_slot_config_t slot_config = CARDANO_PREVIEW_SLOT_CONFIG; // Constants for slot config for every public network can be found at cardano/slot_config.h cardano_sub_tx_builder_t* sub_tx_builder = cardano_sub_tx_builder_new(protocol_params, &slot_config); if (sub_tx_builder != NULL) { // Proceed with constructing the sub transaction } cardano_sub_tx_builder_unref(&sub_tx_builder);
Note
The caller is responsible for releasing the
cardano_sub_tx_builder_tinstance using cardano_sub_tx_builder_unref once it is no longer needed.- Parameters:¶
- cardano_protocol_parameters_t *params¶
[in] A pointer to a cardano_protocol_parameters_t structure containing the protocol parameters used to configure the sub transaction builder. Must not be
NULL.- const cardano_slot_config_t *slot_config¶
[in] A pointer to the cardano_slot_config_t structure that defines the slot/time translation rules for the current network. Must not be
NULL. Constants for every public network can be found atcardano/slot_config.h: CARDANO_MAINNET_SLOT_CONFIG CARDANO_PREVIEW_SLOT_CONFIG CARDANO_PREPROD_SLOT_CONFIG
- Returns:¶
A pointer to a newly created cardano_sub_tx_builder_t instance configured with the given protocol parameters and slot configuration, or
NULLif memory allocation fails or if any argument is invalid.
-
void cardano_sub_tx_builder_set_network_id(cardano_sub_tx_builder_t *builder, cardano_network_id_t network_id)¶
Sets the network ID for the sub transaction builder.
This function configures the sub transaction builder (
cardano_sub_tx_builder_t) with a specific network ID.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_network_id_t network_id = CARDANO_NETWORK_ID_MAIN_NET; // Set the network ID to mainnet cardano_sub_tx_builder_set_network_id(sub_tx_builder, network_id);Note
This function only sets the network ID within the builder and does not perform any validation until cardano_sub_tx_builder_build is called, which will report any related errors at that time.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance for which the network ID is being set.
- cardano_network_id_t network_id¶
[in] The network ID to assign to the sub transaction. This ID specifies the target network (e.g., mainnet, testnet) for which the sub transaction is intended.
-
void cardano_sub_tx_builder_set_donation(cardano_sub_tx_builder_t *builder, uint64_t donation)¶
Sets the donation amount for the sub transaction builder.
This function sets the donation amount. A donation contributes a specific amount to the treasury and is value produced by the sub transaction.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t donation = 1000000; // 1 ADA donation in lovelace cardano_sub_tx_builder_set_donation(sub_tx_builder, donation);- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the donation will be set.
- uint64_t donation¶
[in] The donation amount, specified in lovelace.
-
void cardano_sub_tx_builder_set_invalid_after(cardano_sub_tx_builder_t *builder, uint64_t slot)¶
Sets the expiration slot for a sub transaction, beyond which it is no longer valid.
This function specifies the slot number after which the sub transaction will be considered invalid. Setting this value lets an intent expire if no batcher includes it in a block before the specified slot.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t expiration_slot = 5000000; // Slot after which the sub transaction becomes invalid cardano_sub_tx_builder_set_invalid_after(sub_tx_builder, expiration_slot);- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance being configured.
- uint64_t slot¶
[in] The slot number after which the sub transaction will be marked as invalid.
-
void cardano_sub_tx_builder_set_invalid_after_ex(cardano_sub_tx_builder_t *builder, uint64_t unix_time)¶
Sets the expiration time for a sub transaction based on Unix time (in seconds).
This function configures the validity of the sub transaction based on a specified Unix timestamp, marking it as invalid if it is not included in a block before this time. The Unix timestamp is expressed in seconds since the epoch (January 1, 1970, UTC). This setting is useful for intents that need to expire at a specific real-world time.
Usage Example:
#include <time.h> cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder time_t current_time = time(NULL); // Get current Unix time in seconds uint64_t expiration_time = current_time + 2 * 60 * 60; // Set expiration to 2 hours from now cardano_sub_tx_builder_set_invalid_after_ex(sub_tx_builder, expiration_time);Note
If any errors occur while setting the expiration, they will not be immediately reported. Instead, they will be deferred and can be checked when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance being configured.
- uint64_t unix_time¶
[in] The Unix timestamp (in seconds) at which the sub transaction expires.
-
void cardano_sub_tx_builder_set_invalid_before(cardano_sub_tx_builder_t *builder, uint64_t slot)¶
Sets the minimum valid slot for a sub transaction.
This function configures the earliest slot at which the sub transaction will be considered valid. Sub transactions created with this setting will not be valid for inclusion in a block until the specified slot.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t min_valid_slot = 123456; // Example slot number cardano_sub_tx_builder_set_invalid_before(sub_tx_builder, min_valid_slot);Note
Any errors arising from setting this parameter will be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance being configured.
- uint64_t slot¶
[in] The minimum slot number at which the sub transaction is valid.
-
void cardano_sub_tx_builder_set_invalid_before_ex(cardano_sub_tx_builder_t *builder, uint64_t unix_time)¶
Sets the minimum valid time (Unix timestamp) for a sub transaction.
This function configures the earliest time, in Unix timestamp format (seconds since Epoch), at which the sub transaction will be considered valid. Sub transactions created with this setting will not be valid for inclusion in a block until the specified timestamp.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t min_valid_time = 7200 + time(NULL); // Set to 2 hours from now cardano_sub_tx_builder_set_invalid_before_ex(sub_tx_builder, min_valid_time);Note
Any errors resulting from setting this parameter will be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance being configured.
- uint64_t unix_time¶
[in] The minimum Unix timestamp (in seconds) at which the sub transaction is valid.
-
void cardano_sub_tx_builder_add_input(cardano_sub_tx_builder_t *builder, cardano_utxo_t *utxo, cardano_plutus_data_t *redeemer, cardano_plutus_data_t *datum)¶
Adds an input to the sub transaction.
This function appends a specified UTXO as an input to the sub transaction being built. The builder never selects inputs by itself, so the sub transaction spends exactly the UTXOs added through this function. An input locked by a key or by a native script is spent without a redeemer. An input locked by a PlutusV4 script is spent with a redeemer, and optionally with its datum when the UTXO only carries the datum hash. Provide the script with
cardano_sub_tx_builder_add_scriptor through a reference input.The redeemer points to the position of the input in the inputs of the sub transaction, which are sorted, so its index is set when the sub transaction is built. The builder then evaluates the script with the native evaluator and writes the execution units into the redeemer. An input set cannot hold the same input twice, so a UTXO whose input (transaction id and index) was already added as an input is rejected.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_utxo_t* input_utxo = ...; // UTXO to add as an input cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the input cardano_plutus_data_t* datum = ...; // Optional datum for the input cardano_sub_tx_builder_add_input(sub_tx_builder, input_utxo, redeemer, datum);Note
Any errors resulting from adding this input will be deferred and reported when
cardano_sub_tx_builder_buildis called. An input that was already added as an input makescardano_sub_tx_builder_buildreturn CARDANO_ERROR_DUPLICATED_KEY. An input locked by a PlutusV1, PlutusV2 or PlutusV3 script can not be spent inside a sub transaction and makescardano_sub_tx_builder_buildreturn CARDANO_ERROR_INVALID_SCRIPT_LANGUAGE.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance in which to add the input.
- cardano_utxo_t *utxo¶
[in] A pointer to the cardano_utxo_t structure representing the resolved UTXO to be used as an input.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
- cardano_plutus_data_t *datum¶
[in] A pointer to the cardano_plutus_data_t structure representing the datum for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_add_input_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_utxo_t *utxo, cardano_deferred_redeemer_fn_t callback, void *user_context, cardano_plutus_data_t *datum)¶
Adds an input locked by a PlutusV4 script whose redeemer payload is produced by a deferred callback.
Behaves like cardano_sub_tx_builder_add_input, but instead of a literal redeemer the caller provides a callback that builds the payload once the layout of the sub transaction is final. This is the mechanism for redeemers that carry indices of elements of the script context (see cardano_deferred_redeemer_fn_t and the cardano_transaction_find_input_index family).
The callback is invoked when
cardano_sub_tx_builder_buildis called, after the index of every spend redeemer is set and before the scripts are evaluated, so the produced payload is evaluated and covered by the script data hash. It receives a transaction whose body holds the sorted inputs, the outputs and every other field of the sub transaction body, with a zero fee, together with the UTXOs spent by the sub transaction in that same sorted order. Every index the callback computes is therefore local to the body of the sub transaction, the body that is signed.The callback must be a pure function of its arguments. The caller must keep
user_contextvalid until the sub transaction is built.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_utxo_t* input_utxo = ...; // UTXO locked by a PlutusV4 script cardano_deferred_redeemer_fn_t callback = ...; // Builds the redeemer from the sub transaction body cardano_sub_tx_builder_add_input_with_deferred_redeemer(sub_tx_builder, input_utxo, callback, input_utxo, NULL);Note
Any errors resulting from adding this input will be deferred and reported when
cardano_sub_tx_builder_buildis called. A callback that fails makescardano_sub_tx_builder_buildreturn the error of the callback, and a callback that produces no payload makes it return CARDANO_ERROR_POINTER_IS_NULL.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance in which to add the input.
- cardano_utxo_t *utxo¶
[in] A pointer to the cardano_utxo_t structure representing the resolved UTXO to be used as an input.
- cardano_deferred_redeemer_fn_t callback¶
[in] The cardano_deferred_redeemer_fn_t callback producing the redeemer payload.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.
- cardano_plutus_data_t *datum¶
[in] A pointer to the cardano_plutus_data_t structure representing the datum for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_add_reference_input(cardano_sub_tx_builder_t *builder, cardano_utxo_t *utxo)¶
Adds a reference input to the sub transaction.
This function appends a specified UTXO as a reference input to the sub transaction being built. Reference inputs give access to the data and the reference script of a UTXO without consuming it. A reference input set cannot hold the same input twice, so a UTXO whose input (transaction id and index) was already added as a reference input is rejected.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_utxo_t* reference_utxo = ...; // UTXO to add as a reference input cardano_sub_tx_builder_add_reference_input(sub_tx_builder, reference_utxo);Note
Any errors resulting from adding this input will be reported when
cardano_sub_tx_builder_buildis called. A reference input added twice makescardano_sub_tx_builder_buildreturn CARDANO_ERROR_DUPLICATED_KEY.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance in which to add the reference input.
- cardano_utxo_t *utxo¶
[in] A pointer to the cardano_utxo_t structure representing the UTXO to be used as a reference input.
-
void cardano_sub_tx_builder_add_output(cardano_sub_tx_builder_t *builder, cardano_transaction_output_t *output)¶
Adds an output to the sub transaction.
This function appends a specified transaction output to the sub transaction being built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_transaction_output_t* tx_output = ...; // Transaction output to add cardano_sub_tx_builder_add_output(sub_tx_builder, tx_output);Note
Any errors related to adding this output will be deferred and reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the output will be added.
- cardano_transaction_output_t *output¶
[in] A pointer to the cardano_transaction_output_t structure representing the transaction output to be added.
-
void cardano_sub_tx_builder_send_lovelace(cardano_sub_tx_builder_t *builder, cardano_address_t *address, uint64_t amount)¶
Sends a specified amount of lovelace to a given address.
This function adds a transaction output to the builder, targeting a specific address and setting the amount of lovelace to be sent.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_address_t* recipient_address = ...; // Recipient address uint64_t lovelace_amount = 1000000; // Amount of lovelace to send (e.g., 1 ADA) cardano_sub_tx_builder_send_lovelace(sub_tx_builder, recipient_address, lovelace_amount);Note
Any errors related to sending lovelace will be deferred and reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the output will be added.
- cardano_address_t *address¶
[in] A pointer to the cardano_address_t structure representing the recipient address.
- uint64_t amount¶
[in] The amount of lovelace to send to the specified address.
-
void cardano_sub_tx_builder_send_lovelace_ex(cardano_sub_tx_builder_t *builder, const char *address, size_t address_size, uint64_t amount)¶
Sends a specified amount of lovelace to a given address in string format.
This function adds a transaction output to the builder, targeting a specific address in string format and setting the amount of lovelace to be sent.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* recipient_address = "addr1..."; // Recipient address in string format size_t address_size = strlen(recipient_address); // Size of the address string uint64_t lovelace_amount = 1000000; // Amount of lovelace to send (e.g., 1 ADA) cardano_sub_tx_builder_send_lovelace_ex(sub_tx_builder, recipient_address, address_size, lovelace_amount);Note
Errors, such as an invalid address, will be deferred and reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the output will be added.
- const char *address¶
[in] A pointer to a character array containing the recipient address in string format.
- size_t address_size¶
[in] The size of the address string.
- uint64_t amount¶
[in] The amount of lovelace to send to the specified address.
-
void cardano_sub_tx_builder_send_value(cardano_sub_tx_builder_t *builder, cardano_address_t *address, cardano_value_t *value)¶
Sends a specified value (which may include ADA and other assets) to a given address.
This function adds a transaction output to the builder, specifying an address and a complex value that can include multiple assets in addition to ADA.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_address_t* recipient_address = ...; // Address to send to cardano_value_t* transfer_value = ...; // Value to transfer (e.g., ADA and assets) cardano_sub_tx_builder_send_value(sub_tx_builder, recipient_address, transfer_value);Note
Errors, such as invalid assets, will be deferred and reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the output will be added.
- cardano_address_t *address¶
[in] A pointer to a cardano_address_t object representing the recipient address.
- cardano_value_t *value¶
[in] A pointer to a cardano_value_t object containing the ADA and any additional assets to send.
-
void cardano_sub_tx_builder_send_value_ex(cardano_sub_tx_builder_t *builder, const char *address, size_t address_size, cardano_value_t *value)¶
Sends a specified value (which may include ADA and other assets) to a given address provided as raw string.
This function adds a transaction output to the builder, specifying an address in character array format along with a complex value that may include multiple assets.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* recipient_address = "addr1..."; // Bech32 address size_t address_size = strlen(recipient_address); cardano_value_t* transfer_value = ...; // Value to transfer (e.g., ADA and assets) cardano_sub_tx_builder_send_value_ex(sub_tx_builder, recipient_address, address_size, transfer_value);Note
Errors, such as an invalid address or invalid assets, will be deferred and reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the output will be added.
- const char *address¶
[in] A character array containing the recipient’s address in bech32 or hex format.
- size_t address_size¶
[in] The length of the address character array.
- cardano_value_t *value¶
[in] A pointer to a cardano_value_t object containing the ADA and any additional assets to send.
-
void cardano_sub_tx_builder_lock_lovelace(cardano_sub_tx_builder_t *builder, cardano_address_t *script_address, uint64_t amount, cardano_datum_t *datum)¶
Locks a specified amount of lovelace at a script address.
This function adds a transaction output to the sub transaction that sends lovelace to a script address.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_address_t* script_addr = ...; // Script address uint64_t lovelace_amount = 5000000; // Amount of lovelace to lock cardano_datum_t* datum = ...; // Datum associated with the script cardano_sub_tx_builder_lock_lovelace(sub_tx_builder, script_addr, lovelace_amount, datum);Note
Errors such as an invalid amount or address will be reported when
cardano_sub_tx_builder_buildis called. A datum hash only commits to the datum, so provide the datum itself withcardano_sub_tx_builder_add_datumto include it in the witness set of the sub transaction.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance to which the locked output will be added.
- cardano_address_t *script_address¶
[in] A pointer to the cardano_address_t representing the script address where the lovelace will be locked.
- uint64_t amount¶
[in] The amount of lovelace to be locked at the script address.
- cardano_datum_t *datum¶
[in] A pointer to the cardano_datum_t object containing the data to lock with the transaction.
-
void cardano_sub_tx_builder_lock_lovelace_ex(cardano_sub_tx_builder_t *builder, const char *script_address, size_t script_address_size, uint64_t amount, cardano_datum_t *datum)¶
Locks a specified amount of lovelace at a script address using an address in raw byte format.
This function adds a transaction output to the sub transaction, sending lovelace to a script address.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* script_addr_bytes = ...; // Raw bytes of script address size_t script_addr_size = ...; // Size of the address in bytes uint64_t lovelace_amount = 5000000; // Amount of lovelace to lock cardano_datum_t* datum = ...; // Datum associated with the script cardano_sub_tx_builder_lock_lovelace_ex(sub_tx_builder, script_addr_bytes, script_addr_size, lovelace_amount, datum);Note
Errors such as an invalid amount or address will be deferred until
cardano_sub_tx_builder_buildis called. A datum hash only commits to the datum, so provide the datum itself withcardano_sub_tx_builder_add_datumto include it in the witness set of the sub transaction.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the locked output will be added.
- const char *script_address¶
[in] A pointer to a raw byte array containing the script address where the lovelace will be locked.
- size_t script_address_size¶
[in] The size, in bytes, of the script address.
- uint64_t amount¶
[in] The amount of lovelace to be locked at the specified script address.
- cardano_datum_t *datum¶
[in] A pointer to the cardano_datum_t object containing the datum for the script output.
-
void cardano_sub_tx_builder_lock_value(cardano_sub_tx_builder_t *builder, cardano_address_t *script_address, cardano_value_t *value, cardano_datum_t *datum)¶
Locks a specified value (including ADA and multi-asset tokens) at a script address.
This function adds a transaction output to the sub transaction, sending a specified value to a script address.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_address_t* script_addr = ...; // Script address to lock value at cardano_value_t* value = ...; // Value including ADA and/or tokens cardano_datum_t* datum = ...; // Datum associated with the script cardano_sub_tx_builder_lock_value(sub_tx_builder, script_addr, value, datum);Note
Errors such as invalid address or value will be deferred until
cardano_sub_tx_builder_buildis called. A datum hash only commits to the datum, so provide the datum itself withcardano_sub_tx_builder_add_datumto include it in the witness set of the sub transaction.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the locked output will be added.
- cardano_address_t *script_address¶
[in] A pointer to the cardano_address_t object representing the script address where the value will be locked.
- cardano_value_t *value¶
[in] A pointer to the cardano_value_t object representing the amount and type of value (ADA or tokens) to be locked at the script address.
- cardano_datum_t *datum¶
[in] A pointer to the cardano_datum_t object containing the datum for the script output.
-
void cardano_sub_tx_builder_lock_value_ex(cardano_sub_tx_builder_t *builder, const char *script_address, size_t script_address_size, cardano_value_t *value, cardano_datum_t *datum)¶
Locks a specified value (including ADA and multi-asset tokens) at a script address using a raw address string.
This function adds a transaction output to the sub transaction, sending a specified value to a script address represented by a raw address string.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* script_addr_str = "addr_test1..."; // Raw address string for the script address size_t script_addr_size = strlen(script_addr_str); cardano_value_t* value = ...; // Value including ADA and/or tokens cardano_datum_t* datum = ...; // Datum associated with the script (optional) cardano_sub_tx_builder_lock_value_ex(sub_tx_builder, script_addr_str, script_addr_size, value, datum);Note
Errors such as invalid address or value will be deferred until
cardano_sub_tx_builder_buildis called. A datum hash only commits to the datum, so provide the datum itself withcardano_sub_tx_builder_add_datumto include it in the witness set of the sub transaction.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the locked output will be added.
- const char *script_address¶
[in] A pointer to a character array containing the raw script address string where the value will be locked.
- size_t script_address_size¶
[in] The size of the
script_addressstring in bytes.- cardano_value_t *value¶
[in] A pointer to the cardano_value_t object representing the amount and type of value (ADA or tokens) to be locked at the script address.
- cardano_datum_t *datum¶
[in] A pointer to the cardano_datum_t object containing the datum for the script output.
-
void cardano_sub_tx_builder_set_metadata(cardano_sub_tx_builder_t *builder, uint64_t tag, cardano_metadatum_t *metadata)¶
Sets metadata for a sub transaction builder with a specified tag.
This function attaches metadata to the sub transaction being built, associating it with a specific metadata tag. Metadata can include additional information for the sub transaction, often used to encode arbitrary data on-chain.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t metadata_tag = 12345; // Example metadata tag cardano_metadatum_t* metadata = ...; // Initialized metadata object cardano_sub_tx_builder_set_metadata(sub_tx_builder, metadata_tag, metadata);Note
This function only stores a reference to the metadata. Errors, such as invalid metadata format, will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the metadata will be added.
- uint64_t tag¶
[in] A unique identifier for the metadata, typically a 64-bit unsigned integer.
- cardano_metadatum_t *metadata¶
[in] A pointer to the cardano_metadatum_t object containing the metadata to be added.
-
void cardano_sub_tx_builder_set_metadata_ex(cardano_sub_tx_builder_t *builder, uint64_t tag, const char *metadata_json, size_t json_size)¶
Sets metadata for a sub transaction builder from a JSON string with a specified tag.
This function allows adding metadata to the sub transaction by parsing a JSON string representation of the metadata. The metadata is associated with a specified tag, allowing for organized and accessible on-chain data.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder uint64_t metadata_tag = 12345; // Example metadata tag const char* metadata_json = "{ \"name\": \"some_name\" }"; // Metadata JSON as string size_t json_size = strlen(metadata_json); cardano_sub_tx_builder_set_metadata_ex(sub_tx_builder, metadata_tag, metadata_json, json_size);Note
This function will parse the JSON string to convert it into metadata. Errors, such as invalid JSON format, will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance where the metadata will be added.
- uint64_t tag¶
[in] A unique identifier for the metadata, typically a 64-bit unsigned integer.
- const char *metadata_json¶
[in] A pointer to a JSON string representing the metadata content.
- size_t json_size¶
[in] The length of the
metadata_jsonstring.
-
void cardano_sub_tx_builder_mint_token(cardano_sub_tx_builder_t *builder, cardano_blake2b_hash_t *policy_id, cardano_asset_name_t *name, int64_t amount, cardano_plutus_data_t *redeemer)¶
Adds a token minting operation to the sub transaction builder.
This function allows the user to specify a token minting operation within a sub transaction, including the policy ID, asset name and amount. This enables minting (positive amount) or burning (negative amount) of tokens. A native script policy takes no redeemer. A PlutusV4 policy is run with the redeemer, which is evaluated natively when the sub transaction is built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_blake2b_hash_t* policy_id = ...; // Policy ID for the token cardano_asset_name_t* asset_name = ...; // Asset name for the token int64_t mint_amount = 100; // Amount to mint cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_mint_token(sub_tx_builder, policy_id, asset_name, mint_amount, redeemer);Note
Errors related to this operation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance for building the sub transaction.
- cardano_blake2b_hash_t *policy_id¶
[in] A pointer to a cardano_blake2b_hash_t representing the unique minting policy ID.
- cardano_asset_name_t *name¶
[in] A pointer to a cardano_asset_name_t defining the name of the asset being minted or burned.
- int64_t amount¶
[in] The number of tokens to mint or burn; positive values indicate minting, and negative values indicate burning.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_mint_token_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_blake2b_hash_t *policy_id, cardano_asset_name_t *name, int64_t amount, cardano_deferred_redeemer_fn_t callback, void *user_context)¶
Adds a token minting operation whose redeemer payload is produced by a deferred callback.
Behaves like cardano_sub_tx_builder_mint_token, but the redeemer payload of the PlutusV4 policy is built by the callback from the body of the sub transaction when it is built. See cardano_sub_tx_builder_add_input_with_deferred_redeemer.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_blake2b_hash_t* policy_id = ...; // Hash of the PlutusV4 policy cardano_asset_name_t* asset_name = ...; // Asset name for the token cardano_deferred_redeemer_fn_t callback = ...; // Builds the redeemer from the sub transaction body cardano_sub_tx_builder_mint_token_with_deferred_redeemer(sub_tx_builder, policy_id, asset_name, 100, callback, NULL);Note
Errors related to this operation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance for building the sub transaction.
- cardano_blake2b_hash_t *policy_id¶
[in] A pointer to a cardano_blake2b_hash_t representing the unique minting policy ID.
- cardano_asset_name_t *name¶
[in] A pointer to a cardano_asset_name_t defining the name of the asset being minted or burned.
- int64_t amount¶
[in] The number of tokens to mint or burn; positive values indicate minting, and negative values indicate burning.
- cardano_deferred_redeemer_fn_t callback¶
[in] The cardano_deferred_redeemer_fn_t callback producing the redeemer payload.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.
-
void cardano_sub_tx_builder_mint_token_ex(cardano_sub_tx_builder_t *builder, const char *policy_id_hex, size_t policy_id_size, const char *name_hex, size_t name_size, int64_t amount, cardano_plutus_data_t *redeemer)¶
Adds a token minting operation to the sub transaction builder using policy ID and asset name in hexadecimal format.
This function allows the sub transaction builder to mint or burn tokens associated with a specific policy ID and asset name. A native script policy takes no redeemer. A PlutusV4 policy is run with the redeemer, which is evaluated natively when the sub transaction is built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* policy_id_hex = "abcdef123456"; // Example policy ID in hexadecimal format size_t policy_id_size = strlen(policy_id_hex); // Size of policy ID const char* name_hex = "74657374"; // Asset name in hexadecimal ("test" in hex) size_t name_size = strlen(name_hex); // Size of asset name int64_t mint_amount = 100; // Amount to mint (positive for minting, negative for burning) cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_mint_token_ex(sub_tx_builder, policy_id_hex, policy_id_size, name_hex, name_size, mint_amount, redeemer);Note
Any errors related to this operation will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- const char *policy_id_hex¶
[in] A string in hexadecimal format representing the policy ID of the token to mint or burn.
- size_t policy_id_size¶
[in] The size of the
policy_id_hexstring.- const char *name_hex¶
[in] A string in hexadecimal format representing the asset name within the policy ID.
- size_t name_size¶
[in] The size of the
name_hexstring.- int64_t amount¶
[in] The amount of tokens to mint (positive) or burn (negative).
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_mint_token_with_id(cardano_sub_tx_builder_t *builder, cardano_asset_id_t *asset_id, int64_t amount, cardano_plutus_data_t *redeemer)¶
Adds a token minting operation to the sub transaction builder using a predefined asset ID.
This function allows minting or burning of tokens within a sub transaction by specifying an asset ID along with the amount. A native script policy takes no redeemer. A PlutusV4 policy is run with the redeemer, which is evaluated natively when the sub transaction is built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_asset_id_t* asset_id = ...; // Predefined asset ID for the token int64_t mint_amount = 50; // Amount to mint (positive for minting, negative for burning) cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_mint_token_with_id(sub_tx_builder, asset_id, mint_amount, redeemer);Note
Any errors related to this operation are deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used to build the sub transaction.
- cardano_asset_id_t *asset_id¶
[in] A pointer to a cardano_asset_id_t structure representing the asset to mint or burn.
- int64_t amount¶
[in] The amount of tokens to mint (positive) or burn (negative).
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_mint_token_with_id_ex(cardano_sub_tx_builder_t *builder, const char *asset_id_hex, size_t hex_size, int64_t amount, cardano_plutus_data_t *redeemer)¶
Adds a token minting operation to the sub transaction builder using an asset ID in hexadecimal format.
This function enables minting or burning tokens for a specific asset identified by its unique
asset_idin hexadecimal format. A native script policy takes no redeemer. A PlutusV4 policy is run with the redeemer, which is evaluated natively when the sub transaction is built.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* asset_id_hex = "abcdef1234567890"; // Example asset ID in hexadecimal format size_t hex_size = strlen(asset_id_hex); // Size of asset ID int64_t mint_amount = 100; // Amount to mint (positive for minting, negative for burning) cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_mint_token_with_id_ex(sub_tx_builder, asset_id_hex, hex_size, mint_amount, redeemer);Note
Any errors will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- const char *asset_id_hex¶
[in] A string in hexadecimal format representing the unique asset ID.
- size_t hex_size¶
[in] The size of the
asset_id_hexstring.- int64_t amount¶
[in] The amount of tokens to mint (positive) or burn (negative).
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_add_script(cardano_sub_tx_builder_t *builder, cardano_script_t *script)¶
Adds a script to the sub transaction builder.
This function allows the addition of a native or PlutusV4 script (
cardano_script_t) to the witness set of the sub transaction. Native scripts define the conditions under which outputs can be unlocked and tokens can be minted, and a PlutusV4 script can run for any purpose of the sub transaction that takes a redeemer: spending an input, minting, withdrawing, certifying, voting or satisfying a script hash guard added withcardano_sub_tx_builder_add_guard_with_redeemer. PlutusV1, PlutusV2 and PlutusV3 scripts can not run inside a sub transaction, so adding one of them is reported as an error.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_script_t* script = ...; // A native script for the sub transaction cardano_sub_tx_builder_add_script(sub_tx_builder, script); // Additional sub transaction setup... cardano_error_t result = cardano_sub_tx_builder_build(sub_tx_builder, &sub_transaction); if (result != CARDANO_SUCCESS) { const char* error_msg = cardano_sub_tx_builder_get_last_error(sub_tx_builder); printf("Failed to build sub transaction with script: %s\n", error_msg); }Note
Errors related to adding an invalid or incompatible script will be deferred and reported only when
cardano_sub_tx_builder_buildis called. A PlutusV1, PlutusV2 or PlutusV3 script is reported as CARDANO_ERROR_INVALID_SCRIPT_LANGUAGE.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction details.
- cardano_script_t *script¶
[in] A pointer to the cardano_script_t structure representing the native or PlutusV4 script to be added.
-
void cardano_sub_tx_builder_add_signer(cardano_sub_tx_builder_t *builder, cardano_blake2b_hash_t *pub_key_hash)¶
Adds a signer to the sub transaction being built.
This function registers a specific signer for the sub transaction by providing their public key hash, so the sub transaction must carry a witness for that key. A required signer is a key hash guard: this function produces the same sub transaction as
cardano_sub_tx_builder_add_guardwith a key hash credential of the same hash. Adding a signer that is already present leaves the sub transaction unchanged.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_blake2b_hash_t* signer_hash = ...; // Public key hash for the signer cardano_sub_tx_builder_add_signer(sub_tx_builder, signer_hash);Note
Errors related to adding signers are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- cardano_blake2b_hash_t *pub_key_hash¶
[in] A pointer to the cardano_blake2b_hash_t structure representing the public key hash of the signer to be added.
-
void cardano_sub_tx_builder_add_signer_ex(cardano_sub_tx_builder_t *builder, const char *pub_key_hash, size_t hash_size)¶
Adds a signer to the sub transaction by specifying their public key hash in hexadecimal format.
This function registers a signer by accepting their public key hash as a hexadecimal string. See
cardano_sub_tx_builder_add_signerfor how a signer relates to a key hash guard.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* pub_key_hash = "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37"; size_t hash_size = strlen(pub_key_hash); cardano_sub_tx_builder_add_signer_ex(sub_tx_builder, pub_key_hash, hash_size);Note
Errors associated with adding a signer are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- const char *pub_key_hash¶
[in] A string representing the public key hash in hexadecimal format.
- size_t hash_size¶
[in] The size of the
pub_key_hashstring.
-
void cardano_sub_tx_builder_add_guard(cardano_sub_tx_builder_t *builder, cardano_credential_t *guard)¶
Adds a guard to the sub transaction being built.
This function registers a guard credential for the sub transaction. Guards generalize required signers: a key hash guard is exactly a required signer, so the sub transaction must carry a witness for that key, while a script hash guard requires the ledger to run the script as a validity condition. Adding a guard that is already present leaves the sub transaction unchanged.
The builder does not resolve or attach the script behind a script hash guard. Provide the script with
cardano_sub_tx_builder_add_scriptor through a reference input. A script hash guard added with this function has no redeemer; usecardano_sub_tx_builder_add_guard_with_redeemerto add it together with the guarding redeemer that satisfies it. A guard whose script is a Plutus script provided to the sub transaction makescardano_sub_tx_builder_buildreturn CARDANO_ERROR_MISSING_REDEEMER when it has no redeemer.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_credential_t* guard = ...; // Key hash or script hash credential cardano_sub_tx_builder_add_guard(sub_tx_builder, guard);Note
Errors related to adding guards are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- cardano_credential_t *guard¶
[in] A pointer to the cardano_credential_t structure representing the guard to be added.
-
void cardano_sub_tx_builder_add_guard_ex(cardano_sub_tx_builder_t *builder, const char *hash_hex, size_t hash_hex_size, cardano_credential_type_t type)¶
Adds a guard to the sub transaction by specifying the credential hash in hexadecimal format.
This function registers a guard by accepting the hash of its credential as a hexadecimal string together with the credential type. See
cardano_sub_tx_builder_add_guardfor the difference between key hash and script hash guards.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* key_hash = "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37"; size_t hash_size = strlen(key_hash); cardano_sub_tx_builder_add_guard_ex(sub_tx_builder, key_hash, hash_size, CARDANO_CREDENTIAL_TYPE_KEY_HASH);Note
Errors associated with adding a guard are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- const char *hash_hex¶
[in] A string representing the credential hash in hexadecimal format.
- size_t hash_hex_size¶
[in] The size of the
hash_hexstring.- cardano_credential_type_t type¶
[in] The type of the credential, either CARDANO_CREDENTIAL_TYPE_KEY_HASH or CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH.
-
void cardano_sub_tx_builder_add_guard_with_redeemer(cardano_sub_tx_builder_t *builder, cardano_credential_t *guard, cardano_plutus_data_t *redeemer)¶
Adds a script hash guard to the sub transaction together with the guarding redeemer that satisfies it.
This function registers
guardlikecardano_sub_tx_builder_add_guardand attaches a redeemer with the guarding purpose whose payload isredeemer. The ledger runs the guard script with that redeemer as a validity condition of the sub transaction. The redeemer points to the position of the guard in the guards of the sub transaction, which keep the order in which they were added, counting key hash guards and the signers added withcardano_sub_tx_builder_add_signer. A guard that is already present keeps its position.The guard script must be a PlutusV4 script, the only Plutus language that runs inside a sub transaction. Provide it with
cardano_sub_tx_builder_add_scriptor through a reference input. When the sub transaction is built, the builder evaluates its redeemers with the native evaluator, using the cost models and the protocol version of the protocol parameters and resolving the inputs with the UTXOs added to the builder, writes the execution units into the redeemers and sets the script data hash, so the parties sign the final sub transaction. The sub transaction is evaluated at position 0 of a batch that holds nothing else. Its script context carries its position in the batch, so a script whose path or cost depends on that position may need different execution units in the final batch.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; cardano_credential_t* guard = ...; cardano_script_t* script = ...; cardano_plutus_data_t* redeemer = ...; cardano_sub_tx_builder_add_script(sub_tx_builder, script); cardano_sub_tx_builder_add_guard_with_redeemer(sub_tx_builder, guard, redeemer);Note
Errors are deferred and will only be reported when
cardano_sub_tx_builder_buildis called. A key hash guard makescardano_sub_tx_builder_buildreturn CARDANO_ERROR_INVALID_ARGUMENT, since only a script is satisfied by a redeemer, and a guard that already has a redeemer makes it return CARDANO_ERROR_DUPLICATED_KEY. A guard script that fails makes it return CARDANO_ERROR_SCRIPT_EVALUATION_FAILURE.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- cardano_credential_t *guard¶
[in] A pointer to the script hash cardano_credential_t to add as a guard.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t handed to the guard script as its redeemer.
-
void cardano_sub_tx_builder_add_datum(cardano_sub_tx_builder_t *builder, cardano_plutus_data_t *datum)¶
Adds a datum to the sub transaction builder for use in script-locked UTXOs.
This function registers a Plutus datum with the sub transaction builder. When the sub transaction is built, the datum is included in the plutus data of its witness set and is covered by its script data hash.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_plutus_data_t* datum = ...; // Initialized Plutus datum cardano_sub_tx_builder_add_datum(sub_tx_builder, datum);Note
Errors related to adding a datum are deferred and will be reported when
cardano_sub_tx_builder_buildis called. The caller must ensure that thedatumremains valid until the sub transaction is built.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_plutus_data_t *datum¶
[in] A pointer to a cardano_plutus_data_t object representing the datum to be included.
-
void cardano_sub_tx_builder_require_top_level_guard(cardano_sub_tx_builder_t *builder, cardano_credential_t *credential, cardano_plutus_data_t *datum)¶
Requires a guard from the top level transaction that carries the sub transaction.
A sub transaction can constrain the batch it takes part in: every credential it requires must be listed among the guards of the top level transaction, otherwise the whole batch is invalid. Each required guard may carry a datum that is handed to the guard script of the top level transaction, which lets the sub transaction pass its own terms to that script. Requiring a credential that is already present replaces its datum.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_credential_t* batcher_guard = ...; // Credential the top level transaction must be guarded by cardano_plutus_data_t* terms = ...; // Optional datum for the guard cardano_sub_tx_builder_require_top_level_guard(sub_tx_builder, batcher_guard, terms);Note
Errors related to requiring a top level guard are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- cardano_credential_t *credential¶
[in] A pointer to the cardano_credential_t the top level transaction must be guarded by.
- cardano_plutus_data_t *datum¶
[in] A pointer to the cardano_plutus_data_t handed to the guard (optional; can be NULL).
-
void cardano_sub_tx_builder_require_top_level_guard_ex(cardano_sub_tx_builder_t *builder, const char *hash_hex, size_t hash_hex_size, cardano_credential_type_t type, cardano_plutus_data_t *datum)¶
Requires a guard from the top level transaction by specifying the credential hash in hexadecimal format.
This function behaves like
cardano_sub_tx_builder_require_top_level_guardbut accepts the hash of the credential as a hexadecimal string together with the credential type.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* script_hash = "966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37"; size_t hash_size = strlen(script_hash); cardano_sub_tx_builder_require_top_level_guard_ex(sub_tx_builder, script_hash, hash_size, CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH, NULL);Note
Errors related to requiring a top level guard are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for sub transaction construction.
- const char *hash_hex¶
[in] A string representing the credential hash in hexadecimal format.
- size_t hash_hex_size¶
[in] The size of the
hash_hexstring.- cardano_credential_type_t type¶
[in] The type of the credential, either CARDANO_CREDENTIAL_TYPE_KEY_HASH or CARDANO_CREDENTIAL_TYPE_SCRIPT_HASH.
- cardano_plutus_data_t *datum¶
[in] A pointer to the cardano_plutus_data_t handed to the guard (optional; can be NULL).
-
void cardano_sub_tx_builder_add_direct_deposit(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, uint64_t amount)¶
Adds a direct deposit to the sub transaction being built.
A direct deposit pays lovelace straight into a reward account without creating a UTxO. The deposited amount is value produced by the sub transaction, so it is part of the imbalance the batch has to cover. Adding a direct deposit for a reward account that already has one accumulates both amounts.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Initialized reward address cardano_sub_tx_builder_add_direct_deposit(sub_tx_builder, reward_address, 2000000);Note
Errors related to adding a direct deposit, including an amount or an accumulated amount above INT64_MAX, are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to the cardano_reward_address_t representing the reward account that receives the deposit.
- uint64_t amount¶
[in] The amount of lovelace to deposit. It must be greater than zero and at most INT64_MAX, the largest amount the balancer can represent.
-
void cardano_sub_tx_builder_add_direct_deposit_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, uint64_t amount)¶
Adds a direct deposit to the sub transaction using a string reward address.
This function behaves like
cardano_sub_tx_builder_add_direct_depositbut accepts the reward account as a Bech32 string.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_addr = "stake1u9..."; // Reward address in string format size_t address_size = strlen(reward_addr); // Length of the reward address string cardano_sub_tx_builder_add_direct_deposit_ex(sub_tx_builder, reward_addr, address_size, 2000000);Note
Errors related to adding a direct deposit are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- const char *reward_address¶
[in] A string representing the reward account that receives the deposit.
- size_t address_size¶
[in] The size of the reward address string in bytes.
- uint64_t amount¶
[in] The amount of lovelace to deposit. It must be greater than zero and at most INT64_MAX, the largest amount the balancer can represent.
-
void cardano_sub_tx_builder_add_account_balance_interval(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_account_balance_interval_t *interval)¶
Adds an account balance interval to the sub transaction being built.
An account balance interval makes the sub transaction valid only while the balance of the reward account sits inside the interval at the point the sub transaction is applied. An interval is either bounded (inclusive lower bound, exclusive upper bound, either of which may be absent) or an exact balance. Adding an interval for a reward account that already has one replaces the previous interval.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Initialized reward address cardano_account_balance_interval_t* interval = NULL; const uint64_t lower_bound = 1000000; if (cardano_account_balance_interval_new(&lower_bound, NULL, &interval) == CARDANO_SUCCESS) { cardano_sub_tx_builder_add_account_balance_interval(sub_tx_builder, reward_address, interval); cardano_account_balance_interval_unref(&interval); }Note
Errors related to adding an interval are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to the cardano_reward_address_t representing the reward account the interval constrains.
- cardano_account_balance_interval_t *interval¶
[in] A pointer to the cardano_account_balance_interval_t the account balance must sit in.
-
void cardano_sub_tx_builder_add_account_balance_interval_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, cardano_account_balance_interval_t *interval)¶
Adds an account balance interval to the sub transaction using a string reward address.
This function behaves like
cardano_sub_tx_builder_add_account_balance_intervalbut accepts the reward account as a Bech32 string.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_account_balance_interval_t* interval = ...; // Initialized interval const char* reward_addr = "stake1u9..."; // Reward address in string format size_t address_size = strlen(reward_addr); // Length of the reward address string cardano_sub_tx_builder_add_account_balance_interval_ex(sub_tx_builder, reward_addr, address_size, interval);Note
Errors related to adding an interval are deferred and will only be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- const char *reward_address¶
[in] A string representing the reward account the interval constrains.
- size_t address_size¶
[in] The size of the reward address string in bytes.
- cardano_account_balance_interval_t *interval¶
[in] A pointer to the cardano_account_balance_interval_t the account balance must sit in.
-
void cardano_sub_tx_builder_withdraw_rewards(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, int64_t amount, cardano_plutus_data_t *redeemer)¶
Withdraws rewards from a specified reward account in the sub transaction builder.
This function adds a withdrawal from the specified reward account to the sub transaction. The withdrawn amount is value consumed by the sub transaction, so it is part of the imbalance the batch has to match.
A sub transaction can withdraw part of the balance of an account: the ledger only requires that the withdrawals of an account, added over the top level transaction and every sub transaction of the batch, do not exceed the balance the account had before the batch. The rule that a withdrawal must drain the account exactly only applies to the withdrawals of a top level transaction that needs a PlutusV1, PlutusV2 or PlutusV3 script.
The account must also be registered before the batch, so the ledger rejects a batch whose sub transaction withdraws from an account the batch registers, even one funded by a direct deposit of the batch, or from an account an earlier sub transaction of the batch unregisters. The builder has no view of account state, so it does not check this.
An account controlled by a key or by a native script is withdrawn from without a redeemer. An account controlled by a PlutusV4 script needs a redeemer, evaluated natively when the sub transaction is built, and its script provided with
cardano_sub_tx_builder_add_scriptor through a reference input.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Initialized reward address cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_withdraw_rewards(sub_tx_builder, reward_address, 2532145, redeemer);Note
Errors related to reward withdrawal will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t representing the reward account address from which rewards should be withdrawn.
- int64_t amount¶
[in] The amount of rewards to withdraw from the account, in lovelace.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_withdraw_rewards_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, int64_t amount, cardano_deferred_redeemer_fn_t callback, void *user_context)¶
Withdraws rewards with a redeemer payload produced by a deferred callback.
Behaves like cardano_sub_tx_builder_withdraw_rewards, but the redeemer payload of the PlutusV4 script account is built by the callback from the body of the sub transaction when it is built. See cardano_sub_tx_builder_add_input_with_deferred_redeemer.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address of a PlutusV4 script account cardano_deferred_redeemer_fn_t callback = ...; // Builds the redeemer from the sub transaction body cardano_sub_tx_builder_withdraw_rewards_with_deferred_redeemer(sub_tx_builder, reward_address, 2532145, callback, NULL);Note
Errors related to reward withdrawal will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t representing the reward account address from which rewards should be withdrawn.
- int64_t amount¶
[in] The amount of rewards to withdraw from the account, in lovelace.
- cardano_deferred_redeemer_fn_t callback¶
[in] The cardano_deferred_redeemer_fn_t callback producing the redeemer payload.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.
-
void cardano_sub_tx_builder_withdraw_rewards_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, int64_t amount, cardano_plutus_data_t *redeemer)¶
Withdraws rewards from a specified reward account using a string address in the sub transaction builder.
This function behaves like
cardano_sub_tx_builder_withdraw_rewardsbut accepts the reward account as a Bech32 string. The same rules apply, including that the account must be registered before the batch, which the builder does not check.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_addr = "stake1u9..."; // Reward address in string format size_t address_size = strlen(reward_addr); // Length of the reward address string cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_withdraw_rewards_ex(sub_tx_builder, reward_addr, address_size, 966584122, redeemer);Note
Errors related to reward withdrawal will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- const char *reward_address¶
[in] A string representing the reward account address from which rewards are to be withdrawn.
- size_t address_size¶
[in] The size of the reward address string in bytes.
- int64_t amount¶
[in] The amount of rewards to withdraw from the account, in lovelace.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_register_reward_address(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, cardano_plutus_data_t *redeemer)¶
Registers a staking reward address.
This function adds a staking reward address to be registered in the sub transaction, allowing the specified reward account to start receiving staking rewards. The key deposit of the registration is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_addr = ...; // Reward address to register cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_register_reward_address(sub_tx_builder, reward_addr, redeemer);Note
Any errors related to reward address registration will be reported when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance used for constructing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t representing the reward account to be registered.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_register_reward_address_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, cardano_plutus_data_t *redeemer)¶
Registers a staking reward address using a Bech32 address string.
This function behaves like
cardano_sub_tx_builder_register_reward_addressbut accepts the reward account as a Bech32 string.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1uxxx..."; size_t address_size = strlen(reward_address); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_register_reward_address_ex(sub_tx_builder, reward_address, address_size, redeemer);Note
Errors related to the reward address registration will be reported only when
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction construction.
- const char *reward_address¶
[in] A pointer to a bech32 string representing the reward address.
- size_t address_size¶
[in] The size of the
reward_addressstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_deregister_reward_address(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, cardano_plutus_data_t *redeemer)¶
Deregisters a staking reward address.
This function deregisters the reward address, effectively preventing it from receiving future staking rewards. The key deposit the deregistration gives back is value consumed by the sub transaction, so it is part of the imbalance the batch has to match.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address to be deregistered cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_deregister_reward_address(sub_tx_builder, reward_address, redeemer);Note
Errors related to the deregistration process are deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t structure representing the reward address to deregister.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_deregister_reward_address_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, cardano_plutus_data_t *redeemer)¶
Deregisters a staking reward address using a Bech32 address string.
This function behaves like
cardano_sub_tx_builder_deregister_reward_addressbut accepts the reward account as a Bech32 string.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1uxxx..."; // Reward address in string format size_t address_size = strlen(reward_address); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_deregister_reward_address_ex(sub_tx_builder, reward_address, address_size, redeemer);Note
Errors related to the deregistration process are deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *reward_address¶
[in] A pointer to a bech32 string containing the reward address to be deregistered.
- size_t address_size¶
[in] The length of the reward address string.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_delegate_stake(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, cardano_blake2b_hash_t *pool_id, cardano_plutus_data_t *redeemer)¶
Delegates stake from a specified staking reward address to a staking pool.
This function delegates stake from a specified staking reward address to a staking pool, identified by its unique pool ID.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for staking cardano_blake2b_hash_t* pool_id = ...; // Pool ID to delegate stake to cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_delegate_stake(sub_tx_builder, reward_address, pool_id, redeemer);Note
Any errors associated with this delegation action will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t representing the staking reward address to delegate.
- cardano_blake2b_hash_t *pool_id¶
[in] A pointer to the cardano_blake2b_hash_t representing the hash ID of the pool to delegate to.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_delegate_stake_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, const char *pool_id, size_t pool_id_size, cardano_plutus_data_t *redeemer)¶
Delegates stake from a specified staking reward address to a staking pool using string identifiers.
This function behaves like
cardano_sub_tx_builder_delegate_stakebut accepts the reward address and the pool ID as Bech32 strings.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; size_t reward_address_size = strlen(reward_address); const char* pool_id = "pool1xy..."; size_t pool_id_size = strlen(pool_id); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_delegate_stake_ex(sub_tx_builder, reward_address, reward_address_size, pool_id, pool_id_size, redeemer);Note
Errors related to this action will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *reward_address¶
[in] A bech32 string representing the staking reward address for delegation.
- size_t address_size¶
[in] The size of the
reward_addressstring.- const char *pool_id¶
[in] A bech32 string representing the pool ID to which stake is delegated.
- size_t pool_id_size¶
[in] The size of the
pool_idstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_delegate_voting_power(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *address, cardano_drep_t *drep, cardano_plutus_data_t *redeemer)¶
Adds a voting power delegation to a DRep for governance purposes.
This function enables delegating voting power from a specified reward address to a DRep.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address delegating voting power cardano_drep_t* drep = ...; // DRep receiving the delegated voting power cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_delegate_voting_power(sub_tx_builder, reward_address, drep, redeemer);Note
Errors associated with this delegation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_reward_address_t *address¶
[in] A pointer to the cardano_reward_address_t representing the staking reward address that is delegating voting power.
- cardano_drep_t *drep¶
[in] A pointer to the cardano_drep_t structure that identifies the decentralized representative receiving the delegated voting power.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_delegate_voting_power_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t address_size, const char *drep_id, size_t drep_id_size, cardano_plutus_data_t *redeemer)¶
Delegates voting power to a DRep using string identifiers.
This function behaves like
cardano_sub_tx_builder_delegate_voting_powerbut accepts the reward address and the DRep ID as strings. The DRep ID can be provided in either CIP-105 or CIP-129 format.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; // Reward address delegating voting power size_t address_size = strlen(reward_address); const char* drep_id = "drep1q..."; // DRep ID in CIP-129 format size_t drep_id_size = strlen(drep_id); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_delegate_voting_power_ex(sub_tx_builder, reward_address, address_size, drep_id, drep_id_size, redeemer);Note
The DRep ID must conform to either CIP-105 or CIP-129 format. Errors related to this delegation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *reward_address¶
[in] A string representing the staking reward address for the account delegating voting power.
- size_t address_size¶
[in] The length of the
reward_addressstring.- const char *drep_id¶
[in] A string representing the ID of the decentralized representative (DRep) receiving the voting power. The DRep ID can be in CIP-105 or CIP-129 format.
- size_t drep_id_size¶
[in] The length of the
drep_idstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_register_drep(cardano_sub_tx_builder_t *builder, cardano_drep_t *drep, cardano_anchor_t *anchor, cardano_plutus_data_t *redeemer)¶
Registers a DRep in the sub transaction.
This function registers a DRep with an optional anchor in the sub transaction being constructed. The DRep deposit of the registration is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_drep_t* drep = ...; // DRep to register cardano_anchor_t* anchor = ...; // Optional governance anchor cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_register_drep(sub_tx_builder, drep, anchor, redeemer);Note
Errors related to this registration will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_drep_t *drep¶
[in] A pointer to the cardano_drep_t instance representing the decentralized representative to be registered.
- cardano_anchor_t *anchor¶
[in] An optional pointer to a cardano_anchor_t instance pointing to the metadata of the DRep.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_register_drep_ex(cardano_sub_tx_builder_t *builder, const char *drep_id, size_t drep_id_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, cardano_plutus_data_t *redeemer)¶
Registers a DRep by ID in the sub transaction.
This function behaves like
cardano_sub_tx_builder_register_drepbut accepts the DRep ID and the anchor as strings. The DRep ID must be provided in either CIP-105 or CIP-129 bech32 format.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* drep_id = "drep1q..."; size_t drep_id_size = strlen(drep_id); const char* metadata_url = "https://example.com/drep_metadata.json"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "abcdef123456..."; // Hex-encoded hash of metadata file size_t metadata_hash_hex_size = strlen(metadata_hash_hex); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_register_drep_ex( sub_tx_builder, drep_id, drep_id_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size);Note
The
drep_idmust be in bech32 format as specified by either CIP-105 or CIP-129, which differ in their internal binary encoding. Errors related to this registration will be deferred untilcardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *drep_id¶
[in] A pointer to a character array containing the DRep ID in bech32 format (either CIP-105 or CIP-129).
- size_t drep_id_size¶
[in] The size of the
drep_idstring.- const char *metadata_url¶
[in] The URL pointing to the DRep metadata file.
- size_t metadata_url_size¶
[in] The size of the
metadata_urlstring.- const char *metadata_hash_hex¶
[in] The hash of the DRep metadata file in hexadecimal format.
- size_t metadata_hash_hex_size¶
[in] The size of the
metadata_hash_hexstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_update_drep(cardano_sub_tx_builder_t *builder, cardano_drep_t *drep, cardano_anchor_t *anchor, cardano_plutus_data_t *redeemer)¶
Updates an existing DRep in the sub transaction.
This function allows updating a DRep in the sub transaction with a specified DRep object, optionally providing a new anchor.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_drep_t* drep = ...; // DRep object to update cardano_anchor_t* anchor = ...; // Optional anchor cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_update_drep(sub_tx_builder, drep, anchor, redeemer);Note
Any errors related to updating the DRep will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_drep_t *drep¶
[in] A pointer to the cardano_drep_t instance representing the DRep to be updated.
- cardano_anchor_t *anchor¶
[in] An optional pointer to a cardano_anchor_t instance pointing to the metadata of the DRep.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_update_drep_ex(cardano_sub_tx_builder_t *builder, const char *drep_id, size_t drep_id_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, cardano_plutus_data_t *redeemer)¶
Updates an existing DRep in the sub transaction by ID.
This function behaves like
cardano_sub_tx_builder_update_drepbut accepts the DRep ID and the anchor as strings. The DRep ID must be provided in either CIP-105 or CIP-129 bech32 format.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* drep_id = "drep1q..."; size_t drep_id_size = strlen(drep_id); const char* metadata_url = "https://example.com/drep_metadata.json"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "abcdef123456..."; // Hex-encoded hash of metadata file size_t metadata_hash_hex_size = strlen(metadata_hash_hex); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_update_drep_ex( sub_tx_builder, drep_id, drep_id_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size);Note
The
drep_idmust be in bech32 format as specified by either CIP-105 or CIP-129, which differ in their internal binary encoding. Errors associated with updating the DRep will be deferred untilcardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *drep_id¶
[in] A pointer to a character array containing the DRep ID in bech32 format (either CIP-105 or CIP-129).
- size_t drep_id_size¶
[in] The size of the
drep_idstring.- const char *metadata_url¶
[in] The URL pointing to the DRep metadata file.
- size_t metadata_url_size¶
[in] The size of the
metadata_urlstring.- const char *metadata_hash_hex¶
[in] The hash of the DRep metadata file in hexadecimal format.
- size_t metadata_hash_hex_size¶
[in] The size of the
metadata_hash_hexstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_deregister_drep(cardano_sub_tx_builder_t *builder, cardano_drep_t *drep, cardano_plutus_data_t *redeemer)¶
Deregisters an existing DRep.
This function deregisters a DRep. The DRep deposit the deregistration gives back is value consumed by the sub transaction, so it is part of the imbalance the batch has to match.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_drep_t* drep = ...; // DRep to deregister cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_deregister_drep(sub_tx_builder, drep, redeemer);Note
Errors related to deregistering the DRep will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_drep_t *drep¶
[in] A pointer to the cardano_drep_t instance representing the DRep to deregister.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_deregister_drep_ex(cardano_sub_tx_builder_t *builder, const char *drep_id, size_t drep_id_size, cardano_plutus_data_t *redeemer)¶
Deregisters an existing DRep by ID.
This function behaves like
cardano_sub_tx_builder_deregister_drepbut accepts the DRep ID as a string. The DRep ID must conform to either CIP-105 or CIP-129 standards.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* drep_id = "drep1q..."; // DRep ID in CIP-105 format size_t drep_id_size = strlen(drep_id); cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_deregister_drep_ex(sub_tx_builder, drep_id, drep_id_size, redeemer);Note
The
drep_idmust be in bech32 format as specified by either CIP-105 or CIP-129, which differ in their internal binary encoding. Errors related to deregistering the DRep will be deferred untilcardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- const char *drep_id¶
[in] A pointer to a character array containing the DRep ID in bech32 format (either CIP-105 or CIP-129).
- size_t drep_id_size¶
[in] The size of the
drep_idstring.- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_vote(cardano_sub_tx_builder_t *builder, cardano_voter_t *voter, cardano_governance_action_id_t *action_id, cardano_voting_procedure_t *vote, cardano_plutus_data_t *redeemer)¶
Registers a vote for a specified governance action within the sub transaction.
This function allows a voter to submit their vote for a given governance action. A voter identified by a key or by a native script needs no redeemer. A voter identified by a PlutusV4 script needs a redeemer, evaluated natively when the sub transaction is built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_voter_t* voter = ...; // Voter information cardano_governance_action_id_t* action_id = ...; // Governance action ID cardano_voting_procedure_t* vote = ...; // Voting procedure with choice cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_vote(sub_tx_builder, voter, action_id, vote, redeemer);Note
Errors related to the voting operation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_voter_t *voter¶
[in] A pointer to a cardano_voter_t structure representing the voter participating in the governance action.
- cardano_governance_action_id_t *action_id¶
[in] A pointer to a cardano_governance_action_id_t identifying the governance action being voted on.
- cardano_voting_procedure_t *vote¶
[in] A pointer to a cardano_voting_procedure_t defining the voting procedure and choice.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_vote_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_voter_t *voter, cardano_governance_action_id_t *action_id, cardano_voting_procedure_t *vote, cardano_deferred_redeemer_fn_t callback, void *user_context)¶
Casts a vote whose redeemer payload is produced by a deferred callback.
Behaves like cardano_sub_tx_builder_vote, but the redeemer payload of the PlutusV4 script voter is built by the callback from the body of the sub transaction when it is built. See cardano_sub_tx_builder_add_input_with_deferred_redeemer. The cardano_transaction_find_vote_index function can be used to look up the position of the voter in ledger voter order, which is the voting redeemer index, from inside the callback.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_voter_t* voter = ...; // Voter identified by a PlutusV4 script cardano_governance_action_id_t* action_id = ...; // Governance action ID cardano_voting_procedure_t* vote = ...; // Voting procedure with choice cardano_deferred_redeemer_fn_t callback = ...; // Builds the redeemer from the sub transaction body cardano_sub_tx_builder_vote_with_deferred_redeemer(sub_tx_builder, voter, action_id, vote, callback, NULL);Note
Errors related to the voting operation will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_voter_t *voter¶
[in] A pointer to a cardano_voter_t structure representing the voter participating in the governance action.
- cardano_governance_action_id_t *action_id¶
[in] A pointer to a cardano_governance_action_id_t identifying the governance action being voted on.
- cardano_voting_procedure_t *vote¶
[in] A pointer to a cardano_voting_procedure_t defining the voting procedure and choice.
- cardano_deferred_redeemer_fn_t callback¶
[in] The cardano_deferred_redeemer_fn_t callback producing the redeemer payload.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.
-
void cardano_sub_tx_builder_add_certificate(cardano_sub_tx_builder_t *builder, cardano_certificate_t *certificate, cardano_plutus_data_t *redeemer)¶
Adds a certificate to the sub transaction.
This function adds a specified certificate to the sub transaction being constructed. Certificates are used to perform various actions on the blockchain, such as staking, delegating, or registering/deregistering entities. A certificate whose credential is a key or a native script needs no redeemer. One whose credential is a PlutusV4 script needs a redeemer, evaluated natively when the sub transaction is built.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_certificate_t* certificate = ...; // Certificate to add cardano_plutus_data_t* redeemer = ...; // Optional redeemer for the PlutusV4 script cardano_sub_tx_builder_add_certificate(sub_tx_builder, certificate, redeemer);Note
Errors related to the certificate addition will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_certificate_t *certificate¶
[in] A pointer to a cardano_certificate_t structure representing the certificate to add.
- cardano_plutus_data_t *redeemer¶
[in] A pointer to the cardano_plutus_data_t structure representing the redeemer for the PlutusV4 script (optional; can be NULL).
-
void cardano_sub_tx_builder_add_certificate_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_certificate_t *certificate, cardano_deferred_redeemer_fn_t callback, void *user_context)¶
Adds a certificate whose redeemer payload is produced by a deferred callback.
Behaves like cardano_sub_tx_builder_add_certificate, but the redeemer payload of the PlutusV4 script credential is built by the callback from the body of the sub transaction when it is built. See cardano_sub_tx_builder_add_input_with_deferred_redeemer. The cardano_transaction_find_certificate_index function can be used to look up the position of the certificate from inside the callback.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_certificate_t* certificate = ...; // Certificate of a PlutusV4 script credential cardano_deferred_redeemer_fn_t callback = ...; // Builds the redeemer from the sub transaction body cardano_sub_tx_builder_add_certificate_with_deferred_redeemer(sub_tx_builder, certificate, callback, NULL);Note
Errors related to the certificate addition will be deferred until
cardano_sub_tx_builder_buildis called.- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance managing the sub transaction.
- cardano_certificate_t *certificate¶
[in] A pointer to a cardano_certificate_t structure representing the certificate to add.
- cardano_deferred_redeemer_fn_t callback¶
[in] The cardano_deferred_redeemer_fn_t callback producing the redeemer payload.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.
-
void cardano_sub_tx_builder_propose_parameter_change(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_protocol_param_update_t *protocol_param_update, cardano_governance_action_id_t *governance_action_id, cardano_blake2b_hash_t *policy_hash)¶
Proposes a parameter change within a sub transaction.
This function adds a parameter change proposal to the sub transaction being built. The proposal specifies updates to protocol parameters, a governance action ID, and other metadata associated with the proposal. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
The proposal is validated by the guardrails script, so it carries a proposing redeemer at the index of the proposal. The index is local to the body of the sub transaction and the execution units are computed with the native evaluator when cardano_sub_tx_builder_build is called.
This convenience function uses Plutus unit (
d87980) as the proposing redeemer. Use cardano_sub_tx_builder_add_proposal for a custom redeemer, or cardano_sub_tx_builder_add_proposal_with_deferred_redeemer to compute it after balancing.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for deposit refund cardano_anchor_t* anchor = ...; // Anchor metadata for the proposal cardano_protocol_param_update_t* param_update = ...; // Protocol parameter updates cardano_governance_action_id_t* gov_action_id = ...; // Optional governance action ID cardano_blake2b_hash_t* policy_hash = ...; // Guardrails script hash cardano_sub_tx_builder_propose_parameter_change(sub_tx_builder, reward_address, anchor, param_update, gov_action_id, policy_hash);Note
The guardrails script must be a PlutusV4 script, and it must be added to the sub transaction with cardano_sub_tx_builder_add_script or be available through a reference input. A PlutusV1, PlutusV2 or PlutusV3 guardrails script can not run inside a sub transaction, so cardano_sub_tx_builder_build returns
CARDANO_ERROR_INVALID_SCRIPT_LANGUAGEin that case.Note
Any errors encountered during the addition of the parameter change proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to the cardano_sub_tx_builder_t instance used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t where the deposit will be refunded.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object representing the anchor for the proposal. This parameter must not be NULL.
- cardano_protocol_param_update_t *protocol_param_update¶
[in] A pointer to a cardano_protocol_param_update_t object containing the protocol parameter updates. This parameter must not be NULL.
- cardano_governance_action_id_t *governance_action_id¶
[in] A pointer to a cardano_governance_action_id_t object referencing the most recent enacted action of the same type. This parameter can be NULL if no proposals of this type have been enacted on the network.
- cardano_blake2b_hash_t *policy_hash¶
[in] A pointer to a cardano_blake2b_hash_t object representing the guardrails script hash (also known as the governance action policy script). This parameter must not be NULL.
-
void cardano_sub_tx_builder_propose_parameter_change_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *gov_action_id, size_t gov_action_id_size, const char *policy_hash_hash_hex, size_t policy_hash_hash_hex_size, cardano_protocol_param_update_t *protocol_param_update)¶
Proposes a parameter change within a sub transaction using extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_parameter_changebut accepts the reward address, the anchor, the governance action ID and the guardrails script hash as strings.This convenience function uses Plutus unit (
d87980) as the proposing redeemer. Use cardano_sub_tx_builder_add_proposal for a custom redeemer, or cardano_sub_tx_builder_add_proposal_with_deferred_redeemer to compute it after balancing.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9hwrj..."; // Reward address in Bech32 const char* metadata_url = "https://example.com/metadata.json"; const char* metadata_hash = "d2a4f89b..."; // Metadata hash in hexadecimal const char* gov_action_id = "gov_action1..."; // Governance action ID in CIP-129 format const char* policy_hash = "f4a6b3e..."; // Guardrails script hash in hexadecimal cardano_protocol_param_update_t* param_update = ...; // Protocol parameter updates cardano_sub_tx_builder_propose_parameter_change_ex( sub_tx_builder, reward_address, strlen(reward_address), metadata_url, strlen(metadata_url), metadata_hash, strlen(metadata_hash), gov_action_id, strlen(gov_action_id), policy_hash, strlen(policy_hash), param_update);Note
The guardrails script must be a PlutusV4 script, otherwise cardano_sub_tx_builder_build returns
CARDANO_ERROR_INVALID_SCRIPT_LANGUAGE.Note
Any errors encountered during the addition of the parameter change proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to the cardano_sub_tx_builder_t instance used to build the sub transaction.
- const char *reward_address¶
[in] A string representation of the reward address where the deposit will be refunded.
- size_t reward_address_size¶
[in] The size (in bytes) of the
reward_addressstring.- const char *metadata_url¶
[in] A string containing the URL pointing to additional metadata for the proposal.
- size_t metadata_url_size¶
[in] The size (in bytes) of the
metadata_urlstring.- const char *metadata_hash_hex¶
[in] A hexadecimal string representing the hash of the metadata contents.
- size_t metadata_hash_hex_size¶
[in] The size (in bytes) of the
metadata_hash_hexstring.- const char *gov_action_id¶
[in] A CIP-0129 bech32 string representing the governance action ID that references the most recent enacted action of the same type.
- size_t gov_action_id_size¶
[in] The size (in bytes) of the
gov_action_idstring.- const char *policy_hash_hash_hex¶
[in] A hexadecimal string representing the guardrails script hash (also known as the governance action policy script).
- size_t policy_hash_hash_hex_size¶
[in] The size (in bytes) of the
policy_hash_hash_hexstring.- cardano_protocol_param_update_t *protocol_param_update¶
[in] A pointer to a cardano_protocol_param_update_t object containing the protocol parameter updates. This parameter must not be NULL.
-
void cardano_sub_tx_builder_propose_hardfork(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_protocol_version_t *version, cardano_governance_action_id_t *governance_action_id)¶
Proposes a hard fork within a sub transaction.
This function adds a proposal to initiate a hard fork in the Cardano network to the sub transaction being built. The hard fork proposal specifies the target protocol version and other required parameters. An optional governance action ID can be provided to reference the most recent enacted hard fork action of the same type. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for deposit refund cardano_anchor_t* anchor = ...; // Anchor metadata for the proposal cardano_protocol_version_t* version = ...; // Target protocol version cardano_governance_action_id_t* gov_action_id = ...; // Optional governance action ID cardano_sub_tx_builder_propose_hardfork(sub_tx_builder, reward_address, anchor, version, gov_action_id);Note
Errors encountered during the addition of the hard fork proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to the cardano_sub_tx_builder_t instance used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t object where the deposit will be refunded.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object containing additional metadata related to the proposal.
- cardano_protocol_version_t *version¶
[in] A pointer to a cardano_protocol_version_t object specifying the target protocol version for the hard fork.
- cardano_governance_action_id_t *governance_action_id¶
[in] An optional pointer to a cardano_governance_action_id_t object referencing the most recent enacted governance action of the same type. This can be NULL if no such action has been enacted.
-
void cardano_sub_tx_builder_propose_hardfork_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *gov_action_id, size_t gov_action_id_size, uint64_t minor_protocol_version, uint64_t major_protocol_version)¶
Proposes a hard fork within a sub transaction (extended version).
This function behaves like
cardano_sub_tx_builder_propose_hardforkbut accepts the reward address, the anchor and the governance action ID as strings, and the target protocol version as numbers.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u..."; size_t reward_address_size = strlen(reward_address); const char* metadata_url = "https://example.com/metadata.json"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash = "abcdef1234567890..."; size_t metadata_hash_size = strlen(metadata_hash); const char* gov_action_id = "gov_action1..."; size_t gov_action_id_size = strlen(gov_action_id); cardano_sub_tx_builder_propose_hardfork_ex( sub_tx_builder, reward_address, reward_address_size, metadata_url, metadata_url_size, metadata_hash, metadata_hash_size, gov_action_id, gov_action_id_size, 0, 12);Note
Errors encountered during the addition of the hard fork proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to the cardano_sub_tx_builder_t instance used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to the reward address string where the deposit will be refunded. This must be a valid Bech32-encoded reward address.
- size_t reward_address_size¶
[in] The size of the reward address string in bytes.
- const char *metadata_url¶
[in] A pointer to the URL string containing metadata about the hard fork proposal.
- size_t metadata_url_size¶
[in] The size of the metadata URL string in bytes.
- const char *metadata_hash_hex¶
[in] A pointer to the hexadecimal string representing the hash of the metadata file.
- size_t metadata_hash_hex_size¶
[in] The size of the metadata hash string in bytes.
- const char *gov_action_id¶
[in] A CIP-0129 bech32 string representing the governance action ID that references the most recent enacted action of the same type.
- size_t gov_action_id_size¶
[in] The size (in bytes) of the
gov_action_idstring.- uint64_t minor_protocol_version¶
[in] The minor protocol version for the proposed hard fork.
- uint64_t major_protocol_version¶
[in] The major protocol version for the proposed hard fork.
-
void cardano_sub_tx_builder_propose_treasury_withdrawals(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_withdrawal_map_t *withdrawals, cardano_blake2b_hash_t *policy_hash)¶
Proposes treasury withdrawals within a sub transaction.
This function prepares a proposal to withdraw funds from the treasury. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
The proposal is validated by the guardrails script, so it carries a proposing redeemer at the index of the proposal. The index is local to the body of the sub transaction and the execution units are computed with the native evaluator when cardano_sub_tx_builder_build is called.
This convenience function uses Plutus unit (
d87980) as the proposing redeemer. Use cardano_sub_tx_builder_add_proposal for a custom redeemer, or cardano_sub_tx_builder_add_proposal_with_deferred_redeemer to compute it after balancing.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for deposit refund cardano_anchor_t* anchor = ...; // Metadata for the proposal cardano_withdrawal_map_t* withdrawals = ...; // Treasury withdrawals cardano_blake2b_hash_t* policy_hash = ...; // Guardrails script hash cardano_sub_tx_builder_propose_treasury_withdrawals(sub_tx_builder, reward_address, anchor, withdrawals, policy_hash);Note
The guardrails script must be a PlutusV4 script, and it must be added to the sub transaction with cardano_sub_tx_builder_add_script or be available through a reference input. A PlutusV1, PlutusV2 or PlutusV3 guardrails script can not run inside a sub transaction, so cardano_sub_tx_builder_build returns
CARDANO_ERROR_INVALID_SCRIPT_LANGUAGEin that case.Note
Any errors encountered during the addition of the treasury withdrawals proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t object representing the address that will receive the deposit refund.
- cardano_anchor_t *anchor¶
[in] A pointer to an initialized cardano_anchor_t object containing metadata about the proposal.
- cardano_withdrawal_map_t *withdrawals¶
[in] A pointer to a cardano_withdrawal_map_t object defining the requested treasury withdrawals.
- cardano_blake2b_hash_t *policy_hash¶
[in] A pointer to a cardano_blake2b_hash_t object representing the guardrails script hash. This parameter must not be NULL.
-
void cardano_sub_tx_builder_propose_treasury_withdrawals_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *policy_hash_hash_hex, size_t policy_hash_hash_hex_size, cardano_withdrawal_map_t *withdrawals)¶
Proposes treasury withdrawals within a sub transaction using extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_treasury_withdrawalsbut accepts the reward address, the anchor and the guardrails script hash as strings.This convenience function uses Plutus unit (
d87980) as the proposing redeemer. Use cardano_sub_tx_builder_add_proposal for a custom redeemer, or cardano_sub_tx_builder_add_proposal_with_deferred_redeemer to compute it after balancing.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9v8lkxklxyz123"; const char* metadata_url = "https://example.com/metadata"; const char* metadata_hash = "abc123"; // Metadata hash in hex const char* policy_hash = "def456"; // Guardrails script hash in hex cardano_withdrawal_map_t* withdrawals = ...; // Treasury withdrawals cardano_sub_tx_builder_propose_treasury_withdrawals_ex( sub_tx_builder, reward_address, strlen(reward_address), metadata_url, strlen(metadata_url), metadata_hash, strlen(metadata_hash), policy_hash, strlen(policy_hash), withdrawals);Note
The guardrails script must be a PlutusV4 script, otherwise cardano_sub_tx_builder_build returns
CARDANO_ERROR_INVALID_SCRIPT_LANGUAGE.Note
Any errors encountered during the addition of the treasury withdrawals proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to the reward address string for receiving the deposit refund. Must be a valid Bech32 address.
- size_t reward_address_size¶
[in] The size of the reward address string.
- const char *metadata_url¶
[in] A pointer to the metadata URL string providing additional proposal context.
- size_t metadata_url_size¶
[in] The size of the metadata URL string.
- const char *metadata_hash_hex¶
[in] A pointer to the hexadecimal string representation of the metadata hash.
- size_t metadata_hash_hex_size¶
[in] The size of the metadata hash string.
- const char *policy_hash_hash_hex¶
[in] A pointer to the hexadecimal string representation of the guardrails script hash.
- size_t policy_hash_hash_hex_size¶
[in] The size of the guardrails script hash string.
- cardano_withdrawal_map_t *withdrawals¶
[in] A pointer to a cardano_withdrawal_map_t object defining the requested treasury withdrawals.
-
void cardano_sub_tx_builder_propose_no_confidence(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_governance_action_id_t *governance_action_id)¶
Proposes a no-confidence governance action within a sub transaction.
This function prepares a proposal for a no-confidence action against the current constitutional committee. If enacted, it signals the community’s lack of confidence in the committee, potentially leading to its reconstitution. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for deposit refund cardano_anchor_t* anchor = ...; // Anchor metadata for the proposal cardano_governance_action_id_t* action_id = ...; // Optional governance action ID cardano_sub_tx_builder_propose_no_confidence(sub_tx_builder, reward_address, anchor, action_id);Note
Any errors encountered during the addition of the no-confidence proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t object. This address will receive the deposit refund after the governance action completes.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object providing additional context or metadata for the governance action.
- cardano_governance_action_id_t *governance_action_id¶
[in] An optional pointer to a cardano_governance_action_id_t object. This represents the unique identifier for the most recently enacted action of the same type. This parameter can be NULL if no previous actions of this type exist.
-
void cardano_sub_tx_builder_propose_no_confidence_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *gov_action_id, size_t gov_action_id_size)¶
Proposes a no-confidence governance action using extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_no_confidencebut accepts the reward address, the anchor and the governance action ID as strings.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; size_t reward_address_size = strlen(reward_address); const char* metadata_url = "https://example.com"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "a1b2c3..."; size_t metadata_hash_hex_size = strlen(metadata_hash_hex); const char* gov_action_id = "gov_action1..."; size_t gov_action_id_size = strlen(gov_action_id); cardano_sub_tx_builder_propose_no_confidence_ex(sub_tx_builder, reward_address, reward_address_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size, gov_action_id, gov_action_id_size);Note
Any errors encountered during the addition of the no-confidence proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to a string containing the Bech32-encoded reward address. This address will receive the deposit refund after the governance action completes.
- size_t reward_address_size¶
[in] The size of the reward address string in bytes.
- const char *metadata_url¶
[in] A pointer to a string containing the metadata URL for additional context regarding the proposal.
- size_t metadata_url_size¶
[in] The size of the metadata URL string in bytes.
- const char *metadata_hash_hex¶
[in] A pointer to a string containing the hexadecimal representation of the metadata hash.
- size_t metadata_hash_hex_size¶
[in] The size of the metadata hash string in bytes.
- const char *gov_action_id¶
[in] A CIP-0129 bech32 string representing the governance action ID that references the most recent enacted action of the same type.
- size_t gov_action_id_size¶
[in] The size (in bytes) of the
gov_action_idstring.
-
void cardano_sub_tx_builder_propose_update_committee(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_governance_action_id_t *governance_action_id, cardano_credential_set_t *members_to_be_removed, cardano_committee_members_map_t *members_to_be_added, cardano_unit_interval_t *new_quorum)¶
Proposes an update to the Cardano constitutional committee.
This function prepares a governance action to update the Cardano constitutional committee. The proposal specifies:
Committee members to be added.
Committee members to be removed.
The new quorum threshold for the committee.
The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address to receive refund cardano_anchor_t* anchor = ...; // Governance action anchor cardano_governance_action_id_t* gov_action_id = ...; // Most recently enacted action ID cardano_credential_set_t* members_to_remove = ...; // Members to be removed cardano_committee_members_map_t* members_to_add = ...; // Members to be added cardano_unit_interval_t* new_quorum = ...; // New quorum threshold cardano_sub_tx_builder_propose_update_committee(sub_tx_builder, reward_address, anchor, gov_action_id, members_to_remove, members_to_add, new_quorum);Note
Any errors encountered during the addition of the update committee proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t object representing the reward address that will receive the deposit refund.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object representing the anchor for this governance action.
- cardano_governance_action_id_t *governance_action_id¶
[in] An optional pointer to a cardano_governance_action_id_t object representing the most recently enacted governance action of the same type. Can be NULL if no such prior action exists.
- cardano_credential_set_t *members_to_be_removed¶
[in] A pointer to a cardano_credential_set_t object specifying the committee members to be removed.
- cardano_committee_members_map_t *members_to_be_added¶
[in] A pointer to a cardano_committee_members_map_t object specifying the committee members to be added.
- cardano_unit_interval_t *new_quorum¶
[in] A pointer to a cardano_unit_interval_t object specifying the new quorum threshold for the committee.
-
void cardano_sub_tx_builder_propose_update_committee_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *gov_action_id, size_t gov_action_id_size, cardano_credential_set_t *members_to_be_removed, cardano_committee_members_map_t *members_to_be_added, double new_quorum)¶
Proposes an update to the Cardano constitutional committee with extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_update_committeebut accepts the reward address, the anchor and the governance action ID as strings, and the new quorum threshold as a number.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; size_t reward_address_size = strlen(reward_address); const char* metadata_url = "https://example.com/proposal.json"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "abc123..."; size_t metadata_hash_hex_size = strlen(metadata_hash_hex); const char* gov_action_id = "gov_action1..."; size_t gov_action_id_size = strlen(gov_action_id); cardano_credential_set_t* members_to_remove = ...; // Members to be removed cardano_committee_members_map_t* members_to_add = ...; // Members to be added cardano_sub_tx_builder_propose_update_committee_ex(sub_tx_builder, reward_address, reward_address_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size, gov_action_id, gov_action_id_size, members_to_remove, members_to_add, 0.3);Note
Any errors encountered during the addition of the update committee proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to a string containing the reward address (in Bech32 format) that will receive the deposit refund.
- size_t reward_address_size¶
[in] The size of the
reward_addressstring.- const char *metadata_url¶
[in] A pointer to a string containing the URL for the governance action metadata.
- size_t metadata_url_size¶
[in] The size of the
metadata_urlstring.- const char *metadata_hash_hex¶
[in] A pointer to a string containing the hex-encoded hash of the metadata file.
- size_t metadata_hash_hex_size¶
[in] The size of the
metadata_hash_hexstring.- const char *gov_action_id¶
[in] A CIP-0129 bech32 string representing the governance action ID that references the most recent enacted action of the same type.
- size_t gov_action_id_size¶
[in] The size (in bytes) of the
gov_action_idstring.- cardano_credential_set_t *members_to_be_removed¶
[in] A pointer to a cardano_credential_set_t object specifying the committee members to be removed.
- cardano_committee_members_map_t *members_to_be_added¶
[in] A pointer to a cardano_committee_members_map_t object specifying the committee members to be added.
- double new_quorum¶
[in] The new quorum threshold for the committee.
-
void cardano_sub_tx_builder_propose_new_constitution(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor, cardano_governance_action_id_t *governance_action_id, cardano_constitution_t *constitution)¶
Proposes a new constitution for the Cardano network.
This function creates a governance action to propose a new constitution. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address to refund deposit cardano_anchor_t* anchor = ...; // Anchor metadata cardano_governance_action_id_t* gov_action_id = ...; // Optional governance action ID cardano_constitution_t* constitution = ...; // Constitution details cardano_sub_tx_builder_propose_new_constitution(sub_tx_builder, reward_address, anchor, gov_action_id, constitution);Note
Any errors encountered during the addition of the new constitution proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to a cardano_reward_address_t object representing the address that will receive the deposit refund.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object containing the anchor metadata for the proposal.
- cardano_governance_action_id_t *governance_action_id¶
[in] An optional pointer to a cardano_governance_action_id_t object representing the governance action ID of the most recently enacted action of the same type. This parameter can be NULL if no prior action exists.
- cardano_constitution_t *constitution¶
[in] A pointer to a cardano_constitution_t object containing the new constitution’s details.
-
void cardano_sub_tx_builder_propose_new_constitution_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size, const char *gov_action_id, size_t gov_action_id_size, cardano_constitution_t *constitution)¶
Proposes a new constitution for the Cardano network using extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_new_constitutionbut accepts the reward address, the anchor and the governance action ID as strings.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; size_t reward_address_size = strlen(reward_address); const char* metadata_url = "https://example.com"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "abc123..."; size_t metadata_hash_hex_size = strlen(metadata_hash_hex); const char* gov_action_id = "gov_action1..."; size_t gov_action_id_size = strlen(gov_action_id); cardano_constitution_t* constitution = ...; // Constitution details cardano_sub_tx_builder_propose_new_constitution_ex( sub_tx_builder, reward_address, reward_address_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size, gov_action_id, gov_action_id_size, constitution);Note
Any errors encountered during the addition of the new constitution proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to the reward address as a string. The address will receive the deposit refund.
- size_t reward_address_size¶
[in] The size of the reward address string in bytes.
- const char *metadata_url¶
[in] A pointer to a string containing the URL for additional proposal metadata.
- size_t metadata_url_size¶
[in] The size of the metadata URL string in bytes.
- const char *metadata_hash_hex¶
[in] A pointer to a hexadecimal string representing the hash of the metadata file.
- size_t metadata_hash_hex_size¶
[in] The size of the metadata hash string in bytes.
- const char *gov_action_id¶
[in] A CIP-0129 bech32 string representing the governance action ID that references the most recent enacted action of the same type.
- size_t gov_action_id_size¶
[in] The size (in bytes) of the
gov_action_idstring.- cardano_constitution_t *constitution¶
[in] A pointer to a cardano_constitution_t object containing the new constitution’s details.
-
void cardano_sub_tx_builder_propose_info(cardano_sub_tx_builder_t *builder, cardano_reward_address_t *reward_address, cardano_anchor_t *anchor)¶
Proposes an informational governance action for the Cardano network.
This function creates a governance action proposal to share information with the network. The governance action deposit of the proposal is value produced by the sub transaction, so it is part of the imbalance the batch has to cover.
Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_reward_address_t* reward_address = ...; // Reward address for deposit refund cardano_anchor_t* anchor = ...; // Anchor metadata for the proposal cardano_sub_tx_builder_propose_info(sub_tx_builder, reward_address, anchor);Note
Any errors encountered during the addition of the informational proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- cardano_reward_address_t *reward_address¶
[in] A pointer to the reward address where the deposit refund will be sent if the proposal is enacted or discarded.
- cardano_anchor_t *anchor¶
[in] A pointer to a cardano_anchor_t object containing metadata such as URLs and hashes to link to external information.
-
void cardano_sub_tx_builder_propose_info_ex(cardano_sub_tx_builder_t *builder, const char *reward_address, size_t reward_address_size, const char *metadata_url, size_t metadata_url_size, const char *metadata_hash_hex, size_t metadata_hash_hex_size)¶
Proposes an informational governance action for the Cardano network using extended parameters.
This function behaves like
cardano_sub_tx_builder_propose_infobut accepts the reward address and the anchor as strings.Usage Example:
cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder const char* reward_address = "stake1u9..."; size_t reward_address_size = strlen(reward_address); const char* metadata_url = "https://example.com/proposal-metadata"; size_t metadata_url_size = strlen(metadata_url); const char* metadata_hash_hex = "abcdef123456..."; size_t metadata_hash_hex_size = strlen(metadata_hash_hex); cardano_sub_tx_builder_propose_info_ex( sub_tx_builder, reward_address, reward_address_size, metadata_url, metadata_url_size, metadata_hash_hex, metadata_hash_hex_size);Note
Any errors encountered during the addition of the informational proposal will be deferred until cardano_sub_tx_builder_build is called.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] A pointer to an initialized cardano_sub_tx_builder_t object used to build the sub transaction.
- const char *reward_address¶
[in] A pointer to the reward address in string format where the deposit refund will be sent if the proposal is enacted or discarded.
- size_t reward_address_size¶
[in] The size of the reward address string in bytes.
- const char *metadata_url¶
[in] A pointer to a string containing the URL for the proposal metadata.
- size_t metadata_url_size¶
[in] The size of the metadata URL string in bytes.
- const char *metadata_hash_hex¶
[in] A pointer to a string containing the hexadecimal hash of the metadata.
- size_t metadata_hash_hex_size¶
[in] The size of the metadata hash string in bytes.
-
cardano_error_t cardano_sub_tx_builder_build(cardano_sub_tx_builder_t *builder, cardano_sub_transaction_t **sub_transaction)¶
Builds the sub transaction from the current state of the sub transaction builder.
This function finalizes the sub transaction by aggregating all previously added inputs, outputs, minting operations and other data. The sub transaction is not balanced: it spends exactly the inputs and produces exactly the outputs that were added, and the difference is the intent a batcher matches against the rest of the batch. If any of the previous operations failed, this function reports the first error that was recorded.
When the sub transaction carries redeemers, this function sets the index of every spend redeemer to the position of its input in the sorted inputs, resolves the deferred redeemers against the body of the sub transaction, evaluates the redeemers natively against the UTXOs added as inputs and reference inputs, writes the computed execution units into the redeemers and sets the script data hash of the sub transaction. The indices of the mint, withdrawal, certificate, vote, proposal and guard redeemers are local to the sub transaction body. Building fails with CARDANO_ERROR_ELEMENT_NOT_FOUND when no Plutus script with the hash of a guard, of the payment credential of a spent input, of a minting policy, of a withdrawing account, of a certificate credential, of a voter or of the guardrails of a parameter change or treasury withdrawals proposal is added with
cardano_sub_tx_builder_add_scriptor carried as a reference script by one of those UTXOs, with CARDANO_ERROR_INVALID_SCRIPT_LANGUAGE when that script is a PlutusV1, PlutusV2 or PlutusV3 script, with CARDANO_ERROR_DECODING when a script cannot be deserialized, and with CARDANO_ERROR_SCRIPT_EVALUATION_FAILURE when a script fails phase-2 validation. The message of the failure is available through cardano_sub_tx_builder_get_last_error.An input locked by a datum hash whose datum was not provided to
cardano_sub_tx_builder_add_inputor tocardano_sub_tx_builder_add_input_with_deferred_redeemermakes this function fail with CARDANO_ERROR_ELEMENT_NOT_FOUND.A deferred redeemer callback that fails makes this function fail with the error of the callback, and one that produces no payload makes it fail with CARDANO_ERROR_POINTER_IS_NULL.
Every script purpose of the sub transaction whose script resolves to a Plutus script, among the scripts added with
cardano_sub_tx_builder_add_scriptand the reference scripts of the UTXOs added as inputs and reference inputs, must have a redeemer: spending an input locked by the script, minting under its policy, withdrawing from a reward account it controls, carrying a certificate it must authorize, voting with it as the voter, carrying a proposal it guards as the guardrails script or listing it among the guards. A purpose without its redeemer makes this function fail with CARDANO_ERROR_MISSING_REDEEMER before any script is evaluated, and the last error names the purpose, its redeemer index and the script hash. A purpose whose script is a native script needs no redeemer, and a purpose whose script is not provided is not reported.Usage Example:
cardano_sub_transaction_t* sub_transaction = NULL; cardano_sub_tx_builder_t* sub_tx_builder = ...; // Initialized sub transaction builder cardano_sub_tx_builder_add_input(sub_tx_builder, utxo, NULL, NULL); // Offer the value of a UTXO cardano_sub_tx_builder_send_lovelace_ex(sub_tx_builder, "add...", size, 50000); // Ask for an output in return cardano_sub_tx_builder_set_invalid_after(sub_tx_builder, 1000); // Set the sub transaction validity cardano_error_t result = cardano_sub_tx_builder_build(sub_tx_builder, &sub_transaction); if (result != CARDANO_SUCCESS) { const char* error_msg = cardano_sub_tx_builder_get_last_error(sub_tx_builder); printf("Failed to build sub transaction: %s\n", error_msg); } else { // Sub transaction successfully built; sign it and hand it to a batcher // ... cardano_sub_transaction_unref(&sub_transaction); } cardano_sub_tx_builder_unref(&sub_tx_builder);Note
All errors related to missing or invalid data will be reported upon calling this function. A builder can build a single sub transaction, further calls report CARDANO_ERROR_ILLEGAL_STATE.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance that manages the sub transaction details.
- cardano_sub_transaction_t **sub_transaction¶
[out] A pointer to a cardano_sub_transaction_t pointer where the created sub transaction will be stored upon success.
- Returns:¶
CARDANO_SUCCESS if the sub transaction was successfully built, or an appropriate error code if issues were detected.
-
void cardano_sub_tx_builder_unref(cardano_sub_tx_builder_t **sub_transaction_builder)¶
Decrements the reference count of a cardano_sub_tx_builder_t object.
This function is responsible for managing the lifecycle of a cardano_sub_tx_builder_t object by decreasing its reference count. When the reference count reaches zero, the sub_transaction_builder is finalized; its associated resources are released, and its memory is deallocated.
Usage Example:
cardano_sub_tx_builder_t* sub_transaction_builder = cardano_sub_tx_builder_new(params, &slot_config); // Perform operations with the sub_transaction_builder... cardano_sub_tx_builder_unref(&sub_transaction_builder); // At this point, sub_transaction_builder is NULL and cannot be used.Note
After calling cardano_sub_tx_builder_unref, the pointer to the cardano_sub_tx_builder_t object will be set to NULL to prevent its reuse.
- Parameters:¶
- cardano_sub_tx_builder_t **sub_transaction_builder¶
[inout] A pointer to the pointer of the sub_transaction_builder object. This double indirection allows the function to set the caller’s pointer to NULL, avoiding dangling pointer issues after the object has been freed.
-
void cardano_sub_tx_builder_ref(cardano_sub_tx_builder_t *sub_transaction_builder)¶
Increases the reference count of the cardano_sub_tx_builder_t object.
This function is used to manually increment the reference count of an cardano_sub_tx_builder_t object, indicating that another part of the code has taken ownership of it. This ensures the object remains allocated and valid until all owners have released their reference by calling cardano_sub_tx_builder_unref.
Usage Example:
// Assuming sub_transaction_builder is a previously created sub_transaction_builder object cardano_sub_tx_builder_ref(sub_transaction_builder); // Now sub_transaction_builder can be safely used elsewhere without worrying about premature deallocationNote
Always ensure that for every call to cardano_sub_tx_builder_ref there is a corresponding call to cardano_sub_tx_builder_unref to prevent memory leaks.
- Parameters:¶
- cardano_sub_tx_builder_t *sub_transaction_builder¶
A pointer to the cardano_sub_tx_builder_t object whose reference count is to be incremented.
-
size_t cardano_sub_tx_builder_refcount(const cardano_sub_tx_builder_t *sub_transaction_builder)¶
Retrieves the current reference count of the cardano_sub_tx_builder_t object.
This function returns the number of active references to an cardano_sub_tx_builder_t object. It’s useful for debugging purposes or managing the lifecycle of the object in complex scenarios.
Usage Example:
// Assuming sub_transaction_builder is a previously created sub_transaction_builder object size_t ref_count = cardano_sub_tx_builder_refcount(sub_transaction_builder); printf("Reference count: %zu\n", ref_count);Warning
This function does not account for transitive references. A transitive reference occurs when an object holds a reference to another object, rather than directly to the cardano_sub_tx_builder_t. As such, the reported count may not fully represent the total number of conceptual references in cases where such transitive relationships exist.
- Parameters:¶
- const cardano_sub_tx_builder_t *sub_transaction_builder¶
A pointer to the cardano_sub_tx_builder_t object whose reference count is queried. The object must not be NULL.
- Returns:¶
The number of active references to the specified cardano_sub_tx_builder_t object. If the object is properly managed (i.e., every cardano_sub_tx_builder_ref call is matched with a cardano_sub_tx_builder_unref call), this count should reach zero right before the object is deallocated.
-
void cardano_sub_tx_builder_set_last_error(cardano_sub_tx_builder_t *sub_transaction_builder, const char *message)¶
Sets the last error message for a given cardano_sub_tx_builder_t object.
Records an error message in the sub_transaction_builder’s last_error buffer, overwriting any existing message. This is useful for storing descriptive error information that can be later retrieved. The message is truncated if it exceeds the buffer’s capacity.
Note
The error message is limited to 1023 characters, including the null terminator, due to the fixed size of the last_error buffer.
- Parameters:¶
- cardano_sub_tx_builder_t *sub_transaction_builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance whose last error message is to be set. If
NULL, the function does nothing.- const char *message¶
[in] A null-terminated string containing the error message. If
NULL, the sub_transaction_builder’s last_error is set to an empty string, indicating no error.
-
const char *cardano_sub_tx_builder_get_last_error(const cardano_sub_tx_builder_t *sub_transaction_builder)¶
Retrieves the last error message recorded for a specific sub_transaction_builder.
This function returns a pointer to the null-terminated string containing the last error message set by cardano_sub_tx_builder_set_last_error for the given sub_transaction_builder. If no error message has been set, or if the last_error buffer was explicitly cleared, an empty string is returned, indicating no error.
Note
The returned string points to internal storage within the object and must not be modified by the caller. The string remains valid until the next call to cardano_sub_tx_builder_set_last_error for the same sub_transaction_builder, or until the sub_transaction_builder is deallocated.
- Parameters:¶
- const cardano_sub_tx_builder_t *sub_transaction_builder¶
[in] A pointer to the cardano_sub_tx_builder_t instance whose last error message is to be retrieved. If the sub_transaction_builder is NULL, the function returns a generic error message indicating the null sub_transaction_builder.
- Returns:¶
A pointer to a null-terminated string containing the last error message for the specified sub_transaction_builder. If the sub_transaction_builder is NULL, “Object is NULL.” is returned to indicate the error.
-
void cardano_sub_tx_builder_add_proposal(cardano_sub_tx_builder_t *builder, cardano_proposal_procedure_t *proposal, cardano_plutus_data_t *redeemer)¶
Adds a complete proposal procedure with an optional proposing redeemer.
The proposal deposit must match the configured governance action deposit. Proposals retain insertion order; a proposal with identical serialized contents is rejected as a duplicate. A non-NULL redeemer requires a parameter change or treasury withdrawal with a policy hash. NULL adds no redeemer, including for proposals with a policy hash. The builder retains references to the proposal and redeemer. Errors are deferred until build.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] The builder. NULL is a no-op.
- cardano_proposal_procedure_t *proposal¶
[in] The proposal procedure. Must not be NULL.
- cardano_plutus_data_t *redeemer¶
[in] The proposing payload, or NULL.
-
void cardano_sub_tx_builder_add_proposal_with_deferred_redeemer(cardano_sub_tx_builder_t *builder, cardano_proposal_procedure_t *proposal, cardano_deferred_redeemer_fn_t callback, void *user_context)¶
Adds a proposal whose proposing payload is produced by a deferred callback.
The same proposal and deposit rules as cardano_sub_tx_builder_add_proposal apply. The callback follows cardano_deferred_redeemer_fn_t. Use cardano_transaction_find_proposal_index on the draft transaction to obtain the proposal’s proposing index. For sub transactions this index is local to that body. The caller must keep user_context valid until build completes.
- Parameters:¶
- cardano_sub_tx_builder_t *builder¶
[inout] The builder. NULL is a no-op.
- cardano_proposal_procedure_t *proposal¶
[in] The proposal procedure with a policy hash. Must not be NULL.
- cardano_deferred_redeemer_fn_t callback¶
[in] The callback producing the payload. Must not be NULL.
- void *user_context¶
[in] An opaque pointer forwarded to the callback. Can be NULL.