How does Bitcoin Core choose UTXOs for transactions?

9 replies 110 views
Posts: 5 · Reputation: 128
#1Mar 21, 2023, 12:14 AM
I've been digging into how Bitcoin handles UTXOs (Unspent Transaction Outputs) and its selection process, and I could really use some insights. So, in Bitcoin Core, what kind of algorithm does a wallet use to pick which UTXOs to focus on during a transaction, especially to keep fees low and avoid dust outputs? And hey, is there any way I can manually tweak the UTXO selection process?
7 Reply Quote Share
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#2Mar 21, 2023, 03:27 AM
These should help with your research, the actual algorithm Bitcoin Core use (links are for v29.x branch): github.com/bitcoin/bitcoin/blob/29.x/src/wallet/coinselection.cppgithub.com/bitcoin/bitcoin/blob/29.x/src/wallet/coinselection.h Read the conveniently placed comments in the lines of codes and those should already answer most of your questions. Plus a bonus if you can read the code.
3 Reply Quote Share
humbleledgerLegendary
Posts: 1027 · Reputation: 6554
#3Mar 21, 2023, 09:05 AM
Enable coin control (under Options) to manually select Inputs when Sending a transaction. I can't tell you how Bitcoin Core selects inputs, but I prefer to do it manually anyway. You may want to read my topic on consolidating small inputs. Doing this when fees are low can save a lot later on.
3 Reply Quote Share
DarkSeedSenior Member
Posts: 209 · Reputation: 1423
#4Mar 21, 2023, 09:42 AM
I like Bitcoin Core above all other wallet software because of the Coin Control among other things. Click there: And then simply click the coins you want to move: This way you will have full control. I don't understand how people send transactions without doing this. You don't have privacy unless you control what utxos you are using to send. If you don't then the program should automatically send whatever utxos lead to the less tx size by selecting amounts that are closer to the amount you are sending.
3 Reply Quote Share
bridge2018Full Member
Posts: 50 · Reputation: 405
#5Mar 22, 2023, 04:15 AM
We don't really need Bitcoin core just to have the coin control feature, it is even available in.SPV wallets like Electrum desktop. And the default utxos selection doesn't always be the cheaper TX fees that's why we can send a TX with lowest possible size while using coin control. When we seek privacy than having a node is mandatory, we don't have to rely on third-party nodes to validate our transactions.
0 Reply Quote Share
yield_forkFull Member
Posts: 162 · Reputation: 728
#6Mar 22, 2023, 07:47 AM
One thing I think is really cool about Bitcoin Core is that it's the only wallet that handles the change address based on the address script type: legacy, nested-segwit, bech32, etc. If your transaction has remaining bitcoins to be sent to your change address, the change address chosen will be the same address script type as the recipient's address. e.g if you sent funds to a legacy address, your change address (if any) will also be a legacy address. This helps a lot with privacy and all of this is done by default, you can change it according to what you think is best.
1 Reply Quote Share
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#7Mar 22, 2023, 11:13 AM
It's not the only one, I can name two: First is Mycelium with its default "Privacy Guard" change handling option, that will do that except of course if the output is Taproot which it can't generate. Second is Armory which will try to match the output's script type if set to "Auto-change" (not set by default), Although its "P2SH" is "P2SH-P2PK" which is not commonly used by other clients, the output will look the same as any P2SH outputs.
2 Reply Quote Share
falcon_wizardSenior Member
Posts: 123 · Reputation: 896
#8Mar 22, 2023, 05:18 PM
Coin control has become a standard nowadays. It's like saying, I like car X because it has air conditioning. If your chosen wallet software doesn't have coin control in 2025, you should abandon it and select one that does. Bitcoin Core doesn't do anything special in this case. In fact, it's different from other wallets in that you can't backup your seed phrase, making it a bit more challenging to make back-ups. Its biggest feature is the (full) node capability and being the one that validates and verifies everything personally instead of relying on others to do it.
3 Reply Quote Share
yield_forkFull Member
Posts: 162 · Reputation: 728
#9Mar 22, 2023, 09:33 PM
Thanks, I just remembered Mycelium, it's the wallet I liked to use the most on Android, that is, I haven't used it for years. But I know it offers 3 types of address scripts, that’s what I’d like to see in other wallets. Another wallet that supports three types of receiving address scripts is Coinomi (it hasn't bech32m addresses), but I’m not sure if it handles change addresses using the same script type as the output reserved for the sender. Although Coinomi is closed source. I’ve never used Armory, but I know it’s an excellent advanced wallet, but there are rumors on the forum that the devs would resume its development.
2 Reply Quote Share
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#10Mar 23, 2023, 01:50 AM
I'll get off topic but: It's been in constant development since the last release. It's just going very slowly because there's little to no support from other developers, it's mostly being maintained by a one-man team. Dev branch: github.com/goatpig/BitcoinArmory/tree/dev Master branch: github.com/goatpig/BitcoinArmory/tree/master (there are recent commits and PRs from lu-p-us)
3 Reply Quote Share

Related topics