|
April 22, 2021, 09:58:57 PM |
|
For others that see this thread and don't fully understand what achow101 means when he says: "Bitcoin operates on a UTXO model, not an accounts model".
Here are some details to understand.
#1. There are no addresses in the blockchain. Addresses are an abstraction that we humans use to make it easier to talk about the transfer of control over value. When we put an address into the "send to" part of a user interface, that software uses information embedded within that address to create a standard set of instructions. That set of instructions is what is actually stored in the blockchain. Then when other bitcoin software sees the standard set of instructions, it translates those instructions back into an address with embedded information to show to us humans.
#2. The instructions don't say "transfer this amount to..." or "this identifier has this balance" or anything like that. Instead a transaction has two sections. The first section (commonly called the INPUTs) says "here is some value that I can prove I have control over, I am providing proof that I have control over this value and as such ALL of this value is now under the control of this transaction". The second section (commonly called the OUTPUTs) says "of the value under the control of this transaction, this amount is to be put under the control of whomever can provide a digital signature associated with a public key that hashes to the following value".
#3. When I want to supply value to a transaction that I'm creating, I MUST provide a list of OUTPUTS that have NEVER before been used as INPUTS. I must also provide a digital signature for each of those listed OUTPUTS proving that I'm the whomever that is authorized to spend them. Once I list those as INPUTS, they can NEVER again be used as INPUTS to another transaction.
So, lets imagine that I've received 10 BTC. Those were sent to me in 3 separate transactions (one for 1 BTC, one for 2 BTC and one for 7 BTC). Each of those are a separate OUTPUT that I have control over and can spend. My wallet software recognizes the scripts and tells me that I have 10BTC, but internally it knows that what I ACTUALLY have is 3 OUTPUTS valued at 1, 2, and 7 BTC respectively.
Now, I want to send 2.5 BTC to someone. My wallet software might choose to spend the 1 BTC output and the 2 BTC output as INPUTS to this transaction (providing 3 BTC of value to the transaction). It will provide the necessary signatures for those two INPUTS. Then it will create an OUTPUT that says that (of the 3 BTC of value provided to the transaction) 2.5 BTC are to be put under the control of whoever can provide the signature associated with the public key that hashes to the value embedded in the address that I'm "sending to".
That still leaves 0.5 BTC of value associated with the transaction. If I want that 0.5 BTC to be back under MY control, then my wallet software needs to create ANOTHER new OUTPUT with instructions that puts that 0.5 BTC under control of whoever can provide the signature associated with the public key that hashes to a value embedded in one of MY bitcoin addresses (either the same address that the 1 BTC and 2 BTC were originally sent to, or some other address that my wallet software knows it has the keys to). This additional OUTPUT that puts the excess into a new OUTPUT still under my control is often called a "change output" or "transaction change" since it is analogous to the "change" that you get back from a cashier when you give them more money than needed to pay for whatever you are buying.
Note that ANY value that is left over (SPENT in the INPUTS and not accounted for in the OUTPUTS) is what is commonly called a "transaction fee". This is the value that the miners (or mining pools) get to reward to themselves when they've included the transaction in a block that they've successfully "mined". So, if you wanted to pay a 0.01 BTC transaction fee in that transaction we just discussed, then instead of assigning 0.5 BTC to yourself in the "change output", you would just assign 0.49 BTC. The remaining 0.01 BTCC would be left for the miners to claim for themselves when they confirm your transaction into a block.
If you try to re-broadcast my transaction, every node on the network will recognize that the specific 1BTC and 2BTC outputs that the transaction is attempting to use as INPUTS are no longer available (they've already been spent). Therefore, the rebroadcast transaction is not valid as a new transaction. If the original transaction is not yet confirmed, then the nodes will see that the transaction which spends those inputs is ALREADY in their mempool, so they won't bother to add it to the mempool again.
|