<blockquote>
  <p>How does a wallet know how much Bitcoins belongs to a specific address?</p>
</blockquote>

<p>A wallet is a private key which generates public keys. You can look those up in the blockchain to see if any of them have an open balance. </p>

<blockquote>
  <p>In which block will the transaction for creating a block hash listed?</p>
</blockquote>

<p>The first transaction in a block is generated by miners themselves, crediting themselves with the coinbase reward. then, the miner adds further transactions and starts looking for a hash that has the right difficulty target. If the miner finds one, the miner publishes the block. Miners thus credits themselves within their own block.</p>

<blockquote>
  <p>Who hashes the merkle root?</p>
</blockquote>

<p>The act of mining is finding a suitable hash for the merkle root and the block header.</p>

<blockquote>
  <p>How do miners know that there is a new block?</p>
</blockquote>

<p>The difficulty is updated every 2016 blocks. Because each block is timestamped, the difficulty adjustment knows how much time has passed, and can raise the difficulty in such a way that the next 2016 blocks will all take approximately 10min to find. Note that this assumes a steady hash rate.</p>

<blockquote>
  <p>Is the difficulty only regulated by the leading zeroes in a hash?</p>
</blockquote>

<p>Yup.</p>

<blockquote>
  <p>What if no nounce is found for a block?</p>
</blockquote>

<p>If so, you swap two transactions in the merkle tree that are unrelated. You can look for a new nonce for the corresponding tree. </p>

CC BY-SA 3.0
2017-12-13T09:29:21.563Z
Thanks for your answer.
But what's the best way to look up the public address in the blockchain? Parsing the complete blockchain would take too long.
SO1992
CC BY-SA 3.0
2017-12-13T10:11:32.987Z
if you want to do it manually, have a look at blockchain.info. The bitcoin core wallet does this while receiving tx from other nodes. So there is no manual intervention required...
pebwindkraft
CC BY-SA 3.0
2017-12-13T11:17:02.813Z
Let's say I would have 100 Bitcoins and I'm going to download a mobile wallet from the AppStore. How exactly does the wallet get it's current balance? Or can a address ever only be accessed by the same wallet? So moving to a new wallet app wouldn't make any sense?
SO1992
CC BY-SA 3.0
2017-12-13T15:01:49.760Z
The hot wallet will probably not download the whole chain itself, but will just ask a server what the balance is for a bitcoin address.
BlackBeltBob
CC BY-SA 3.0
2017-12-13T15:15:44.397Z
So the server has to parse the complete blockchain? I'm sorry, but I don't understand how to access the blockchain the fastest way...
SO1992
CC BY-SA 3.0
2017-12-13T15:27:39.950Z
To be able to check the balance of a bitcoin address, at the very least somebody needs to parse the entire blockchain. Once that is done, you can ask that entity (preferably you yourself, or someone you trust) if an address currently has a balance.
BlackBeltBob
CC BY-SA 3.0
2017-12-13T09:06:37.283Z
2017-12-13T09:06:37.283Z
BlackBeltBob
<p>At the moment I'm trying to get a look inside Bitcoin and the Blockchain, but I'm having some general unanswered questions.</p>

<ol>
<li>How does a wallet know how much Bitcoins belongs to a specific address?</li>
</ol>

<p>I guess there are many possible ways to do that like parsing the complete blockchain and look for some transaction the address made and just sum up the transaction amounts. But that seems to be like the worst possible method. Is there another way to access the blockchain, for example like SQL for relational databases?</p>

<ol start="2">
<li>In which block will the transaction for creating a block hash listed?</li>
</ol>

<p>When you find a correct hash of a block you'll receive Bitcoins. But the transaction will be listed in the following block, correct? If the transaction would be listed in the block for which the miner found the hash, the hash would be instantly incorrect after adding this transaction to the block?!</p>

<ol start="3">
<li>Who hashes the merkle root?</li>
</ol>

<p>I already know that the merkle tree is "final" hash from all pairwise hashed transactions. But who hashes all the transactions? Is that also part of the miners themselves?
If so, the miners have to hash all transactions and afterwards find the correct nonce?</p>

<ol start="4">
<li>How do miners know that there is a new block?</li>
</ol>

<p>I know that news blocks are generated every 10 minutes. Is this regulated by time? Let's say the last blocks hash was found at 9:30 and it's now 9:40, would the miner just look in the blockchain and get all transactions from 9:30 to 9:40 and that's the block that needs to be hashed?</p>

<ol start="5">
<li>Is the difficulty only regulated by the leading zeroes in a hash?</li>
</ol>

