1

As you perform transactions on the blockchain, you generate unspent transaction outputs of various sizes. When you create a new transaction, how are the UTXOs prioritised, i.e. which ones will be used first? Is it possible to specify which of your UTXOs you want to use? If I have one large UTXO and one small UTXO and I want to make a transaction with:

large UTXO > transaction value > small UTXO

Will the large UTXO automatically be used, or may I end up using both, and therefore leaving only a single UTXO as a result?

1
  • Welcome to Cardano SE! As a new user be sure to take the Tour.
    – gRebel
    Jan 22, 2022 at 13:55

2 Answers 2

3

You can find a great quick read on this topic here: https://cips.cardano.org/cips/cip2/#algorithms (or a big long one here https://iohk.io/en/blog/posts/2018/07/03/self-organisation-in-coin-selection/)

Basically it's the job of the wallet (or whoever composes the transaction) to implement such a selection strategy.

Two of those strategies proposed are "Largest-First" (similar to what you mentioned) and another is "Random-Improve".

If you're interested, here's how the cardano-serialization-lib implemented the algorithms in practice in rust: https://github.com/Emurgo/cardano-serialization-lib/blob/6a8c67a0fdb2ac6d72132d9693b87a6734f3fed5/rust/src/tx_builder.rs#L329

While Cardano Wallet gives priority to Random-Improve, there might be cases where you need to use Largest First, e.g. when creating multi-asset transactions with this lib (https://github.com/Emurgo/cardano-serialization-lib/blob/6a8c67a0fdb2ac6d72132d9693b87a6734f3fed5/rust/src/tx_builder.rs#L370).

When you create the transaction yourself, eg through the Cardano CLI, you can also freely select which utxo to spend.

0

I believe it's the same as with paying with cash: you have in principle the option of paying with the largest bill you have, so you make sure the amount is covered and you don't have to do a lot of maths, of getting rid of all the small coins you need to spend to reach the desired amount so you don't have to carry them in your pocket, or even of paying with the bill that is closest to the amount you have to pay to make it easy for the one giving you the change. As far as I know, wallets usually implement heuristics combining (at least the) first two options, so not just one strategy. I don't think it makes that much of a difference though, in the end money is money.

Your Answer

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

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