<p>The blockchain does not see wallets at all.  It only sees spent and unspent transaction outputs (txouts).  A txout is either completely spent or completely unspent - it cannot be "partially" spent and so there is no notion of balance.  (If you want to spend less than the full value of a transaction, you create a <a href="https://bitcoin.stackexchange.com/questions/736/how-does-change-work-in-a-bitcoin-transaction">change</a> output.)</p>

<p>In your example, there are now two txouts that B can spend.  The "private key" B would actually be a master private key - each "derived" key is really a keypair consisting of a private key B.1.priv and a public key B.1.pub.  So in order to spend the txout that was paid to B.1, user B must sign a transaction using the private key B.1.priv.  If B wants to spend the entire 1 BTC, she can create a transaction with two inputs and signed by both B.1.priv and B.2.priv.</p>

<p>It is true that nobody except B (and maybe A) knows that both txouts are spendable by the same person.  That is fine - they don't need to know.  This is considered a desirable privacy feature.</p>

<p>If B should lose B.1.pub, no problem - it can be regenerated from B.1.priv. This is part of how ECDSA works.   If she should lose B.1.priv, it can be regenerated from the master private key B.  If she loses the master private key, she is out of luck and cannot spend her coins.</p>

CC BY-SA 4.0
2019-10-22T01:32:36.977Z
wait but suppose I have my 12 word backup and I loose everything and re import my master private key from the words, how would I determine which private keys B.1.priv and B.2.priv?
noone392
CC BY-SA 4.0
2019-10-22T02:30:37.220Z
@noone392 the wallet will derive keypairs from the master key, and then check to see if there are any valid UTXOs that are spendable by a key the wallet controls.
chytrik
CC BY-SA 4.0
2019-10-22T02:40:50.320Z
@chytrik so you saying there is some policy to derive keys sequentially in a repeatable way, then you generate the first say 100 keys and perform a verification on all 18 million BTC?! So validating the spendable amount requires probably 1.8 billion asymmetric operations?
noone392
CC BY-SA 4.0
2019-10-22T02:49:20.747Z
No, that would be a very inefficient way to do it. For details of the key derivation see BIP32/39/44/84, eg: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki. For the balance check, it will depend on what type of wallet you are using, there are several different ways it might be done (full node vs SPV, etc). But in general, the network does not keep track of individual coins, it keeps track of 'UTXOs', so the wallet just needs to filter the current UTXO set for any entries that are spendable by one of it's keys. See BIP 37/157/158 for more info.
chytrik
CC BY-SA 4.0
2019-10-22T15:19:02.883Z
Thank you @chytrik. I will spend some time reading this. So then in a transaction the sender must provide all derived public keys in the transaction to account for the funds? So suppose there is 3 derived keys each with 0.5 BTC. If you want to send 0.75 you would need to both sign the transaction, but also provide at least 2 of your public keys so the chain can validate the funds?
noone392
CC BY-SA 4.0
2019-10-22T16:20:51.780Z
A signature actually includes the public key corresponding to the private key that is used to sign.  So yes, if you want to send 0.75 BTC, you will need at least two inputs, each signed by the corresponding (derived) private key and including the corresponding (derived) public key.
Nate Eldredge
CC BY-SA 4.0
2019-10-22T17:17:03.407Z
@NateEldredge I see thank you! So then the sender would have to pay gas tax twice in the above example? Sense it requires 2 of the three derived key pairs to cover the funds and both have to provide their signatures?
noone392
CC BY-SA 4.0
2019-10-22T01:23:04.680Z
2019-10-22T01:23:04.680Z
Nate Eldredge
<p>I have ready about 10 posts that are similar and none of them seem to answer my question so any help is appreciated. </p>

<p>My question is how to miners technically determine if a "wallets" has the "balance" to complete the transaction. Before you say this is a duplicate let me elaborate:</p>

<p>User A has private key A and Public key A.1 and A.2
User B has private key B and Public key B.1 and B.2</p>

<p>Transaction 1 A-> B.1 by User B sending B.1 to A and A signs the transaction (0.5 BTC for illustration) with that private Key.
Transaction 2 A-> B.2  by user B sending B.2 to A and A signs the transaction (0.5 BTC) with that same private key.</p>

<p>Now private Key B has 1 BTC. But sense No one knows that B.1 a and B.2 belong to B because those are derived dynamically from B how can you know how much A has? Further suppose you loose track of you public keys, so B.1 and B.2 have been forgotten. How are you able to figure out the bitcoins that B has access to?</p>

