How does Internal Keychain exactly work?

0

I understand that an internal keychain is used to receive a change of payment when I pay someone.

For example, I pay $20, but it costs $17, so I get $3.

But what I don't understand is how can there be a change? When I send 1 BTC to someone, how does the receiving end determine that I overpaid by 0.9 BTC and send that back to me?

Carol Ward

Posted 2019-04-17T19:17:05.420

Reputation: 131

Answers

1

Bitcoin does not have the concept of account balance. It works on consuming the bitcoins that you have earnt in prior transactions. However, you cannot consume partial amounts. So according to your example, when you are creating a new transaction, in the inputs you will reference the transaction where you earnt the 1 BTC (it may be a single transaction where you got your 1 BTC, or you might reference multiple transactions whose values all add up to 1 BTC) and consume it entirely. Now in the outputs, you will send 0.1 BTC to address A and say 0.895 BTC to your change address. The difference of 0.005 BTC will go as mining fees.

Ugam Kamat

Posted 2019-04-17T19:17:05.420

Reputation: 5 180

so every time I'm sending a bitcoin, I'm sending my entire balance and receiving balance - payment - mining fee back to my change address? What if I don't have a whole bitcoin? What if I only have 0.001 BTC?Carol Ward 2019-04-17T19:39:52.003

@CarolWard you have to reference multiple transactions in the inputs where you earned your BTCs and the values from those transaction should that add up to an amount that is more that want to intend to pay to a person. the difference (after removing mining fees) is what would go to your change address.Ugam Kamat 2019-04-17T19:48:15.990

ok. I think I'm starting to understand. So when I send 0.001 BTC, the wallet references enough transactions together that equals 0.001 BTC or greater. If it's exactly 0.001 BTC, then no change needed. If it's 0.0017 BTC, then it pays 0.001 BTC to the recipient, pays mining fee (let's say 0.0003 BTC), and send the change of 0.0004 back to my change address. Is that right?Carol Ward 2019-04-17T20:05:05.443

@CarolWard that is correctchytrik 2019-04-17T20:05:54.737