Zero Change

No change output transactions

Zero change transaction building is an excellent resource for developers who wish to construct STAS transactions without any change outputs. An instance of this model is when the payment UTXOs for the transactions are prearranged. By incorporating this model in conjunction with fee estimation functions, developers can minimize chained UTXO transactions by determining the exact fee amount requirement ahead of time, allowing them to create the appropriate size UTXO for the fee payment without the need to handle UTXOs afterwards as part of further fee UTXOs. This is especially handy for instances where multiple fee UTXOs are required for multiple transactions at once.

To use the zero change model in the functions it requires an arguement boolean set to true. Here is an example in the stasTransfer function:

const transferHex = await stasTransfer.signed(
    ownerPrivatekey, 
    stasUtxo, 
    destinationAddress, 
    paymentUtxo, 
    paymentPrivateKey,
    undefined|data,
    true
)

We can observe that the final argument in the stasTransfer function is set to "true". This allows for the transfer to be conducted utilizing the zero change model. It's important to note that the second-to-last argument in the function must be set to either "undefined" or, if data is required, added in as demonstrated in the preceding examples regarding data additions.

Utilizing the zero change model also involves a fallback to ensure that no significant excess in satoshis goes unaccounted for in the change output. The parameters for the zero change model can be located in the utility.js file as depicted below:

this.ZEROCHANGETHRESHOLD = 10 // Don't change this setting unless you know what you're doing

In this instance, if the change amount surpasses 10 satoshis, an error will be thrown, and the transaction build will not be completed. The zero change model is intended to be utilized alongside fee estimation functions to yield optimal results with minimal satoshi wastage, and to decrease the handling of excess change UTXOs when they are not required.

Each transaction function in the library has zero change option in the function arguments. By default, this value is set to false when not supplied.

Last updated