<blockquote>
<p>Is there a way to calculate how much ADA of a UTxO isn't locked with any assets?</p>
</blockquote>
<p>I am not sure I follow the question. All the ADA inside a UTxO is locked with all the tokens inside the UTxO, they are all in the same boat, you cannot consume only part of a UTxO, you either spend it as a whole (and return some change) or you don't spend it at all.</p>
<p>Maybe what you meant is &quot;how to calculate how much ADA I can spend from a UTxO without raising a transaction error&quot;, in which case we come to your next question, which effectively the same.</p>
<blockquote>
<p>how do you calculate the minimum output amount that are required to avoid OutputTooSmall error?</p>
</blockquote>
<p>You can see a complete response in the <a href="https://docs.cardano.org/native-tokens/minimum-ada-value-requirement" rel="nofollow noreferrer">Cardano documentation</a>. In summary</p>
<blockquote>
<p>minUTxoVal = (160 + sizeInBytes (TxOut)) * coinsPerUTxOByte</p>
</blockquote>
<p>Some Cardano tools offer easy ways to calculate this value. In lucid, you can use the <a href="https://deno.land/x/lucid@0.9.4/mod.ts?s=Core.min_ada_required" rel="nofollow noreferrer"><code>min_ada_required</code> function</a>. In PyCardano, you can use the <a href="https://pycardano.readthedocs.io/en/latest/api/pycardano.utils.html#pycardano.utils.min_lovelace" rel="nofollow noreferrer"><code>min_lovelace</code> function</a>.</p>

CC BY-SA 4.0
2023-02-28T18:45:58.730Z
I think I got your point, but I am still unsure of one thing. Let's say I picked an UTXO with random improve method that contains 2 ADA. Then I added 20 NFT as output. As you might guess, adding 20 NFT will set the minUtxo way higher than 2 ADA as the tx size will be big.

But I can only get the sizeInBytes(TxOut) once I build the transaction. And if the transaction is already built, what's the point of retrieving minUTXOValue then? What should be the appropriate approach here?
Alexis
CC BY-SA 4.0
2023-02-28T22:37:13.623Z
"And if the transaction is already built, what's the point of retrieving minUTXOValue then?" In your case the point is to not have it raise an error. When we calculate what fees we need to pay, we do the same thing in the background, we first the transaction with an arbitrary amount for the fees and then we calculate it and change it. You would do the same thing, you first create the transaction and then calculate the min utxo value and change it in the transaction again, seems redundant, but in your case is what you need to do.
Mateus
CC BY-SA 4.0
2023-02-28T22:38:22.240Z
Unless somehow you already know how the new output UTxO will look like (what values it will contain), in which case you don't need to build the full transaction, you can simply use the `sizeInBytes(TxOut)` function and give it as an argument the output you expect
Mateus
CC BY-SA 4.0
2023-02-28T13:01:34.037Z
2023-02-28T13:01:34.037Z
Mateus
<p>I think what you need to do is figure out what mph + token names you have in the utxos, and then craft an output that consolidates the separate UTXOs (with their own minting policy + token name) into one output.   I would recommend you checkout Helios which has coin selection algorithms that may be able to help with that.  You may also need to augment your own offchain code by examining the following code snippet from the helios.js library to help create this specific output.</p>
<p><a href="https://github.com/Hyperion-BT/helios/blob/main/helios.js#L35660" rel="nofollow noreferrer">https://github.com/Hyperion-BT/helios/blob/main/helios.js#L35660</a></p>
<p><a href="https://i.sstatic.net/JE2lR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JE2lR.png" alt="enter image description here" /></a></p>
<p>Here is a related problem where I needed to find out the number of a specific tokens in the input UTXOs.  This is because when I minted more of them, I wanted the output to be both the amount of tokens in the input + the new minted ones.</p>
<p><a href="https://i.sstatic.net/CR9Wr.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CR9Wr.png" alt="enter image description here" /></a></p>
<p>Source code: <a href="https://github.com/lley154/littercoin/blob/preprod-6.33/app/pages/index.tsx" rel="nofollow noreferrer">https://github.com/lley154/littercoin/blob/preprod-6.33/app/pages/index.tsx</a></p>

