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?