Difference between revisions of "Change"

(Created page with "=DISCLAIMER= This article is a direct copy of the original https://en.bitcoin.it/wiki/Transaction and has not been checked for correctness or edited. 9th October 2019 Expected...")
 
m
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=DISCLAIMER=
+
=== Introduction ===
This article is a direct copy of the original https://en.bitcoin.it/wiki/Transaction and has not been checked for correctness or edited.
+
When a UTXO is spent, it must be consumed entirely. If the value of the UTXO is greater than the amount being spent, then the difference in the amount must be allocated to a new address that the spender owns; this is a change address.
9th October 2019
 
Expected review by: 20 October 2019
 
  
Review BJL 20191009
+
===Example 1===
 +
In a standard payment scenario, the sender consumes a single UTXO, paying the spending amount to the receiver's address, then receiving the change into a new address that they control to take advantage of privacy.
  
 +
In [https://whatsonchain.com/tx/d0033a539a426de7142f4b230328c84306b6ebc1c985515d522a411c397522df this example], we can see that address 197vdcD73wQF5FviYXXgv6cXJBibc9phdq held a UTXO containing 47,097 [[Satoshis]].
  
 +
The sender paid 10,000 Satoshis to 1C7UVhVnspkxot82j6ooMxUUFEWy4Pj1tc and received 36,871 Satoshis as change into address 1LNq2ZePCj2mycctrvQqBVnTLeaJeyDeR4.
  
 +
The difference of 226 Satoshis was paid as [[Transaction fees]] to the Miner who found block 605,046.
  
 +
===Example 2===
 +
In [https://whatsonchain.com/tx/defaaec6d8687a27da68d2bd445dac9c1333c4460246309070a5a3cf40f3d6f0 this example], we can see more clearly that the difference between the input and output is the mining fee.
  
When the output of a transaction is used as the input of another transaction, it must be spent in its entirety. Sometimes the coin value of the output is higher than what the user wishes to pay. In this case, the client generates a new Bitcoin address, and sends the difference back to this address. This is known as [[change]].
+
In this transaction a UTXO held by address 13N2c1uxZee4LYGruhWED6K4P4D8Ncmepq is spent in a transaction that writes a message onto the ledger in an [[False_Return#OP_RETURN_Outputs|OP_RETURN output]], and receives the original amount minus the 276 Satoshi mining fee back into the same address.
  
Say you want to buy a candy bar ($1) from a store. You open your wallet (fiat wallet) and inside there is a single $20 bill.  What is the min amount you can pay?  It isn't $1; you can't rip up 1/20th of the bill and give it to the cashier.  You need to pay $20 and since you only owe $1, the cashier gives you back $19.  Now in fiat nobody except the central bank can make new bills so bills are in fixed denominations and thus your fiat transaction may look something like the following.
+
=== Consolidating UTXOs ===
 +
In some cases, the spender may have many UTXOs that they would like to consolidate. In this situation, the only output is their 'change' address where the total amount, less mining fees is sent.
  
* Inputs:
+
These 'consolidation transactions' have the added benefit of reducing the size of the UTXO set, shrinking the database that all nodes maintain. While the computation for processing these inputs could be expensive, it is envisaged that the savings in storage will encourage Miners to potentially process these types of transactions for a lower fee.
** $20 bill
 
  
* Outputs:  
+
An example can be found [https://whatsonchain.com/tx/682e4ee70f5ba2a174e5427e4bdd645ee229ed64d2b9ca55d315035de6d85668 here].
** $1 bill to cashier
 
** $10 bill to you
 
** $5 bill to you
 
** $1 bill to you
 
** $1 bill to you
 
** $1 bill to you
 
** $1 bill to you
 
  
We do it everyday so it becomes instinctive but if you break it down that is what is happening. Now lets imagine for a second that some system existed which allowed the cashier (or anyone) to securely destroy any authentic fiat money (bills) and print replacements in arbitrary amounts (not just $10s and $20s but $18.94537208 if you wanted to), while preventing double spending, counterfeiting, and ensuring that at all times the amount of money created is exactly the same as the amount of money destroyed. In that case your transaction may look like this:
+
==Attribution==
 
+
This content is based on content sourced from https://en.bitcoin.it/wiki/Change under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated, we acknowledge the original authors.
* Inputs:
 
** $20 bill - destroyed
 
* Outputs:
 
** $1 newly created bill to cashier
 
** $19 newly created bill to you
 
 
 
That is exactly how bitcoin works.  Except instead of bills we call the elements inputs and outputs. When you "spend" bitcoins (create a transaction) you must use the entire value of an unspent output (of a prior transaction) and make it the input for a new transaction.  Your wallet hides this somewhat by continually looking for unspent outputs and adding up their total value.  So when your wallet says you have 130 BTC it simply means the sum of all your unspent outputs total 130 BTC.  Just like a fiat wallet the value comes from one or more discrete bills/outputs.
 
 
 
Take the case of the transaction [http://blockchain.info/tx/0a1c0b1ec0ac55a45b1555202daf2e08419648096f5bcc4267898d420dffef87 0a1c0b1ec0ac55a45b1555202daf2e08419648096f5bcc4267898d420dffef87], a 10.89 BTC previously unspent output was spent by the client. 10 BTC was the payment amount, and 0.89 BTC was the amount of change returned. The client can't spend just 10.00 BTC out of a 10.89 BTC payment anymore than a person can spend $1 out of a $20 bill.  The entire 10.89 BTC unspent output became the input of this new transaction and in the process produced are two new unspent outputs which have a combined value of 10.89 BTC.  The 10.89 BTC is now "spent" and effectively destroyed because the network will prevent it from ever being spent again.  Those unspent outputs can now become inputs for future transactions. 
 
 
 
In this transaction, the fee is 0 but if there was a tx fee paid it would be the difference between the inputs and the outputs. (i.e. 10.89 BTC input and a 10.88 BTC output = 0.01 BTC fee).
 
 
 
The wallet file contains the private keys for change addresses, and they can receive and send coins normally. However, the GUI in the default client does not display them in the address book, therefore a recommendation is to backup wallet.dat every 50 transactions.
 
 
 
==See Also==
 
 
 
* [[Coin analogy]]
 
 
 
[[Category:Technical]]
 
[[Category:Vocabulary]]
 

Latest revision as of 02:51, 27 October 2020

Introduction

When a UTXO is spent, it must be consumed entirely. If the value of the UTXO is greater than the amount being spent, then the difference in the amount must be allocated to a new address that the spender owns; this is a change address.

Example 1

In a standard payment scenario, the sender consumes a single UTXO, paying the spending amount to the receiver's address, then receiving the change into a new address that they control to take advantage of privacy.

In this example, we can see that address 197vdcD73wQF5FviYXXgv6cXJBibc9phdq held a UTXO containing 47,097 Satoshis.

The sender paid 10,000 Satoshis to 1C7UVhVnspkxot82j6ooMxUUFEWy4Pj1tc and received 36,871 Satoshis as change into address 1LNq2ZePCj2mycctrvQqBVnTLeaJeyDeR4.

The difference of 226 Satoshis was paid as Transaction fees to the Miner who found block 605,046.

Example 2

In this example, we can see more clearly that the difference between the input and output is the mining fee.

In this transaction a UTXO held by address 13N2c1uxZee4LYGruhWED6K4P4D8Ncmepq is spent in a transaction that writes a message onto the ledger in an OP_RETURN output, and receives the original amount minus the 276 Satoshi mining fee back into the same address.

Consolidating UTXOs

In some cases, the spender may have many UTXOs that they would like to consolidate. In this situation, the only output is their 'change' address where the total amount, less mining fees is sent.

These 'consolidation transactions' have the added benefit of reducing the size of the UTXO set, shrinking the database that all nodes maintain. While the computation for processing these inputs could be expensive, it is envisaged that the savings in storage will encourage Miners to potentially process these types of transactions for a lower fee.

An example can be found here.

Attribution

This content is based on content sourced from https://en.bitcoin.it/wiki/Change under Creative Commons Attribution 3.0. Although it may have been extensively revised and updated, we acknowledge the original authors.