CC BY-SA 4.0
2023-02-26T11:59:13.193Z
mph? Can you elaborate a little bit? I tried to google the term but nothing came up
Alexis
CC BY-SA 4.0
2023-02-26T21:46:04.113Z
sorry, I should have been more clear.   mph = minting policy hash.
lley154
CC BY-SA 4.0
2023-02-26T21:58:37.130Z
If you want to see other helios examples, you can checkout my repo here: https://github.com/lley154/helios-examples  and book here: https://github.com/lley154/helios-examples/blob/main/docs/Cardano%20Smart%20Contracts%20with%20Helios.pdf
lley154
CC BY-SA 4.0
2023-02-25T00:51:22.333Z
2023-02-26T21:55:03.633Z
2023-02-26T21:55:03.633Z
lley154
<p>I’m trying to build a multi-sig transaction to mint an NFT. The transaction will take some input from users wallet via coin selection and add an additional NFT as output.</p>
<p>The problem begans, when the wallet have some ada but all of them are locked with some tokens. We all know that you can’t just send a token alone; there must be some ada attached to it.</p>
<p>Consider this UTXO, for example.</p>
<p>Hex:-</p>
<pre><code>828258205abda375b18b2097b2011f22dbf2d14643ce5fd7478ba4df6b21c2b91d9fd1a70182583901c13c23461bf40f5e07e1a0a84759e8e6b75dc0c6f2364bfa52f0b45fe7230182c948c67dc319960f10910f8489818f6f85163f0deb83e6fc821a003be9eca5581c0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1a144505245531a000153d8581c5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3eaa5504e6f7a6f6d69433152616e6b3331323801504e6f7a6f6d69433152616e6b3432383601504e6f7a6f6d69433152616e6b3533343201504e6f7a6f6d69433152616e6b3534373301504e6f7a6f6d69433152616e6b3534393601581c6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311b1544e6f7a6f6d69436e66742050617373202330323401544e6f7a6f6d69436e66742050617373202330343301544e6f7a6f6d69436e66742050617373202330343601544e6f7a6f6d69436e66742050617373202330353801544e6f7a6f6d69436e66742050617373202330363001544e6f7a6f6d69436e66742050617373202330383401544e6f7a6f6d69436e66742050617373202330383601544e6f7a6f6d69436e66742050617373202330383801544e6f7a6f6d69436e66742050617373202330393201544e6f7a6f6d69436e66742050617373202330393501544e6f7a6f6d69436e66742050617373202330393701544e6f7a6f6d69436e66742050617373202331303201544e6f7a6f6d69436e66742050617373202331323001544e6f7a6f6d69436e66742050617373202331323401544e6f7a6f6d69436e66742050617373202331323901544e6f7a6f6d69436e66742050617373202331343301544e6f7a6f6d69436e66742050617373202331343801581c8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cba153464643466f756e64657273506173733030373301581cf0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9aa1496a696d742e6b69726b01
</code></pre>
<p>CSL JSON:-</p>
<pre><code>{
  &quot;address&quot;: &quot;addr1q8qncg6xr06q7hs8uxs2s36earntwhwqcmervjl62tctghl8yvqc9j2gce7uxxvkpugfzruy3xqc7mu9zclsm6urum7qlau4pp&quot;,
  &quot;amount&quot;: {
    &quot;coin&quot;: &quot;3926508&quot;,
    &quot;multiasset&quot;: {
      &quot;0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1&quot;: {
        &quot;50524553&quot;: &quot;87000&quot;
      },
      &quot;5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3ea&quot;: {
        &quot;4e6f7a6f6d69433152616e6b33313238&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69433152616e6b34323836&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69433152616e6b35333432&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69433152616e6b35343733&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69433152616e6b35343936&quot;: &quot;1&quot;
      },
      &quot;6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311&quot;: {
        &quot;4e6f7a6f6d69436e667420506173732023303234&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303433&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303436&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303538&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303630&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303834&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303836&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303838&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303932&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303935&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023303937&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313032&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313230&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313234&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313239&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313433&quot;: &quot;1&quot;,
        &quot;4e6f7a6f6d69436e667420506173732023313438&quot;: &quot;1&quot;
      },
      &quot;8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cb&quot;: {
        &quot;464643466f756e646572735061737330303733&quot;: &quot;1&quot;
      },
      &quot;f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a&quot;: {
        &quot;6a696d742e6b69726b&quot;: &quot;1&quot;
      }
    }
  },
  &quot;plutus_data&quot;: null,
  &quot;script_ref&quot;: null
}
</code></pre>
<p>This wallet has 3.92 ADA in it, more than enough to overcome the min utxo rules.</p>
<p>But all of these ADA are locked with the tokens of that utxo. Which means if we add another token, we also have to add some additional lovelace from another UTXO; otherwise, this will throw a BabbageOutputTooSmallUTxO error.</p>
<pre><code>&quot;transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Mainnet (KeyHashObj (KeyHash \&quot;c13c23461bf40f5e07e1a0a84759e8e6b75dc0c6f2364bfa52f0b45f\&quot;)) (StakeRefBase (KeyHashObj (KeyHash \&quot;e7230182c948c67dc319960f10910f8489818f6f85163f0deb83e6fc\&quot;))),Value 3671749 (fromList [(PolicyID {policyID = ScriptHash \&quot;0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1\&quot;},fromList [(50524553,87000)]),(PolicyID {policyID = ScriptHash \&quot;5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3ea\&quot;},fromList [(4e6f7a6f6d69433152616e6b33313238,1),(4e6f7a6f6d69433152616e6b34323836,1),(4e6f7a6f6d69433152616e6b35333432,1),(4e6f7a6f6d69433152616e6b35343733,1),(4e6f7a6f6d69433152616e6b35343936,1)]),(PolicyID {policyID = ScriptHash \&quot;6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311\&quot;},fromList [(4e6f7a6f6d69436e667420506173732023303234,1),(4e6f7a6f6d69436e667420506173732023303433,1),(4e6f7a6f6d69436e667420506173732023303436,1),(4e6f7a6f6d69436e667420506173732023303538,1),(4e6f7a6f6d69436e667420506173732023303630,1),(4e6f7a6f6d69436e667420506173732023303834,1),(4e6f7a6f6d69436e667420506173732023303836,1),(4e6f7a6f6d69436e667420506173732023303838,1),(4e6f7a6f6d69436e667420506173732023303932,1),(4e6f7a6f6d69436e667420506173732023303935,1),(4e6f7a6f6d69436e667420506173732023303937,1),(4e6f7a6f6d69436e667420506173732023313032,1),(4e6f7a6f6d69436e667420506173732023313230,1),(4e6f7a6f6d69436e667420506173732023313234,1),(4e6f7a6f6d69436e667420506173732023313239,1),(4e6f7a6f6d69436e667420506173732023313433,1),(4e6f7a6f6d69436e667420506173732023313438,1)]),(PolicyID {policyID = ScriptHash \&quot;8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cb\&quot;},fromList [(464643466f756e646572735061737330303733,1)]),(PolicyID {policyID = ScriptHash \&quot;9c241d1a9269da78a85a0e1269ecd5f56477641df28b2ce5ccd65188\&quot;},fromList [(4e6f7a6f6d69436e667420506173732023303234,1)]),(PolicyID {policyID = ScriptHash \&quot;f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a\&quot;},fromList [(6a696d742e6b69726b,1)])]),NoDatum,SNothing),Coin 4055710)]))])
</code></pre>
<p>I'm looking for a way to prevent this kind of coin selection. Is there a way to calculate how much ADA of a UTXo isn't locked with any assets?</p>
<p>Also, how do you calculate the minimum output amount that are required to avoid OutputTooSmall error?</p>

