<p>The inputs are chosen by the function <code>SelectCoins()</code> in <a href="https://github.com/bitcoin/bitcoin/blob/0.11/src/wallet/wallet.cpp#L1801" rel="nofollow"><code>CreateTransaction()</code></a> and then <a href="https://github.com/bitcoin/bitcoin/blob/0.11/src/wallet/wallet.cpp#L1899" rel="nofollow">added one by one (without shuffling)</a> to the transaction.</p>

<p>The order is defined by the coin selection (<code>CWallet::SelectCoinsMinConf</code>) which does a random shuffle of the potential useful inputs and a stochastic approximation.</p>

<p>Mind also that Bitcoin-Core's coin selection could be improved and there are several issues and improve proposals (<a href="https://github.com/bitcoin/bitcoin/pull/4906" rel="nofollow">[1]</a>, <a href="https://github.com/bitcoin/bitcoin/issues/1643" rel="nofollow">[2]</a>, <a href="https://github.com/bitcoin/bitcoin/issues/3631" rel="nofollow">[3]</a>)</p>

CC BY-SA 3.0
2015-08-13T07:28:42.563Z
2015-08-13T10:26:18.623Z
2015-08-13T10:26:18.623Z
Jonas Schnelli
<p>What order does Bitcoin core place the inputs it spends in? Is it random? Is it sorted by anything? What, if anything, can you tell about the originator of a transaction by the input ordering?</p>

CC BY-SA 3.0
2015-08-13T10:26:56.460Z
related: [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/q/1077/5406)
Murch
<bitcoin-core><coin-selection><transaction-input>
What order does Bitcoin Core place the inputs it spends in?
Nick ODell
# What order does Bitcoin Core place the inputs it spends in?

(Asked by: username_0 on 2015-08-13)

What order does Bitcoin core place the inputs it spends in? Is it random? Is it sorted by anything? What, if anything, can you tell about the originator of a transaction by the input ordering?

**Tags:** bitcoin-core, coin-selection, transaction-input

> **Comments:**
> **username_1**: related: [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/q/1077/5406)  

---

## 1 answers

### Answer by username_2 on 2015-08-13. Score: 5

The inputs are chosen by the function `SelectCoins()` in [`CreateTransaction()`](https://github.com/bitcoin/bitcoin/blob/0.11/src/wallet/wallet.cpp#L1801) and then [added one by one (without shuffling)](https://github.com/bitcoin/bitcoin/blob/0.11/src/wallet/wallet.cpp#L1899) to the transaction.

The order is defined by the coin selection (`CWallet::SelectCoinsMinConf`) which does a random shuffle of the potential useful inputs and a stochastic approximation.

Mind also that Bitcoin-Core's coin selection could be improved and there are several issues and improve proposals ([[1]](https://github.com/bitcoin/bitcoin/pull/4906), [[2]](https://github.com/bitcoin/bitcoin/issues/1643), [[3]](https://github.com/bitcoin/bitcoin/issues/3631))


---

