Anastasia-Labs / lucid-evolution

https://anastasia-labs.github.io/lucid-evolution/
47 stars 20 forks source link

TxBuilderError when sending all the funds #368

Closed stanvladut closed 2 weeks ago

stanvladut commented 1 month ago

Hi Lucid Evolution team, I'm contacting you on behalf of the VESPR Wallet team. We've recently migrated to using Lucid Evolution for transaction building and we are currently facing a new scenario in our wallet. When a user tries to send all his ADA to another address, or if there's not enough ADA left in the wallet for an UTxO to be created, we receive the following error; { Complete: Your wallet does not have enough funds to cover required minimum ADA for change output: { "lovelace": "4032" } Or it contains UTxOs with reference scripts; which are excluded from coin selection. }

Previously, what would happen is that, if the amount left was not enough to return an UTxO, that amount would be added to the fee.

Is there an option like that for Lucid Evolution to do this automatically when completing the transaction?

stanvladut commented 1 month ago

@Julietnacy Thanks for your response!

Is there a way to do it manually? (to calculate the fee needed and construct the transaction with it)

solidsnakedev commented 1 month ago

ahh I see you're looking to drain the wallet, I can add an option for that. give me some time and I'll put together a PR for it. are you guys facing another issue in wallet VESPR?

stanvladut commented 1 month ago

Thanks a lot @solidsnakedev! Really appreciate it.

No issues at all. The transition was smooth and the integration is already in production. It works smooth so far 👌

AlexDochioiu commented 1 month ago

ahh I see you're looking to drain the wallet, I can add an option for that. give me some time and I'll put together a PR for it. are you guys facing another issue in wallet VESPR?

Hi @solidsnakedev and thank you for this! It may not necessarily be only about draining the wallet. The user may only send all spendabla ada (but not the NFTs/Tokens). I believe the ideal approach is to have a configuration where we can select one of the options when the refund ada is not enough to be put in a return utxo:

  1. Throw error (current behaviour)
  2. Attach the additional ada to the first destination specified by user (basically send more to the user)
  3. Burn the additional ADA in an increased fee (old behaviour of Lucid library)

Sometimes (3) may be preferable because the user may make a payment for a service/product that checks automatically for the exact requested amount (in which case option 2 would be problematic).


P.s. Having an option to get the required fee for a transaction before calling complete would have allowed us to have a work-around for this, assuming the utxo selection is the same to not change the required fee.

solidsnakedev commented 1 month ago

@stanvladut @AlexDochioiu

There is setMinFee when building the transaction. e.g., This will force the transaction to set the fee to a minimum of 10 ADA

newTx().setMinFee(10_000_000)...

let me know if this works for your use case

https://github.com/Anastasia-Labs/lucid-evolution/blob/ac054ba1053b68d2e40d638b7bec54bf462af604/packages/lucid/src/tx-builder/TxBuilder.ts#L188

AlexDochioiu commented 1 month ago

@solidsnakedev I am aware, but it's not useful. Unless I know which utxos have been selected, I cannot know by how much I need to increase the fee to burn the extra ada that would otherwise be returned in an utxo.

And I guess there's no utxo selection happening before you call complete, which we cannot do because it would throw an error.

AlexDochioiu commented 2 weeks ago

Hi @solidsnakedev just following up on this.

solidsnakedev commented 2 weeks ago

We pushed an update you can do .complete({ includeLeftoverLovelaceAsFee: true }); , please let us know if it works for you

AlexDochioiu commented 1 week ago

@solidsnakedev Seems to work perfect 🙏🏻 . Thank you a lot for the help!