<nft><cardano-serialization-lib><native-assets><utxo>
Cardano Multi-Sig Mint BabbageOutputTooSmallUTxO
# Cardano Multi-Sig Mint BabbageOutputTooSmallUTxO

(Asked by: username_0 on 2023-02-18)

I’m trying to build a multi-sig transaction to mint an NFT. The transaction will take some input from users wallet via coin selection and add an additional NFT as output.
The problem begans, when the wallet have some ada but all of them are locked with some tokens. We all know that you can’t just send a token alone; there must be some ada attached to it.
Consider this UTXO, for example.
Hex:-
828258205abda375b18b2097b2011f22dbf2d14643ce5fd7478ba4df6b21c2b91d9fd1a70182583901c13c23461bf40f5e07e1a0a84759e8e6b75dc0c6f2364bfa52f0b45fe7230182c948c67dc319960f10910f8489818f6f85163f0deb83e6fc821a003be9eca5581c0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1a144505245531a000153d8581c5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3eaa5504e6f7a6f6d69433152616e6b3331323801504e6f7a6f6d69433152616e6b3432383601504e6f7a6f6d69433152616e6b3533343201504e6f7a6f6d69433152616e6b3534373301504e6f7a6f6d69433152616e6b3534393601581c6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311b1544e6f7a6f6d69436e66742050617373202330323401544e6f7a6f6d69436e66742050617373202330343301544e6f7a6f6d69436e66742050617373202330343601544e6f7a6f6d69436e66742050617373202330353801544e6f7a6f6d69436e66742050617373202330363001544e6f7a6f6d69436e66742050617373202330383401544e6f7a6f6d69436e66742050617373202330383601544e6f7a6f6d69436e66742050617373202330383801544e6f7a6f6d69436e66742050617373202330393201544e6f7a6f6d69436e66742050617373202330393501544e6f7a6f6d69436e66742050617373202330393701544e6f7a6f6d69436e66742050617373202331303201544e6f7a6f6d69436e66742050617373202331323001544e6f7a6f6d69436e66742050617373202331323401544e6f7a6f6d69436e66742050617373202331323901544e6f7a6f6d69436e66742050617373202331343301544e6f7a6f6d69436e66742050617373202331343801581c8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cba153464643466f756e64657273506173733030373301581cf0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9aa1496a696d742e6b69726b01

