cardano-multiplatform-lib
cardano-multiplatform-lib copied to clipboard
Improve unclear usage of set_exunits
Currently, set_exunits exists both in the regular tx builder & in TxRedeemerBuilder from build_for_evaluation
It's not clear to users that you should call the set_exunits in the main builder from the result of TxRedeemerBuilder and so instead, some people have tried building their own system for dummy witnesses to call the set_exunits in the main builder directly even though TxRedeemerBuilder was meant to handle this for them
Probably the API should be changed to make it clearer what the main path is. For example, make that the set_exunits call in the main builder only accepts a type received from a function in TxRedeemerBuilder
I am just making a simple pool delegation TX, it works great with CSL, but I really want to switch to CML.
However I get the error ex_unit_prices
not initialized.
So I tried initializing in the TX builder by adding .ex_unit_prices( )
but I get the following error: expected instance of UnitInterval
Thank you.
// instantiate the tx builder with the Cardano protocol parameters - these may change later on
const txBuilder = await CSLwasm.TransactionBuilder.new(
CSLwasm.TransactionBuilderConfigBuilder.new()
.fee_algo(
CSLwasm.LinearFee.new(CSLwasm.BigNum.from_str('44'),
CSLwasm.BigNum.from_str('155381'))
)
.pool_deposit(CSLwasm.BigNum.from_str('500000000'),)
.key_deposit( CSLwasm.BigNum.from_str('2000000'),)
.coins_per_utxo_word(CSLwasm.BigNum.from_str('34482'))
.max_value_size(5000)
.max_tx_size(16384)
.prefer_pure_change(true)
.ex_unit_prices(
CSLwasm.ExUnitPrices.new(
CSLwasm.BigNum.from_str("1100"), //memory
CSLwasm.BigNum.from_str("297830") //steps
)
)
.build()
);
@bakon11 you get the error because you used the wrong type. The constructor for ExUnitPrices
is of type new(mem_price: UnitInterval, step_price: UnitInterval): ExUnitPrices
. This is because the memory and steps values are fractions, so you need to specify the numerator and the denominator.
It will look something like this
CSLwasm.ExUnitPrices.new(
CSLwasm.UnitInterval.new(
CSLwasm.BigNum.from_str('0'),
CSLwasm.BigNum.from_str('0')
),
CSLwasm.UnitInterval.new(
CSLwasm.BigNum.from_str('0'),
CSLwasm.BigNum.from_str('0')
)
)
Here are the values for mainnet for example using the JOSN notation
CSLwasm.ExUnitPrices.from_json(JSON.stringify({
mem_price: {
denominator: '721',
numerator: '10000000',
},
step_price: {
denominator: '577',
numerator: '10000',
},
})),