<p>When finding the correct hash it seems like getting the correct amount of leading zeroes is elementary. But is this the only way to regulate the difficulty?</p>

<ol start="6">
<li>What if no nounce is found for a block?</li>
</ol>

<p>Is it possible that the network can't find a nonce to generate the needed hash? </p>

<p>Thank you very much</p>

CC BY-SA 3.0
2017-12-13T08:57:45.903Z
Most of your questions are easily answered by looking them up in "Mastering Bitcoin" by Andreas Antonopoulos. Freely available at bitcoinbook.info.
BlackBeltBob
<wallet><hash><difficulty><merkle-tree>
General Bitcoin questions
SO1992
# General Bitcoin questions

(Asked by: username_0 on 2017-12-13)

At the moment I'm trying to get a look inside Bitcoin and the Blockchain, but I'm having some general unanswered questions.

1. How does a wallet know how much Bitcoins belongs to a specific address?

I guess there are many possible ways to do that like parsing the complete blockchain and look for some transaction the address made and just sum up the transaction amounts. But that seems to be like the worst possible method. Is there another way to access the blockchain, for example like SQL for relational databases?

2. In which block will the transaction for creating a block hash listed?

When you find a correct hash of a block you'll receive Bitcoins. But the transaction will be listed in the following block, correct? If the transaction would be listed in the block for which the miner found the hash, the hash would be instantly incorrect after adding this transaction to the block?!

3. Who hashes the merkle root?

I already know that the merkle tree is "final" hash from all pairwise hashed transactions. But who hashes all the transactions? Is that also part of the miners themselves?
If so, the miners have to hash all transactions and afterwards find the correct nonce?

4. How do miners know that there is a new block?

I know that news blocks are generated every 10 minutes. Is this regulated by time? Let's say the last blocks hash was found at 9:30 and it's now 9:40, would the miner just look in the blockchain and get all transactions from 9:30 to 9:40 and that's the block that needs to be hashed?

5. Is the difficulty only regulated by the leading zeroes in a hash?

When finding the correct hash it seems like getting the correct amount of leading zeroes is elementary. But is this the only way to regulate the difficulty?

6. What if no nounce is found for a block?

Is it possible that the network can't find a nonce to generate the needed hash?

Thank you very much

**Tags:** wallet, hash, difficulty, merkle-tree

> **Comments:**
> **username_1**: Most of your questions are easily answered by looking them up in "Mastering Bitcoin" by Andreas Antonopoulos. Freely available at bitcoinbook.info.  

---

## 1 answers

### Answer by username_1 on 2017-12-13. Score: 1

> How does a wallet know how much Bitcoins belongs to a specific address?

A wallet is a private key which generates public keys. You can look those up in the blockchain to see if any of them have an open balance.

> In which block will the transaction for creating a block hash listed?

The first transaction in a block is generated by miners themselves, crediting themselves with the coinbase reward. then, the miner adds further transactions and starts looking for a hash that has the right difficulty target. If the miner finds one, the miner publishes the block. Miners thus credits themselves within their own block.

> Who hashes the merkle root?

The act of mining is finding a suitable hash for the merkle root and the block header.

> How do miners know that there is a new block?

The difficulty is updated every 2016 blocks. Because each block is timestamped, the difficulty adjustment knows how much time has passed, and can raise the difficulty in such a way that the next 2016 blocks will all take approximately 10min to find. Note that this assumes a steady hash rate.

> Is the difficulty only regulated by the leading zeroes in a hash?

Yup.

> What if no nounce is found for a block?

If so, you swap two transactions in the merkle tree that are unrelated. You can look for a new nonce for the corresponding tree.

> **Comments:**
> **username_0**: Thanks for your answer. But what's the best way to look up the public address in the blockchain? Parsing the complete blockchain would take too long.  
> **username_2**: if you want to do it manually, have a look at blockchain.info. The bitcoin core wallet does this while receiving tx from other nodes. So there is no manual intervention required...  
> **username_0**: Let's say I would have 100 Bitcoins and I'm going to download a mobile wallet from the AppStore. How exactly does the wallet get it's current balance? Or can a address ever only be accessed by the same wallet? So moving to a new wallet app wouldn't make any sense?  
> **username_1**: The hot wallet will probably not download the whole chain itself, but will just ask a server what the balance is for a bitcoin address.  
> **username_0**: So the server has to parse the complete blockchain? I'm sorry, but I don't understand how to access the blockchain the fastest way...  
> **username_1**: To be able to check the balance of a bitcoin address, at the very least somebody needs to parse the entire blockchain. Once that is done, you can ask that entity (preferably you yourself, or someone you trust) if an address currently has a balance.  

---

