Skip to main content
16 votes
Accepted

What's the most efficient way to create a raw transaction with a specific fee rate?

Yes! The trick is to count each input with its effective value rather than its nominal value. Transactions are composed of three parts: the overhead, the inputs and the outputs. Outputs: The size of ...
Murch's user avatar
  • 77.9k
9 votes
Accepted

What does "Waste Metric" mean in the context of Coin Selection?

Coin Selection Funds are tracked in discrete portions, so called Unspent Transaction Outputs (see UTXO model). Generally, a wallet's funds are split across multiple to numerous such UTXOs. When a ...
Murch's user avatar
  • 77.9k
7 votes

How would I need to change ElectrumX to use FIFO selection of UTXOs?

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, ...
Pieter Wuille's user avatar
6 votes

What's the most efficient way to create a raw transaction with a specific fee rate?

Kind of, but coin selection is hard in general. The idea is that inputs pay for themselves. It is easy to compute how much in fees you will need to pay for an input at a given fee rate. So when you do ...
Ava Chow's user avatar
  • 72.2k
6 votes
Accepted

Why are there round numbers after the fees and no change?

If your wallet has a large UTXO pool with some variance in the values, it is often possible to find a combination of inputs that provide a matching amount to pay for recipient output and transaction ...
Murch's user avatar
  • 77.9k
6 votes

Why do some transactions have more than one input?

What might be confusing you, and which is a common misconception, is that the addresses themselves somehow "hold" the bitcoin balances, and gain and lose the coins via transactions. In fact all the ...
meshcollider's user avatar
  • 11.9k
5 votes
Accepted

What's partial spending? What does avoidpartialspend do?

Currently, best practices are to receive coins to an address only once - Any reasonably new wallet will generate a new receiving address for you if the previously displayed one has already received ...
Raghav Sood's user avatar
  • 17.3k
5 votes
Accepted

Are all UTXOs locked by an address spent in a transaction?

