<blockquote>
  <p>By default, UTXOs are picked randomly. </p>
</blockquote>

<p>You mean in Bitcoin Core's wallet? No, they're not picked randomly. There are a number of strategies, but in general the aim is to avoid change if possible, avoid transaction outputs with few confirms if possible, and otherwise create a match close to the amount intended to be sent.</p>

<blockquote>
  <p>My want to change this behaviour and spend UTXOs on 'FIFO' basis. What changes do i need to make?</p>
</blockquote>

<p>That's possible - the wallet already knows the timestamp when transaction outputs were created, so you don't need to make any changes besides changing the coin selection algorithm. In particular, you don't need to add timestamps to UTXOs.</p>

<p>However, FIFO isn't known to be a very good strategy. <a href="http://murch.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf" rel="noreferrer">Mark Erhardt's thesis</a> does a comparative study to analyse various coin selection strategies. There is ongoing work in Bitcoin Core to adopt some of the outcomes of this research, some of which is already completed. In particular, the master branch as of writing (April 2018) includes the <a href="https://github.com/bitcoin/bitcoin/pull/10637" rel="noreferrer">Branch and Bound strategy</a> for change avoidance.</p>

CC BY-SA 3.0
2018-04-15T21:32:38.883Z
2018-04-15T21:32:38.883Z
Pieter Wuille
<p>Transactions and utxos (in Bitcoin) do not have timestamps.</p>

<blockquote>
  <p>What changes do i need to make?</p>
</blockquote>

<p>Change your aim.</p>

CC BY-SA 3.0
2018-04-15T21:19:42.147Z
But the wallet (which is what does coin selection) already knows the timestamps that UTXOs were created, because it knows the transactions that created them. It's unclear to me why you would want FIFO coin selection though; research ib this area shows this is not a very good strategy.
Pieter Wuille
CC BY-SA 3.0
2018-04-15T21:29:10.187Z
I agree that it is not a very good strategy but I need to implement it.
Shahr_96
CC BY-SA 3.0
2018-04-15T21:13:02.307Z
2018-04-15T21:13:02.307Z
amaclin
<p>By default, UTXOs are picked randomly in ElectrumX. I want to change this behaviour and spend UTXOs on 'FIFO' basis. What changes do I need to make?</p>

CC BY-SA 3.0
2018-04-15T23:55:56.220Z
"By default, UTXOs are picked randomly." That may be true for some software, but definitely not all. What wallet software are you using?
Murch
CC BY-SA 3.0
2018-04-16T09:54:10.750Z
Yes, I get it now. I am using Electrumx and I want to change the coin selection behaviour for that.
Shahr_96
<electrum><coin-selection>
How would I need to change ElectrumX to use FIFO selection of UTXOs?
Shahr_96
# How would I need to change ElectrumX to use FIFO selection of UTXOs?

(Asked by: username_0 on 2018-04-15)

By default, UTXOs are picked randomly in ElectrumX. I want to change this behaviour and spend UTXOs on 'FIFO' basis. What changes do I need to make?

**Tags:** electrum, coin-selection

> **Comments:**
> **username_1**: "By default, UTXOs are picked randomly." That may be true for some software, but definitely not all. What wallet software are you using?  
> **username_0**: Yes, I get it now. I am using Electrumx and I want to change the coin selection behaviour for that.  

---

## 2 answers

### Answer by username_2 on 2018-04-15. Score: 7

> By default, UTXOs are picked randomly.

You mean in Bitcoin Core's wallet? No, they're not picked randomly. There are a number of strategies, but in general the aim is to avoid change if possible, avoid transaction outputs with few confirms if possible, and otherwise create a match close to the amount intended to be sent.

> My want to change this behaviour and spend UTXOs on 'FIFO' basis. What changes do i need to make?

That's possible - the wallet already knows the timestamp when transaction outputs were created, so you don't need to make any changes besides changing the coin selection algorithm. In particular, you don't need to add timestamps to UTXOs.

However, FIFO isn't known to be a very good strategy. [Mark Erhardt's thesis](http://username_1.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf) does a comparative study to analyse various coin selection strategies. There is ongoing work in Bitcoin Core to adopt some of the outcomes of this research, some of which is already completed. In particular, the master branch as of writing (April 2018) includes the [Branch and Bound strategy](https://github.com/bitcoin/bitcoin/pull/10637) for change avoidance.


---

### Answer by username_3 on 2018-04-15. Score: -3

Transactions and utxos (in Bitcoin) do not have timestamps.

> What changes do i need to make?

Change your aim.

> **Comments:**
> **username_2**: But the wallet (which is what does coin selection) already knows the timestamps that UTXOs were created, because it knows the transactions that created them. It's unclear to me why you would want FIFO coin selection though; research ib this area shows this is not a very good strategy.  
> **username_0**: I agree that it is not a very good strategy but I need to implement it.  

---

