1

When creating a new transaction, how does the Bitcoin Core wallet (or any other wallet) handle/use the outputs (UTXO's)?

e.g. when 2 outputs have to be used, will Bitcoin spend the highest address (most BTC) first and then the second highest or are the UTXO's used in another way?

Which output will be used for the change (if there is any)?

Murch
  • 75,206
  • 34
  • 186
  • 622
Bart DV
  • 149
  • 5

1 Answers1

3

Bitcoin Core uses a Branch and Bound algorithm to search for an input set that exactly matches the send request. To that end, it will deterministically search the combination space of all of its available utxos and pick the set that is the most efficient if there are multiple solutions. The Branch and Bound algorithm is briefly described in the sourcecode and more comprehensively in my master's thesis.

If no matching solution is found with the Branch and Bound algorithm, Bitcoin Core will fall back to its previous strategy. This entails sorting all unspents descendingly by their value and iteratively picking a subset by randomly including or skipping list elements.

Murch
  • 75,206
  • 34
  • 186
  • 622