2

So, imagine I bought 1 BTC, so I have my private key generated by my online wallet and also my public key that I can give to people/friends. My question is, if I spend 0.5 to buy Apples on a website?

How does that work?

1) Only 0.5 BTC is sent to the website, I still have 0.5 BTC on private key A

2) 1 BTC total is sent through the protocol, thus the change is sent back to me. On which key? Key A where I had 1 BTC ? Or a new one generated? (Key B)

Thank you :)

  • Since you're using blockchain.info as your wallet provider, it is probably best if you ask them how are your keys managed or read their FAQ – renlord Jan 30 '17 at 8:46
  • I'm really not sure what this question is supposed to be about. 1) Are you asking whether blockchain.info reuses addresses for change outputs? 2) Are you asking whether there can be more than one address per private key? 3) Are you generally asking about wallets managing multiple addresses? – Murch Feb 4 '17 at 14:19
  • Hi, I am asking: I have 1 BTC I buy something at 0.5 BTC. Where is the 0.5 change going to go on my wallet? – Pierrew Feb 4 '17 at 15:08
  • Someone else told me there is no change, so if you have 1 BTC on address A you want to spend 0.5, well you spend it and you still have 0.5 BTC on address A. – Pierrew Feb 4 '17 at 15:09
4

Every private key has exactly one corresponding public key, and every public key has one address. Whenever a new address is generated, internally that means a new private key and public key are generated. Note that with BIP32 and BIP44, private keys can be generated deterministically from a master key or a seed, in which case these new private keys do not necessary need to be saved - they can just be regenerated from the seed or master whenever needed.

A new keypair is used for each change in most wallets, but that's done internally - it won't show you the address for those, as there is no need for anyone else to send you money to that.

Creating addresses is very cheap. A modern CPU can generate 1000s per second. It also does not require any interaction with the network. All that is needed is generating 32 bytes of random data, and computing its corresponding elliptic curve point.

  • Ok thank you but it means that I still keep my FIRST (same) private key of my wallet with the change I received? (internally they should've sent it back to my first adress) right? – Pierrew Jan 29 '17 at 20:55
  • I don't understand your comment. – Pieter Wuille Jan 29 '17 at 22:50
  • "A new key is used for each change in most wallets, but that's done internally" which key? a new private one? or public? – Pierrew Jan 30 '17 at 8:59
  • Edited to keypair. Every private key has one public key (ignoring encoding), and the other way around. – Pieter Wuille Jan 30 '17 at 15:52
0

If all the 1BTC was in one Unspent Transaction Output (UTXO) then you'd indeed send all of the 1BTC as an input in a transaction and assign this to two new outputs: 0.5BTC to make your payment and 0.5BTC to return your change to yourself.

If the 1BTC was split up into several Unspent Transaction Outputs, then you may have a combination that amounts exactly to 0.5BTC, e.g. you could use 0.1BTC+0.2BTC+0.2BTC. Then no change output would be created.

Whether you send change to the same address as before, or to a new address is up to the creator of the transaction. Most wallets avoid reusing the same address by default though, so the change output is sent to a new address.

  • related: How does change work in a bitcoin transaction? – Murch Feb 4 '17 at 16:09
  • Ok thank you! But either way, everything is done automatically by the wallet right? I don't need to care about wether or not the BTC was in one Unspent Transaction Output (UTXO) ? However, when is it truly useful to know that? – Pierrew Feb 4 '17 at 17:45
  • Yes, this sort of managing is exactly the purpose of wallet software. It may be interesting for you to know about your UTXO if you're micromanaging your privacy. – Murch Feb 4 '17 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.