CC BY-SA 4.0
2019-10-22T15:07:18.903Z
Related: https://bitcoin.stackexchange.com/a/91152/5406
Murch
<blockchain><wallet><address><balance>
How do miners determine if a wallet has sufficient funds
noone392
# How do miners determine if a wallet has sufficient funds

(Asked by: username_0 on 2019-10-22)

I have ready about 10 posts that are similar and none of them seem to answer my question so any help is appreciated.

My question is how to miners technically determine if a "wallets" has the "balance" to complete the transaction. Before you say this is a duplicate let me elaborate:

User A has private key A and Public key A.1 and A.2
User B has private key B and Public key B.1 and B.2

Transaction 1 A-> B.1 by User B sending B.1 to A and A signs the transaction (0.5 BTC for illustration) with that private Key.
Transaction 2 A-> B.2 by user B sending B.2 to A and A signs the transaction (0.5 BTC) with that same private key.

Now private Key B has 1 BTC. But sense No one knows that B.1 a and B.2 belong to B because those are derived dynamically from B how can you know how much A has? Further suppose you loose track of you public keys, so B.1 and B.2 have been forgotten. How are you able to figure out the bitcoins that B has access to?

**Tags:** blockchain, wallet, address, balance

> **Comments:**
> **username_1**: Related: https://bitcoin.stackexchange.com/a/91152/5406  

---

## 1 answers

### Answer by username_2 on 2019-10-22. Score: 6

The blockchain does not see wallets at all. It only sees spent and unspent transaction outputs (txouts). A txout is either completely spent or completely unspent - it cannot be "partially" spent and so there is no notion of balance. (If you want to spend less than the full value of a transaction, you create a [change](https://bitcoin.stackexchange.com/questions/736/how-does-change-work-in-a-bitcoin-transaction) output.)

In your example, there are now two txouts that B can spend. The "private key" B would actually be a master private key - each "derived" key is really a keypair consisting of a private key B.1.priv and a public key B.1.pub. So in order to spend the txout that was paid to B.1, user B must sign a transaction using the private key B.1.priv. If B wants to spend the entire 1 BTC, she can create a transaction with two inputs and signed by both B.1.priv and B.2.priv.

It is true that nobody except B (and maybe A) knows that both txouts are spendable by the same person. That is fine - they don't need to know. This is considered a desirable privacy feature.

If B should lose B.1.pub, no problem - it can be regenerated from B.1.priv. This is part of how ECDSA works. If she should lose B.1.priv, it can be regenerated from the master private key B. If she loses the master private key, she is out of luck and cannot spend her coins.

> **Comments:**
> **username_0**: wait but suppose I have my 12 word backup and I loose everything and re import my master private key from the words, how would I determine which private keys B.1.priv and B.2.priv?  
> **username_3**: @username_0 the wallet will derive keypairs from the master key, and then check to see if there are any valid UTXOs that are spendable by a key the wallet controls.  
> **username_0**: @username_3 so you saying there is some policy to derive keys sequentially in a repeatable way, then you generate the first say 100 keys and perform a verification on all 18 million BTC?! So validating the spendable amount requires probably 1.8 billion asymmetric operations?  
> **username_3**: No, that would be a very inefficient way to do it. For details of the key derivation see BIP32/39/44/84, eg: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki. For the balance check, it will depend on what type of wallet you are using, there are several different ways it might be done (full node vs SPV, etc). But in general, the network does not keep track of individual coins, it keeps track of 'UTXOs', so the wallet just needs to filter the current UTXO set for any entries that are spendable by one of it's keys. See BIP 37/157/158 for more info.  
> **username_0**: Thank you @username_3. I will spend some time reading this. So then in a transaction the sender must provide all derived public keys in the transaction to account for the funds? So suppose there is 3 derived keys each with 0.5 BTC. If you want to send 0.75 you would need to both sign the transaction, but also provide at least 2 of your public keys so the chain can validate the funds?  
> **username_2**: A signature actually includes the public key corresponding to the private key that is used to sign.  So yes, if you want to send 0.75 BTC, you will need at least two inputs, each signed by the corresponding (derived) private key and including the corresponding (derived) public key.  
> **username_0**: @username_2 I see thank you! So then the sender would have to pay gas tax twice in the above example? Sense it requires 2 of the three derived key pairs to cover the funds and both have to provide their signatures?  

---

