Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically adjust fee when spending all UTxO assets? #113

Open
defiyass26 opened this issue Nov 1, 2022 · 3 comments
Open

Automatically adjust fee when spending all UTxO assets? #113

defiyass26 opened this issue Nov 1, 2022 · 3 comments

Comments

@defiyass26
Copy link

defiyass26 commented Nov 1, 2022

Hey Ales, sorry to add to the list..I just thought there might be a simple solution to a problem I was encountering...

Description of the issue:

  • My wallet has 1 specific UTxO I want to use in a tx
  • I want to send the entire contents of that UTxO to another address.
  • So I add the UTxO to the inputs and outputs via payToAddress and collectFrom
  • When completing the transaction however, an error is thrown Insufficient inputs.
// Fetch the specific utxo I want to consume entirely (at index 0)
const specificUtxo = await wallet.getUtxos()[0];

// Create tx
const tx = await lucid.newTx()
  .payToAddress(receiver, specificUtxo.assets)
  .collectFrom([specificUtxo])
  .complete({ coinSelection: false })
  
// Console: Insufficient input

Basically, I'm looking for an easy way to "Spend Everything" from a UTxO - but the fee isn't being adjusted. Any ideas on how to fix this easily?

@alessandrokonrad
Copy link
Contributor

I think we need another flag for this. Lucid can't really tell if you ran out of funds or your intention really is to spend everything. Also if you have like 10 outputs, the question is which output should the fees be subtracted from.

@eliasearlym
Copy link

eliasearlym commented Nov 1, 2022

I think we need another flag for this.

+1 for this. This would be a great quality of life feature. I've been digging Lucid and things like this will just make it more powerful and dev-friendly.

Also if you have like 10 outputs, the question is which output should the fees be subtracted from.

Perhaps you could add a feeFrom or payFeeFrom method which accepted a tx hash. Otherwise, another selection algo would be needed to choose the output at random. I'm not sure how you want to implement the flag...but the feeFrom method might look something like this?

const tx = await lucid.newTx()
  .payToAddress(receiver, specificUtxo.assets)
  .collectFrom([specificUtxo])
  .feeFrom(specificUtxo.txHash)
  .complete({ coinSelection: false })

@nejcr
Copy link

nejcr commented Feb 5, 2023

@alessandrokonrad Is there by any chance workaround around this?
@eliasearlym Have you found something that works for your case, the fee from is exatcly something that I am looking for.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants