Closed tqueri closed 1 week ago
Hi @tqueri ! Unfortunately current coin selection implementation does't know about the change. https://github.com/Emurgo/cardano-serialization-lib/issues/553#issuecomment-1326260015 And unfortunately we don't have plans to fix in a short time. But it is an open source project, feel free to contribute.
Fixed by add_inputs_from_and_change
function in the CSL 12.0.0, please use add_inputs_from_and_change
instead add_inputs_from
. Thanks @twwu123 for your implementation.
I've been working around that issue for a while right now but I think it's a good idea to share the issue. When using add_inputs_from with utxos containing nfts, the balance without the coin selection doesnt take into consideration the amount of lovelace that will be needed for the change output.
So let's say, you have 2 utxos containing each 1 nft. Both of them will have the minimum ada (around 1.2 ada each) so the total in your wallet at this point is 2.4 ada + 2 nfts, if you want to send 1 ada to someone (normally you should have enough) the add_inputs_from function will only add 1 of the 2 utxos considering 1.2 ada is enough to cover the 1 ada output + the tx fees. Which is false, in that instance, all utxos should be included in the transaction and the 2 nfts now merged will only need 1.4 min ada instead of the initial 1.2 each.
I made a simple transaction builder using CSL to show the issue.
From my understanding, all the issue is caused by add_inputs_from since when handling manually the coin selection, its possible to build the transaction with the same utxos. Thanks