When I pay, how is my balance checked, if I use different address every time?

1

I know there are quite similar questions, but none have addressed my issue. Let's say I use Electrum wallet, that generates addresses & keypairs from seed. So for every next transaction I use different private key, public key & address. So (as I understand) when I want to buy something I send my address encrypted with private key to recipient, he decrypts it with public key & then checks the blockchain to determine if I can afford the transaction. But since I use different address for every transaction, how is that possible? I don't see way to connect current transaction to all that came before.

Sushi271

Posted 2016-03-09T18:18:56.993

Reputation: 113

Answers

1

So (as I understand) when I want to buy something I send my address encrypted with private key to recipient, he decrypts it with public key & then checks the blockchain to determine if I can afford the transaction

Not quite the way it works. You just send the address, which is essentially the public key, to the person who is trying to do the paying. Given the address (more technically, references to times that address has been paid to on the blockchain before), anyone (not just the payee/payer) can verify that the transaction has the funds to spend.

And rather than sending the private key to show that you are the owner of the coins, you send a Digital Signature, which you need the private key to generate.

Your wallet reports your balance by looking at the list of times that you have been paid to before, which you have also not spent. This will be across many addresses. The network doesn't know which payments on the blockchain are yours, you have to reference a few of them when you want to spend funds, and prove you own the key to them with a digital signature.

morsecoder

Posted 2016-03-09T18:18:56.993

Reputation: 12 624

Check out the original paper, it explains how the whole referencing-previous-payments-to-pay works.

morsecoder 2016-03-09T18:33:32.870

1Indeed. To clarify further: there is no encryption involved anywhere, and it's the receiver that uses a new key for every requested transaction (not the sender, except for his own change).Pieter Wuille 2016-03-09T18:35:43.280

1@PieterWuille btw, thanks for spending time answering Qs on B.SE, I've learned a lot from you, as I'm sure many others have, it's nice to have a core dev so involved.morsecoder 2016-03-09T18:38:54.400

@StephenM347 Reading your answer I was confused at first. I was asking about situation, when I am the buyer, but your answer assumes, that I'm the seller. But now it makes sense: as buyer I don't need to send address to anyone - instead I need to receive address to which I need to pay - right? And so the address needs change after receiving bitcoins, not after sending them (as PieterWuille said). Still, blockchain needs to be checked by receiver to verify my funds. Why do I have to reference few of my payments, instead of all of them? (Trying to read paper too but, its though...)Sushi271 2016-03-09T19:44:19.673

@StephenM347 w8 I think I just got an epiphany. Is it that every receiving address has its own balance? As in: by analyzing blockchain information about payment made to that address and then all payments made from that address I can determine how much money this address contains? And when I buy something, if it's not enough, wallet software sends more addresses, so that in total they contain enough money to cover the expense?Sushi271 2016-03-09T20:07:12.733

@Sushi271, yeah, sorry that I mixed up buyer and seller vantage point, seems like you worked through it though. Address balances isn't exactly how it works under the hood, but that's a good mental model, and the mental model for how most people think about addresses. If you want to go a layer deeper, each time you pay to an address it creates whats called a UTXO (unspent transaction output). There might be many UTXOs per address, or if an address hasn't been used yet there won't be any. Blockchain clients actually keep track of UTXOs not addresses, and to send coins you references UTXOs.morsecoder 2016-03-09T20:22:03.560