<p>You can do this with 1 transaction, it will get more expensive, but it has nothing to do with whether you use separate addresses or not (or with whether or not you're using BIP32 in any way or form, for that matter).</p>

<p>Bitcoin uses a UTXO model: every transaction has 1 or more inputs, and one or more outputs. Every output creates a UTXO (which you can think of as "a coin", with a certain address and a certain amount). Every input consumes an entire UTXO. Change is simply an output that goes back to yourself, because the sum of the input values exceeds the amount you want to send. Change always requires a separate output, whether it reuses an address or not.</p>

<p>So, what matters to the complexity (and thus cost) of your transaction is how many inputs you need. If that's outputs created in 10000 outputs, you will need 10000 inputs, regardless of whether they're all in the same address or not.</p>

CC BY-SA 4.0
2020-04-03T23:35:27.343Z
So it doesn't really matter if they come from different addresses as long as I have the private key for each one of those addresses so I can sign and spend every input? ohhh ok that makes so much sense! Thanks a lot!
Oscar Serna
CC BY-SA 4.0
2020-04-03T23:30:47.880Z
2020-04-04T06:54:15.263Z
2020-04-04T06:54:15.263Z
Pieter Wuille
<p>I am developing my own wallet in python for which I have already implemented BIP32 and BIP39. According to BIP32 documentation, change should be stored in different addresses as well as payments received. This is fine. However, how can I spend my bitcoins when they are stored in different addresses? Let's suppose I have 1000000 satoshis in 10000 different addresses that are derived from <code>m/0'/1'/</code> path, and each address has 100 satoshis. If I need to send my 1000000 satoshis to XYZ address, can I build a single raw transaction to achieve this, or do I have to create a raw transaction for every single address that is storing my change? Isn't this very expensive?</p>

<transactions><wallet><bip32-hd-wallets><raw-transaction>
How to spend the change in a BIP32 super account?
Oscar Serna
# How to spend the change in a BIP32 super account?

(Asked by: username_0 on 2020-04-03)

I am developing my own wallet in python for which I have already implemented BIP32 and BIP39. According to BIP32 documentation, change should be stored in different addresses as well as payments received. This is fine. However, how can I spend my bitcoins when they are stored in different addresses? Let's suppose I have 1000000 satoshis in 10000 different addresses that are derived from `m/0'/1'/` path, and each address has 100 satoshis. If I need to send my 1000000 satoshis to XYZ address, can I build a single raw transaction to achieve this, or do I have to create a raw transaction for every single address that is storing my change? Isn't this very expensive?

**Tags:** transactions, wallet, bip32-hd-wallets, raw-transaction


---

## 1 answers

### Answer by username_1 on 2020-04-03. Score: 2 | Accepted answer

You can do this with 1 transaction, it will get more expensive, but it has nothing to do with whether you use separate addresses or not (or with whether or not you're using BIP32 in any way or form, for that matter).

Bitcoin uses a UTXO model: every transaction has 1 or more inputs, and one or more outputs. Every output creates a UTXO (which you can think of as "a coin", with a certain address and a certain amount). Every input consumes an entire UTXO. Change is simply an output that goes back to yourself, because the sum of the input values exceeds the amount you want to send. Change always requires a separate output, whether it reuses an address or not.

So, what matters to the complexity (and thus cost) of your transaction is how many inputs you need. If that's outputs created in 10000 outputs, you will need 10000 inputs, regardless of whether they're all in the same address or not.

> **Comments:**
> **username_0**: So it doesn't really matter if they come from different addresses as long as I have the private key for each one of those addresses so I can sign and spend every input? ohhh ok that makes so much sense! Thanks a lot!  

---

