2

I created a bidding war in Plutus Playground between 5 wallets.

Wallet 2 bids first and then is outbid by Wallet 3 and got refunded as usual. Later on when Wallet 2 went to bid again with a higher amount only the first unspent Tx was used as an input.

However later on Wallet 3 was outbid by Wallet 4 which was outbid again a few slots after. Wallet 4 then placed another bid, but this time when Wallet 4 placed its bid, it used 2 inputs (the previous change amount plus the refunded amount) to cover the bid.

In both scenarios, both wallets had enough in their first unspent Tx after their initial bid to cover the next bid they put in. This would make me think that the wallets don't necessarily spent their lowest UTxO first since only one wallet used their refunded bid in addition to their first unspent Tx.

Why is this?

Images below show what happened.

Wallet 2 gets outbid and refunded

Wallet 4 makes initial bid

Wallet 4 gets outbid and refunded

Wallet 2 makes another bid with only the first UTxO

Wallet 4 makes a bid using both UTxOs

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

1 Answer 1

1

How coins are selected isn't defined in the playground. Probably the easiest algorithm is largest utxo first (since it's a playground you don't need to worry about fragmentation). If that's the case then as long as the initial change is large enough for a bid the tx wouldn't need to consume both inputs.

In practice on chain the user (or more likely the user's wallet) is responsible for choosing the utxo that is the input for the transaction. Cardano wallet for example uses a random coin selection algorithm. Other wallets use a largest utxo algorithm and others may have something entirely different. From the perspective of plutus though the tx outputs into the contract is all it cares about though.

2
  • On chain wouldn't it be best to go with smallest UTxO first in order to minimize data by having fewer "change" UTxOs? Or am I thinking of it wrong?
    – Taco_Man
    Jan 17, 2022 at 1:21
  • Depending on fragmentation of wallet and how big of output you're sending you could end up in a state where you can't make a successful transaction anymore because tx size is exhausted combining all the small utxos. Jan 17, 2022 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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