When building an output that includes a scriptRef, the SDK helper calculateMinimumUtxoLovelace can return a value that is too low for minimum UTxO requirements. This causes transactions to be rejected due to insufficient lovelace on the output.
Expected Behavior
calculateMinimumUtxoLovelace should return a minimum lovelace amount that satisfies the min-UTxO rule for the produced output, including:
- the 160-byte UTxO entry overhead, and
- correct CBOR sizing behavior for the lovelace field.
Actual Behavior
calculateMinimumUtxoLovelace appears to omit the 160-byte UTxO entry overhead, and the computed CBOR size can vary depending on whether the output’s lovelace is encoded as 0 (1-byte CBOR) versus a typical final amount (≥ 65,536 → 5-byte CBOR). This can lead to under-calculation of the required lovelace.
Reproduction (High-level)
- Construct a transaction output that includes a
scriptRef.
- Use
calculateMinimumUtxoLovelace to determine the lovelace amount.
- Submit the transaction.
- Observe rejection due to insufficient lovelace in the output.
Workaround
Compute the output CBOR size via the SDK helper using coinsPerUtxoByte: 1n to obtain a raw byte count, then apply the missing overhead and actual coinsPerUtxoByte:
- Fetch
coinsPerUtxoByte from protocol parameters
- Use a 1 ADA placeholder (instead of zero) to ensure the lovelace field uses the same 5-byte CBOR encoding as the final value
- Compute: minLovelace = (cborSize + 160) * coinsPerUtxoByte
Link to workaround: MynthAI/mint-chocolate-chip#32
When building an output that includes a
scriptRef, the SDK helpercalculateMinimumUtxoLovelacecan return a value that is too low for minimum UTxO requirements. This causes transactions to be rejected due to insufficient lovelace on the output.Expected Behavior
calculateMinimumUtxoLovelaceshould return a minimum lovelace amount that satisfies the min-UTxO rule for the produced output, including:Actual Behavior
calculateMinimumUtxoLovelaceappears to omit the 160-byte UTxO entry overhead, and the computed CBOR size can vary depending on whether the output’s lovelace is encoded as 0 (1-byte CBOR) versus a typical final amount (≥ 65,536 → 5-byte CBOR). This can lead to under-calculation of the required lovelace.Reproduction (High-level)
scriptRef.calculateMinimumUtxoLovelaceto determine the lovelace amount.Workaround
Compute the output CBOR size via the SDK helper using
coinsPerUtxoByte: 1nto obtain a raw byte count, then apply the missing overhead and actualcoinsPerUtxoByte:coinsPerUtxoBytefrom protocol parametersLink to workaround: MynthAI/mint-chocolate-chip#32