General Bitcoin questions

1

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?

  1. 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?!

  1. 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?

  1. 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?

  1. 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?

  1. 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

SO1992

Posted 2017-12-13T08:45:37.890

Reputation: 11

Question was closed 2017-12-14T21:32:20.143

1Most of your questions are easily answered by looking them up in "Mastering Bitcoin" by Andreas Antonopoulos. Freely available at bitcoinbook.info.BlackBeltBob 2017-12-13T08:57:45.903

Answers

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.

BlackBeltBob

Posted 2017-12-13T08:45:37.890

Reputation: 447

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 2017-12-13T09:29:21.563

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 2017-12-13T10:11:32.987

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 2017-12-13T11:17:02.813

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 2017-12-13T15:01:49.760

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 2017-12-13T15:15:44.397

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 2017-12-13T15:27:39.950