cardano-client-lib icon indicating copy to clipboard operation
cardano-client-lib copied to clipboard

Vasil - Update min ada in UTXO

Open satran004 opened this issue 2 years ago • 5 comments

Modify min ada calculation logic due to inline datum and reference script support in Babbage era.

satran004 avatar Jun 07 '22 14:06 satran004

Is this issue is causing errors like this?

Transaction failed: Result{successful=false, response='{"error":"Bad Request","message":"\"transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash \\\"ff1f7d5044589c668f4ea8946a9cd96670a03082a626046f43f467bd\\\")) (StakeRefBase (KeyHashObj (KeyHash \\\"2711eac3b659022ada0b49cd720790c3e44722c5df165a4d4e8df1f9\\\"))),Value 168090 (fromList [(PolicyID {policyID = ScriptHash \\\"acf3057d8848a3c530225b8d276f4a0a3df6e1665449be9ad9693770\\\"},fromList [(54657374436f696e,250000)])]),NoDatum,SNothing),Coin 1172320)]))])\"","status_code":400}', code=400, value=TransactionResult{signedTxn=84a60081825820d90e7f4d58cb4155943b2e9026ce76921e89e39ec344b0a5bbcd8c2fe22f230500018282583900ff1f7d5044589c668f4ea8946a9cd96670a03082a626046f43f467bd2711eac3b659022ada0b49cd720790c3e44722c5df165a4d4e8df1f91a00118bd582583900ff1f7d5044589c668f4ea8946a9cd96670a03082a626046f43f467bd2711eac3b659022ada0b49cd720790c3e44722c5df165a4d4e8df1f9821a0002909aa1581cacf3057d8848a3c530225b8d276f4a0a3df6e1665449be9ad9693770a14854657374436f696e1a0003d090021a0002c6f1031a03c1aa58075820b001d5217d22e06c66cc52034231e99fd2c9ab9fb7b743bc53e93f24ad49d7f909a1581cacf3057d8848a3c530225b8d276f4a0a3df6e1665449be9ad9693770a14854657374436f696e1a0003d090a20082825820ba4b0f03ea2d69bd0550f460a9e23f9d5e4bba525ab73ccea7867eb4199d26a65840958efb650c904c1d23c101ef489fc909193845fe295eb11783712612ee29a78a29bdb9de5b0be94f973be716bfbde44e47d95a768524d10ba9a7c736e41244028258207268067ef8798a3f227caa270b3f6f57bd08b37b4b7d9dfb7d7b85bb56d500c95840fcd0260faecd94fa0605f32bcceb2946738e63025a84f6839598fe88c03de9dda6fc10d9dac1c8d119169b3c0ec94107c430acbe08350734174d30e4cb01930e01818200581c23010b13af9340aaed4c71db563b06b614e5350f20527d29f5f62e65f5a21a000bbfd1a265746f6b656e6a5465737420546f6b656e6673796d626f6c6454544f4b1a000bbfd28264746167316474616732, transactionId='null'}}

I had a working "Hello World" to mint an NFT about a month ago and when I came back to the project today I am seeing the error I posted above. Curious if they are related.

MSchiavi avatar Jul 09 '22 18:07 MSchiavi

Yes, it seems min ada calculation logic needs to be updated. I found some parameter value change in babbage era. Like coins_per_utxo_size value is changed from 34482 to 4310 in epoch 215 (testnet). Though this parameter is fetched from node during min ada calculation, but it seems calculation logic also needs to be updated.

Workaround

For now, if you are using high level MintTransaction api to mint token, you can override ProtocolPrameterSupplier and update protocol parameter value in your code to old value. Add the following code snippet before calling feeCalculationService

 transactionHelperService.getTransactionBuilder().setProtocolParamsSupplier(new ProtocolParamsSupplier() {
            @Override
            public ProtocolParams getProtocolParams() {
                DefaultProtocolParamsSupplier protocolParamsSupplier =  new DefaultProtocolParamsSupplier(backendService.getEpochService());
                ProtocolParams protocolParams = protocolParamsSupplier.getProtocolParams();
                protocolParams.setCoinsPerUtxoWord("34482");
                return protocolParams;
            }
        });

But, if you are using composable functions or low level api, you can adjust the LOVELACE amount to some higer amount in TransactionOutput (instead of 0) https://github.com/bloxbean/cardano-client-examples/blob/c2bfb9f98f7ce4e692cbaea1bc76d3cf1bbf2fbe/src/main/java/com/bloxbean/cardano/client/examples/function/minting/MintTokenNFT.java#L70

satran004 avatar Jul 10 '22 03:07 satran004

In Babbage era, the min ada is calcuated according to following rule

(serSize txout + 160) ∗ coinsPerUTxOByte 

According to https://hydra.iohk.io/build/15339994/download/1/babbage-changes.pdf See on the page 9 getValue txout

satran004 avatar Jul 10 '22 15:07 satran004

Do you plan to include this in a release relatively soon?

MSchiavi avatar Jul 20 '22 07:07 MSchiavi

@MSchiavi A beta build should be out in a week or two.

Alternatively, you can try build from SNAPSHOT repository. You can find the SNAPSHOT build info here https://github.com/bloxbean/cardano-client-lib#for-snapshot-binaries

satran004 avatar Jul 20 '22 10:07 satran004

Fixed in 0.3.0.

satran004 avatar Nov 02 '22 12:11 satran004