CSL JSON:-
{
  "address": "addr1q8qncg6xr06q7hs8uxs2s36earntwhwqcmervjl62tctghl8yvqc9j2gce7uxxvkpugfzruy3xqc7mu9zclsm6urum7qlau4pp",
  "amount": {
    "coin": "3926508",
    "multiasset": {
      "0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1": {
        "50524553": "87000"
      },
      "5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3ea": {
        "4e6f7a6f6d69433152616e6b33313238": "1",
        "4e6f7a6f6d69433152616e6b34323836": "1",
        "4e6f7a6f6d69433152616e6b35333432": "1",
        "4e6f7a6f6d69433152616e6b35343733": "1",
        "4e6f7a6f6d69433152616e6b35343936": "1"
      },
      "6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311": {
        "4e6f7a6f6d69436e667420506173732023303234": "1",
        "4e6f7a6f6d69436e667420506173732023303433": "1",
        "4e6f7a6f6d69436e667420506173732023303436": "1",
        "4e6f7a6f6d69436e667420506173732023303538": "1",
        "4e6f7a6f6d69436e667420506173732023303630": "1",
        "4e6f7a6f6d69436e667420506173732023303834": "1",
        "4e6f7a6f6d69436e667420506173732023303836": "1",
        "4e6f7a6f6d69436e667420506173732023303838": "1",
        "4e6f7a6f6d69436e667420506173732023303932": "1",
        "4e6f7a6f6d69436e667420506173732023303935": "1",
        "4e6f7a6f6d69436e667420506173732023303937": "1",
        "4e6f7a6f6d69436e667420506173732023313032": "1",
        "4e6f7a6f6d69436e667420506173732023313230": "1",
        "4e6f7a6f6d69436e667420506173732023313234": "1",
        "4e6f7a6f6d69436e667420506173732023313239": "1",
        "4e6f7a6f6d69436e667420506173732023313433": "1",
        "4e6f7a6f6d69436e667420506173732023313438": "1"
      },
      "8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cb": {
        "464643466f756e646572735061737330303733": "1"
      },
      "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a": {
        "6a696d742e6b69726b": "1"
      }
    }
  },
  "plutus_data": null,
  "script_ref": null
}