Transactions explicitly refer to which UTXOs they are spending. You can construct a transaction which only spends one of the two 5-BTC UTXOs, and sends 2 BTC to the destination and 3 BTC to a (...
Pieter Wuille's user avatar
5 votes
Accepted

Is there a way to allow use of unconfirmed RBF outputs in transaction building?

Bitcoin Core will happily spend RBF marked inputs it doesn't avoid them much less prohibit them. Perhaps you're being confused by the fact that it will not spend an unconfirmed input created by a ...
G. Maxwell's user avatar
  • 7,727
5 votes
Accepted

Coin selection algorithm

There are a lot of things that need to be considered when selecting coins. Just covering the amount that you want to send is not enough, you have not considered the transaction fees that you will be ...
Ava Chow's user avatar
  • 72.2k
5 votes

How does the Branch and Bound coin selection algorithm work?

Disclosure: I’m describing my own work: the Branch and Bound coin selection algorithm was first described in my own Master thesis. The Branch and Bound algorithm searches for the least wasteful input ...
Murch's user avatar
  • 77.9k
5 votes
Accepted

How does Bitcoin Core Wallet calculate the weight of each input before it's spent?

The coin selection algorithms all use an estimated weight. It is not a metric but rather the estimated weight that the resulting input will have. The estimate is based on the type of the output script....
Ava Chow's user avatar
  • 72.2k
4 votes

Has UTXO selection methods changed since activation of Segwit?

Segwit corrects this incentive mismatch. Segwit only improves the ratio, but outputs are still cheaper than inputs even with segwit. As sr-gi mentioned in his answer, the Branch and Bound algorithm ...
Murch's user avatar
  • 77.9k
4 votes

Has UTXO selection methods changed since activation of Segwit?

Bitcoin Core's client has recently applied changes to their coin selection algorithms based on Murch's Master's thesis.
sr_gi's user avatar
  • 3,260
4 votes
Accepted

Address Reuse vs. Coin Selection

Do the instructions to not reuse an address include change? That is, should I generate a new key pair for any transaction that needs to receive change, and then manually specify my change be sent to ...
Pieter Wuille's user avatar
4 votes

How do I know which UTXOs are safe to spend?

Is there an easy way to make sure a UTXO doesn't have rare sats/inscriptions/anything else No. There isn't an easy way, because there is no central coordination of these forms of graffiti and ...
RedGrittyBrick's user avatar
4 votes
Accepted

How do I know which UTXOs are safe to spend?

How do I pick UTXOs, which are safe to spend? Is there an easy way to make sure a UTXO doesn't have rare sats/inscriptions/anything else before spending it? Those UTXOs are still "safe" to ...
Arminsdev's user avatar
4 votes
Accepted

How light can an input be?

In the rust-bitcoin code, the 160 is a minimum weight, denominated in weight units, not size. 160 weight units corresponds to 40 (virtual) bytes. In the Bitcoin Core coin selection unit test, the 150 ...
Ava Chow's user avatar
  • 72.2k
3 votes
Accepted

Is there a concept of tolerance used in coin selection algos in Bitcoin Core?

Yes, Bitcoin Core will permit slightly overshooting the selection target when using the Branch and Bound algorithm, as long as the overshoot is smaller than the cost of creating and spending a change ...
Murch's user avatar
  • 77.9k
3 votes

Calculating fee based on fee rate for bitcoin transaction

There are some improvements that you can make to this algorithm. The first is to select UTXOs based on their effective value. The effective value is the value of the UTXO with the amount in fees ...
Ava Chow's user avatar
  • 72.2k
3 votes
Accepted

Testing `avoidpartialspends` option in Bitcoin Core

In this particular case, it is because Bitcoin Core prefers to make transactions which do not create change over anything else. Notice how this transaction does not have any change. If the Branch and ...
Ava Chow's user avatar
  • 72.2k
3 votes

Is there a way to determine the optimal size of a batched transaction to save on fees?

But at some point the sum of the amounts of the ouputs will grow bigger than the one input I added at first and I'll need to add another input. If I have relatively big ouputs to spend this is ...
Antoine Poinsot's user avatar
3 votes
Accepted

bitcoin-core automatic coin selection

This occurs because Bitcoin Core's coin selection algorithm tries to have a minimum change of 0.01 BTC. Fees are subtracted from the change output so the result is that the change output has a lower ...
Ava Chow's user avatar
  • 72.2k
3 votes

How does a Bitcoin (Core) wallet use inputs?

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 ...
Murch's user avatar
  • 77.9k
3 votes

Address Reuse vs. Coin Selection

Does following the address reuse recommendation render the concept of coin selection useless? No, it does not. It seems like the main misconception is that using an address multiple times creates ...
Ava Chow's user avatar
  • 72.2k
3 votes

What does Bitcoin Core's "Coin Control Features" do and how do I use it?

When making a payment, Bitcoin Core will automatically pick an input set to fund the transaction. The Coin Control feature allows the user to perform the input selection manually instead. Explicitly ...
Murch's user avatar
  • 77.9k
2 votes
Accepted

coin selection - why selecting transactions with confirmations first better

Many wallet implementations prefer spending confirmed inputs over unconfirmed inputs. There are multiple reasons for this preference: Bitcoin Core (and perhaps other software as well) does not ...
Murch's user avatar
  • 77.9k
2 votes
Accepted

why is BnB coin selection algorithm not enabled by default?

You're misunderstanding the code. That variable tracks whether BnB was used. Not whether we attempt to use it. BnB does not always yield an acceptable result, as it requires a solution with no change ...
Pieter Wuille's user avatar
2 votes

Calculating fee based on fee rate for bitcoin transaction

If you don't account for the fees of the inputs until after selecting the inputs, your target is shifting while you're selecting with each input you add. Since your transaction building starts with a ...
Murch's user avatar
  • 77.9k

Only top scored, non community-wiki answers of a minimum length are eligible