<p>Bitcoin Core's coin selection algorithm has had multiple improvements in the past years. More recent versions of Bitcoin Core (<a href="https://github.com/bitcoin/bitcoin/pull/10637" rel="nofollow noreferrer">0.17.0+</a>) will attempt to select an input set that does not require a change output. If you are on a sufficiently recent version of Bitcoin Core, it should find and prefer such a solution if one is possible.</p>
<p>This means that either the wallet's UTXO pool did not yield such a solution or your version of Bitcoind is older than 0.17.0. In the former case, you may want to use coin control or <code>createrawtransaction</code>  to fall back to manual selection to enforce your selection requirements, in the latter case, you may want to update and try again.</p>
<p>Note that the current difficulty period has had exceptionally low blockspace demand, and it would be an excellent time to consolidate some of your &quot;several hundred small&quot; UTXOs to bigger UTXOs at the minimum feerate of 1 sat/vB. If you were attempting to send at a low feerate, a transaction with 47 inputs might actually save you money in the long run.</p>

CC BY-SA 4.0
2021-06-19T07:29:39.860Z
I'm on 0.19.  I'll look into coin control.
David Hoelzer
CC BY-SA 4.0
2021-06-18T18:58:37.003Z
2021-06-18T18:58:37.003Z
Murch
<p>I have a wallet that has several hundred small amounts residing at multiple addresses.  I noticed yesterday that, when sending a relatively small amount to a third party that the bitcoind &quot;swept&quot; about 47 of those small amounts together as <code>vin</code> amounts and generated two <code>vout</code> destinations; 1 is the third party, the second is a new address in the wallet (a change address).</p>
<p>What surprised me is that, rather than assembling only the number of fragments necessary for the transfer (plus fee), it swept many of the fragments together to generate a much larger than necessary change transfer.</p>
<p>To give some specifics but to keep it simple:</p>
<ul>
<li>I initiated a <code>sendtoaddress</code> via the cli.  The amount transferred was 0.004 BTC</li>
<li>Bitcoind used some 47 existing fragments as vin, generating a total value of 0.08+ BTC</li>
</ul>
<p>Is there any way, aside from manually generating a raw transaction (which I can do, but I prefer not to when I can avoid it since a simple error can result in inadvertently generating a large fee amount... :) ) to force <code>sendtoaddress</code> to assemble only the minimal pieces needed?</p>

<bitcoind><coin-selection><coin-control>
Is there a way to avoid sendtoaddress from "sweeping"?
David Hoelzer
# Is there a way to avoid sendtoaddress from "sweeping"?

(Asked by: username_0 on 2021-06-12)

I have a wallet that has several hundred small amounts residing at multiple addresses. I noticed yesterday that, when sending a relatively small amount to a third party that the bitcoind "swept" about 47 of those small amounts together as `vin` amounts and generated two `vout` destinations; 1 is the third party, the second is a new address in the wallet (a change address).

What surprised me is that, rather than assembling only the number of fragments necessary for the transfer (plus fee), it swept many of the fragments together to generate a much larger than necessary change transfer.

To give some specifics but to keep it simple:

* I initiated a `sendtoaddress` via the cli. The amount transferred was 0.004 BTC
* Bitcoind used some 47 existing fragments as vin, generating a total value of 0.08+ BTC

Is there any way, aside from manually generating a raw transaction (which I can do, but I prefer not to when I can avoid it since a simple error can result in inadvertently generating a large fee amount... :) ) to force `sendtoaddress` to assemble only the minimal pieces needed?

**Tags:** bitcoind, coin-selection, coin-control


---

## 1 answers

### Answer by username_1 on 2021-06-18. Score: 2

Bitcoin Core's coin selection algorithm has had multiple improvements in the past years. More recent versions of Bitcoin Core ([0.17.0+](https://github.com/bitcoin/bitcoin/pull/10637)) will attempt to select an input set that does not require a change output. If you are on a sufficiently recent version of Bitcoin Core, it should find and prefer such a solution if one is possible.

This means that either the wallet's UTXO pool did not yield such a solution or your version of Bitcoind is older than 0.17.0. In the former case, you may want to use coin control or `createrawtransaction` to fall back to manual selection to enforce your selection requirements, in the latter case, you may want to update and try again.

Note that the current difficulty period has had exceptionally low blockspace demand, and it would be an excellent time to consolidate some of your "several hundred small" UTXOs to bigger UTXOs at the minimum feerate of 1 sat/vB. If you were attempting to send at a low feerate, a transaction with 47 inputs might actually save you money in the long run.

> **Comments:**
> **username_0**: I'm on 0.19.  I'll look into coin control.  

---

