Bitcoin Forum

Other => Beginners & Help => Topic started by: ungirt on April 22, 2013, 03:30:50 PM



Title: Change addresses
Post by: ungirt on April 22, 2013, 03:30:50 PM
I'm sure this has been asked before... but this is the newbie forum right? Can someone explain to me how change addresses work?

So lets say I have a wallet in multibit with 5 addresses and 1 BTC has been sent to each address. An address is one key pair right, so essentially each of the private keys has 1 BTC... I think?

So now I send someone 3.5 BTC. What happens? Am I left with one address with 1 BTC and another address with 0.5 BTC, if so how does Multibit decide what addresses to take the coins from? Or am I left with one address with 1.5 BTC and all the others empty, if so how does multibit decide which address is the "change address"?

???


Title: Re: Change addresses
Post by: DannyHamilton on April 22, 2013, 03:40:03 PM
Every wallet handles the situation differently, so you'll get better responses if you specify MultiBit in your Subject line.

I really haven't learned much about the inner workings of MultiBit yet, so you'll have to wait for someone else to stop by.


Title: Re: Change addresses
Post by: CIYAM on April 22, 2013, 03:43:05 PM
Like Danny I am not up with MultiBit but basically it has only two choices wrt change.

1) Create a new address and send it there (which is how the Satoshi client behaves)

2) Send the change back to one of the existing addresses (I guess this should be easily verifiable by experiment).


Title: Re: Change addresses
Post by: ungirt on April 22, 2013, 03:52:41 PM
Every wallet handles the situation differently, so you'll get better responses if you specify MultiBit in your Subject line.

I've used MultiBit as an example but to be honest I'd be interested in knowing how the different wallets handle it differently.

Quote from: CIYAM Open
Like Danny I am not up with MultiBit but basically it has only two choices wrt change.

1) Create a new address and send it there (which is how the Satoshi client behaves)

2) Send the change back to one of the existing addresses (I guess this should be easily verifiable by experiment).

Ah OK, that makes sense - thanks. So am I right in assuming that irrespective of what choice the wallet makes, in terms of my example above it takes the entire balance from all the addresses in the wallet, and then puts the change either in a new address or one of the existing ones? So every time you send some bitcoins, all the remaining coins from various addresses in that wallet end up in one address?


Title: Re: Change addresses
Post by: condor335 on April 22, 2013, 03:56:16 PM
I disagree reginald.


Title: Re: Change addresses
Post by: CIYAM on April 22, 2013, 03:56:26 PM
All UTXOs need to be spent *in full* (if not then the remainder is *fees*) so yes the client can only do one of the two.


Title: Re: Change addresses
Post by: DannyHamilton on April 22, 2013, 04:10:46 PM
- snip -
it takes the entire balance from all the addresses in the wallet, and then puts the change either in a new address or one of the existing ones? So every time you send some bitcoins, all the remaining coins from various addresses in that wallet end up in one address?

No.  The wallet will choose a set of previously unspent outputs to spend.  That set may be every output in the wallet, but it also may just be a subset of unspent outputs.

In your example, it is possible that the wallet will spend four of the five 1 BTC outputs, and send 0.5 BTC as a new output to a change address.  It is also possible that a wallet could choose to spend all five of the unspent outputs and send 1.5 BTC as a new output to a change address.

Note that if four of the unspent outputs are chosen, and the 0.5 BTC "change" is sent to the remaining address that already has a 1 BTC output, that address now has 2 separate outputs (a 1 BTC output and a 0.5 BTC output) that can each be spent in a future transactions individually.  On the other hand, if all five outputs are chosen, and the 1.5 BTC "change" is sent to an address, than address now has a single 1.5 BTC output that must be spent in full in some future transaction.