<p>The two preceding answers describe correctly that there is no network-wide requirement to order inputs or outputs, but I don't agree that the "order doesn't matter".</p>

<p>Early on, many wallets did order their inputs and outputs, e.g. the inputs were in the order the addresses were created, in the order that they got picked by the wallet's coin selection, or simply sorted by age. Similarly, outputs would often list the recipient outputs first and the change output last. Such patterns are a privacy leak as they fingerprint the used wallet software, and may allow observers to learn additional data about the user's finances.</p>

<p>If everyone shuffled the inputs and outputs of a transaction properly these issues would be mitigated. However, it can be difficult to recognize whether an order is random or follows a more complex pattern. From what I understand, this is why <a href="https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki" rel="nofollow noreferrer">BIP69</a> instead suggests a global adoption of sorting inputs and outputs lexicographically. Again, everyone would be indistinguishable if they all sorted the same way, and it would be much easier to audit, test, and notice wallets that don't adhere to such a standard.</p>

CC BY-SA 4.0
2019-11-30T21:24:14.343Z
Great answer, thank you for pointing me in the direction of BIP69
K Stewart
CC BY-SA 4.0
2019-11-29T18:11:57.507Z
2019-11-29T18:11:57.507Z
Murch
<p>The convention is to have the outputs in random order. This is specifically done in an effort to conceal which output is the <a href="https://bitcoin.org/en/glossary/change-address" rel="nofollow noreferrer">change output</a>. The change is by default sent to a new address that is owned by the sender, and as such has no history associated with it.</p>

<p>The majority of bitcoin's code is actually c++. Here is a link to the relevant <a href="https://github.com/bitcoin/bitcoin/blob/0.19/src/wallet/wallet.cpp#L2976" rel="nofollow noreferrer">transaction creation code</a>, maybe there are a few comments that could point you in the right direction.</p>

CC BY-SA 4.0
2019-11-26T01:54:48.090Z
Thank you, presstab. My question may not have been very clear. I am looking for the order of the inputs. But, the order of the outputs are just as important for my use case. I will check out the link.
K Stewart
CC BY-SA 4.0
2019-11-26T03:24:14.360Z
The order of the inputs does not matter. What does matter is that the inputs have not been spent, have valid signature, and are worth more than the outputs of the transaction being created.
presstab
CC BY-SA 4.0
2019-11-26T01:49:10.453Z
2019-11-26T01:49:10.453Z
presstab
<p>No, the order in which you add inputs while building a raw transaction does not matter. The RPC documentation on raw transactions describes what you need to <a href="https://bitcoincore.org/en/doc/0.19.0/rpc/rawtransactions/createrawtransaction/" rel="nofollow noreferrer">create a transaction</a> and/or <a href="https://bitcoincore.org/en/doc/0.19.0/rpc/rawtransactions/signrawtransactionwithkey/" rel="nofollow noreferrer">sign</a>. </p>

CC BY-SA 4.0
2019-11-26T03:03:45.093Z
Why on earth would you order them? That makes absolutely no sense.
Claris
CC BY-SA 4.0
2019-11-26T15:04:25.617Z
No, there is no need for this. All private keys will be available for all transaction input, regardless of their order. You may be confusing with the OP_CHECKMULTISIG opcode, which requires signatures in the same order as its public keys? Even there, the RPC interface to Bitcoin Core does not care about the order private keys are passed in in.
Pieter Wuille
CC BY-SA 4.0
2019-11-27T04:48:02.223Z
Edited to remove incorrect detail on the array input.
m1xolyd1an
CC BY-SA 4.0
2019-11-26T01:58:07.250Z
2019-11-27T04:46:34.573Z
2019-11-27T04:46:34.573Z
m1xolyd1an
<p>I am not sure it matters to produce a correctly formatted transaction, but I am playing around with a wallet that does not keep its own private keys, but produces the raw txs to sign and want to give the user the ability to verify the details of the raw txs with a third party or some control libraries. Assume, Bitcoin Core sets the standard, but I am unfortunately C illiterate. Thanks, Kyle</p>

<bitcoin-core><raw-transaction>
Is there a convention for how to order UTXOs in a transaction with multiple inputs?
K Stewart
# Is there a convention for how to order UTXOs in a transaction with multiple inputs?

(Asked by: username_0 on 2019-11-26)

I am not sure it matters to produce a correctly formatted transaction, but I am playing around with a wallet that does not keep its own private keys, but produces the raw txs to sign and want to give the user the ability to verify the details of the raw txs with a third party or some control libraries. Assume, Bitcoin Core sets the standard, but I am unfortunately C illiterate. Thanks, Kyle

**Tags:** bitcoin-core, raw-transaction


---

## 3 answers

### Answer by username_1 on 2019-11-29. Score: 1 | Accepted answer

The two preceding answers describe correctly that there is no network-wide requirement to order inputs or outputs, but I don't agree that the "order doesn't matter".

Early on, many wallets did order their inputs and outputs, e.g. the inputs were in the order the addresses were created, in the order that they got picked by the wallet's coin selection, or simply sorted by age. Similarly, outputs would often list the recipient outputs first and the change output last. Such patterns are a privacy leak as they fingerprint the used wallet software, and may allow observers to learn additional data about the user's finances.

If everyone shuffled the inputs and outputs of a transaction properly these issues would be mitigated. However, it can be difficult to recognize whether an order is random or follows a more complex pattern. From what I understand, this is why [BIP69](https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki) instead suggests a global adoption of sorting inputs and outputs lexicographically. Again, everyone would be indistinguishable if they all sorted the same way, and it would be much easier to audit, test, and notice wallets that don't adhere to such a standard.

> **Comments:**
> **username_0**: Great answer, thank you for pointing me in the direction of BIP69  

---

### Answer by username_2 on 2019-11-26. Score: 1

The convention is to have the outputs in random order. This is specifically done in an effort to conceal which output is the [change output](https://bitcoin.org/en/glossary/change-address). The change is by default sent to a new address that is owned by the sender, and as such has no history associated with it.

The majority of bitcoin's code is actually c++. Here is a link to the relevant [transaction creation code](https://github.com/bitcoin/bitcoin/blob/0.19/src/wallet/wallet.cpp#L2976), maybe there are a few comments that could point you in the right direction.

> **Comments:**
> **username_0**: Thank you, username_2. My question may not have been very clear. I am looking for the order of the inputs. But, the order of the outputs are just as important for my use case. I will check out the link.  
> **username_2**: The order of the inputs does not matter. What does matter is that the inputs have not been spent, have valid signature, and are worth more than the outputs of the transaction being created.  

---

### Answer by username_3 on 2019-11-26. Score: 0

No, the order in which you add inputs while building a raw transaction does not matter. The RPC documentation on raw transactions describes what you need to [create a transaction](https://bitcoincore.org/en/doc/0.19.0/rpc/rawtransactions/createrawtransaction/) and/or [sign](https://bitcoincore.org/en/doc/0.19.0/rpc/rawtransactions/signrawtransactionwithkey/).

> **Comments:**
> **username_4**: Why on earth would you order them? That makes absolutely no sense.  
> **username_5**: No, there is no need for this. All private keys will be available for all transaction input, regardless of their order. You may be confusing with the OP_CHECKMULTISIG opcode, which requires signatures in the same order as its public keys? Even there, the RPC interface to Bitcoin Core does not care about the order private keys are passed in in.  
> **username_3**: Edited to remove incorrect detail on the array input.  

---

