4

Is there any prebuild method in Cardano Serialization Lib that allows to select some UTXOs that cover the balance needed for a transaction?

Or should i make a script that querys all the utxo in that addres and selects the first ones that covers this given amount?

1 Answer 1

3

You are speaking about what we call Coin Selection Algorithms and they are described in CIP2.

There are several implementations floating around on Github, such as BerryPool implementation of the Random-Improve coin selection algorithm or what Yoroi does.

5
  • Yes i have seen Berrys implementation, but it semed a little bit too complex, and the CIP2 apears to be in haskell right? I did one script that only querys one by one until it gets the minimun and then the extra is sended back to the owner, i dont know if this is enought for my dapp or if should I use Berry implementation. Commented Nov 13, 2021 at 3:25
  • 1
    No, the CIP describes the algorithm, these are language agnostic. Commented Nov 13, 2021 at 19:50
  • +1 for the links to the coin selection CIP and the implementations!
    – LACE pool
    Commented Jan 15, 2022 at 13:43
  • The cardano-wallet's implementation in Haskell for coin selection can be found here: github.com/input-output-hk/cardano-wallet/blob/…
    – LACE pool
    Commented Jan 15, 2022 at 13:52
  • @MarekMahut-StakeNuts CIP20 states "Problems relating to network fees, and how to adjust coin selections to pay for such fees, are outside the scope of this article." Any ideas how to solve that?
    – wutzebaer
    Commented Nov 2, 2022 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.