This wallet has 3.92 ADA in it, more than enough to overcome the min utxo rules.
But all of these ADA are locked with the tokens of that utxo. Which means if we add another token, we also have to add some additional lovelace from another UTXO; otherwise, this will throw a BabbageOutputTooSmallUTxO error.
"transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Mainnet (KeyHashObj (KeyHash \"c13c23461bf40f5e07e1a0a84759e8e6b75dc0c6f2364bfa52f0b45f\")) (StakeRefBase (KeyHashObj (KeyHash \"e7230182c948c67dc319960f10910f8489818f6f85163f0deb83e6fc\"))),Value 3671749 (fromList [(PolicyID {policyID = ScriptHash \"0445383201b56c4acedf544afa57cb88bfbc616c35b57e5b7dbad2d1\"},fromList [(50524553,87000)]),(PolicyID {policyID = ScriptHash \"5f4fa7ef47236a2b2a6b9455e7685b6d5993c925680d507fce3cd3ea\"},fromList [(4e6f7a6f6d69433152616e6b33313238,1),(4e6f7a6f6d69433152616e6b34323836,1),(4e6f7a6f6d69433152616e6b35333432,1),(4e6f7a6f6d69433152616e6b35343733,1),(4e6f7a6f6d69433152616e6b35343936,1)]),(PolicyID {policyID = ScriptHash \"6eae3a98e41c11c85a1620357a1eeae0a8df772287d6cf71313ad311\"},fromList [(4e6f7a6f6d69436e667420506173732023303234,1),(4e6f7a6f6d69436e667420506173732023303433,1),(4e6f7a6f6d69436e667420506173732023303436,1),(4e6f7a6f6d69436e667420506173732023303538,1),(4e6f7a6f6d69436e667420506173732023303630,1),(4e6f7a6f6d69436e667420506173732023303834,1),(4e6f7a6f6d69436e667420506173732023303836,1),(4e6f7a6f6d69436e667420506173732023303838,1),(4e6f7a6f6d69436e667420506173732023303932,1),(4e6f7a6f6d69436e667420506173732023303935,1),(4e6f7a6f6d69436e667420506173732023303937,1),(4e6f7a6f6d69436e667420506173732023313032,1),(4e6f7a6f6d69436e667420506173732023313230,1),(4e6f7a6f6d69436e667420506173732023313234,1),(4e6f7a6f6d69436e667420506173732023313239,1),(4e6f7a6f6d69436e667420506173732023313433,1),(4e6f7a6f6d69436e667420506173732023313438,1)]),(PolicyID {policyID = ScriptHash \"8b6e715851dead233ae5c4f8ed1f192e78461d2f64d0f4bb35b823cb\"},fromList [(464643466f756e646572735061737330303733,1)]),(PolicyID {policyID = ScriptHash \"9c241d1a9269da78a85a0e1269ecd5f56477641df28b2ce5ccd65188\"},fromList [(4e6f7a6f6d69436e667420506173732023303234,1)]),(PolicyID {policyID = ScriptHash \"f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a\"},fromList [(6a696d742e6b69726b,1)])]),NoDatum,SNothing),Coin 4055710)]))])

I'm looking for a way to prevent this kind of coin selection. Is there a way to calculate how much ADA of a UTXo isn't locked with any assets?
Also, how do you calculate the minimum output amount that are required to avoid OutputTooSmall error?

**Tags:** nft, cardano-serialization-lib, native-assets, utxo

---

## 2 answers

### Answer by username_1 on 2023-02-28. Score: 0 | Accepted answer

> Is there a way to calculate how much ADA of a UTxO isn't locked with any assets?

I am not sure I follow the question. All the ADA inside a UTxO is locked with all the tokens inside the UTxO, they are all in the same boat, you cannot consume only part of a UTxO, you either spend it as a whole (and return some change) or you don't spend it at all.

Maybe what you meant is "how to calculate how much ADA I can spend from a UTxO without raising a transaction error", in which case we come to your next question, which effectively the same.

> how do you calculate the minimum output amount that are required to avoid OutputTooSmall error?

You can see a complete response in the [Cardano documentation](https://docs.cardano.org/native-tokens/minimum-ada-value-requirement). In summary

> minUTxoVal = (160 + sizeInBytes (TxOut)) \* coinsPerUTxOByte

Some Cardano tools offer easy ways to calculate this value. In lucid, you can use the [`min_ada_required` function](https://deno.land/x/lucid@0.9.4/mod.ts?s=Core.min_ada_required). In PyCardano, you can use the [`min_lovelace` function](https://pycardano.readthedocs.io/en/latest/api/pycardano.utils.html#pycardano.utils.min_lovelace).

> **Comments:**
> **username_0**: I think I got your point, but I am still unsure of one thing. Let's say I picked an UTXO with random improve method that contains 2 ADA. Then I added 20 NFT as output. As you might guess, adding 20 NFT will set the minUtxo way higher than 2 ADA as the tx size will be big.  But I can only get the sizeInBytes(TxOut) once I build the transaction. And if the transaction is already built, what's the point of retrieving minUTXOValue then? What should be the appropriate approach here?  
> **username_1**: "And if the transaction is already built, what's the point of retrieving minUTXOValue then?" In your case the point is to not have it raise an error. When we calculate what fees we need to pay, we do the same thing in the background, we first the transaction with an arbitrary amount for the fees and then we calculate it and change it. You would do the same thing, you first create the transaction and then calculate the min utxo value and change it in the transaction again, seems redundant, but in your case is what you need to do.  
> **username_1**: Unless somehow you already know how the new output UTxO will look like (what values it will contain), in which case you don't need to build the full transaction, you can simply use the `sizeInBytes(TxOut)` function and give it as an argument the output you expect  

---

### Answer by username_2 on 2023-02-25. Score: 0

I think what you need to do is figure out what mph + token names you have in the utxos, and then craft an output that consolidates the separate UTXOs (with their own minting policy + token name) into one output. I would recommend you checkout Helios which has coin selection algorithms that may be able to help with that. You may also need to augment your own offchain code by examining the following code snippet from the helios.js library to help create this specific output.

<https://github.com/Hyperion-BT/helios/blob/main/helios.js#L35660>

[![enter image description here](https://i.sstatic.net/JE2lR.png)](https://i.sstatic.net/JE2lR.png)

Here is a related problem where I needed to find out the number of a specific tokens in the input UTXOs. This is because when I minted more of them, I wanted the output to be both the amount of tokens in the input + the new minted ones.

[![enter image description here](https://i.sstatic.net/CR9Wr.png)](https://i.sstatic.net/CR9Wr.png)

Source code: <https://github.com/lley154/littercoin/blob/preprod-6.33/app/pages/index.tsx>

> **Comments:**
> **username_0**: mph? Can you elaborate a little bit? I tried to google the term but nothing came up  
> **username_2**: sorry, I should have been more clear.   mph = minting policy hash.  
> **username_2**: If you want to see other helios examples, you can checkout my repo here: https://github.com/lley154/helios-examples  and book here: https://github.com/lley154/helios-examples/blob/main/docs/Cardano%20Smart%20Contracts%20with%20Helios.pdf  

---

