2

I would like to know the consequences of sending bitcoin several times to the same address. Let us say I send 1 BTC from Address1 to Address3 and later I send 2 BTC from Address2 to Address3 again. The blockchain will have both, 1 BTC and 2 BTC transactions registered. So, What hapens when I want to send 2.5 NTC from Address3 to a new address?

2

It works just fine.

Bitcoin transactions can have multiple inputs and outputs; each input is a "pointer" to an output of a previous transaction (specifically, it consists of a transaction id and output index). So you would create a new transaction with two inputs:

  • the A1->A3 transaction (or more properly, the particular output of this transaction that credited A3)

  • the A2->A3 transaction (again, the particular output).

It's not necessary to include amounts in the inputs, since the rule is that each input must be consumed completely. So we now have 3 BTC worth of inputs in our transaction.

An output consists of an amount and a destination address. (One can also have a script which directs the payment in more elaborate ways, requiring multiple signatures, etc, but let's ignore that for now.) You would want to have two outputs:

  • An output paying 2.5 BTC to the desired destination address, call it A4

  • An output paying the "change", 0.5 BTC, to some address of yours. You could use A3 again, but it is generally better to use a newly generated address; call it A5.

(Actually, in real life, the second output would more likely be something like 0.4995 BTC. The leftover 0.0005 BTC wouldn't appear in any output; it would be a transaction fee, collected by whichever miner includes this transaction in a block.)

For an end user, this is all done under the hood by their wallet software. The user just specifies that they want to pay 2.5 BTS to A4, and the software takes care of identifying appropriate transactions to use as inputs and creating the necessary change output. Sometimes this confuses people when they see that after the transaction, the balance in A3 has dropped from 3 to 0, if they don't know that the remaining 0.5 BTC has gone to a new address A5 which is still theirs.

  • Thanks indeed Steven. It is a very ellaborated answer. However I still have doubts at the protocol level. Let me explain, the first transaction (A1->A3) is saved in block 444,444 of teh blockchain, and the second transaction (A2->A3) is saved in block 444,555 (111 blocks later). When I try to move the balance, there are two different blocks with two different balnces fo rthe same address (A3). DOes it men then that the protocol adds up all unspent balances for a given address? (reviewing then the whole blockchain). – PlatoWright Oct 3 '17 at 14:52
  • 1
    On the contrary - the blocks don't contain balance information at all, so there is no inconsistency. There is a transaction with amount 2 BTC, and another transaction with amount 1 BTC. Nowhere in the blockchain are these numbers added to make 3 BTC; in fact, the blockchain doesn't form any connection between multiple transactions with the same address. It's up to your client software to keep track of all the unspent outputs in the chain that correspond to your addresses, and sum them to show your total balance. – Nate Eldredge Oct 3 '17 at 15:13
  • The system doesn't care that the same key happens to be able to claim both unspent outputs. As far as it's concerned, they're just two unspent outputs in a pool of many, many unspent outputs. – David Schwartz Dec 1 '17 at 12:35

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.