<p>In fact, all these functions are implemented in the original Bitcoin client. Mining pools do only distribute it to contributors and sometimes slightly change the problem like Stratum does, but that's not very relevant.</p>

<p>Like I say, the original Bitcoin client performs the first and the last functions, but I'll explain what they imply.</p>

<ol>
<li><p><em>WHO gives the current hash to work on?</em></p>

<p>The data to work on is the header of the current block. You can build this block yourself, but the client also does it for you. Some important <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow">pieces of information</a> in this header (that will be hashed so that they are confirmed by the hash) are the hash of the previous block, the merkle root of all transactions in the block (this is used to check if a transaction has been included in the block) and nonce.</p>

<p>So basically what you do is hash this header and check if the hash complies with the current <a href="https://en.bitcoin.it/wiki/Target" rel="nofollow">target</a>. If not, you can change the nonce and try again. When a new transaction comes in, you add it, update the merkle root and continue. When a new block comes in, you update the previous block hash, remove transactions in the new block from yours, update the merkle root and continue.</p></li>
<li><p><em>The Computation</em></p>

<p>As <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow">explained</a> on the Bitcoin wiki, a double SHA-256 hash is used to hash the complete block header.</p>

<p><code>SHA256( SHA256( Block_Header ) )</code></p></li>
<li><p><em>How can I submit my result?</em></p>

<p>The original <a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list" rel="nofollow">Bitcoin API</a> has a method called <code>submitblock</code> that you should use to submit the block to the network. Note that you will have to create the block yourself in binary format, containing all the transactions in it.</p></li>
</ol>

<p>As for</p>

<blockquote>
  <p>I want to be SOLO, not mining solo</p>
</blockquote>

<p>those things are exactly the same. Mining solo means that you do not rely on a mining pool. You can easily start with solo mining using many of the existing mining programs or simply by only using the original client.</p>

<p>Note that it is almost always required to have the Bitcoin client running and and being up to date in order to mine solo.</p>

CC BY-SA 3.0
2013-05-28T23:42:10.737Z
2013-05-28T23:42:10.737Z
Steven Roose
<p>I think you have the (common) misconception that everyone is working on the same block.  That is not true.  There is no "official" block to work on.  All miners just gather a bunch of transactions that are valid and haven't already been included in previous blocks.  Usually even as you are mining a block you are adding more transactions to it.  This does not make finding the nonce any harder.  It is pretty much a random shot every time you increment it, even if the content you are hashing keeps changing.</p>

<p>When you (the miner) solve the nonce, you publish the block on the P2P network and all the other miners and clients pick it up, abandon the block they were working on and start with a new block that links to the one you just published.</p>

CC BY-SA 3.0
2013-05-29T00:56:05.763Z
2013-05-29T00:56:05.763Z
RentFree
<p>I am currently looking on how does Bitcoin work, and I would like to sum things up with your help. The point is, if I ever want to write my own mining agent, what do I have to understand in order to do so ?</p>

<p>First Point: The Data</p>

<p>Through my research, I didn't really understand WHO gives the current hash to work on. I know that it is working as a P2P network, and I think, but not sure, that all clients connected to the network are aware of the transactions.</p>

<p>But what should I do if I want to have access to the latest OFFICIAL (might not be the best word) block, without being in a mining pool ?</p>

<p>Second Point: The Computation</p>

<p>If I undestood this part, I have to try every nonce until sha256(sha256(data + nonce)) meets the requirements from Bitcoin.</p>

<p>Third part, submitting the answer</p>

<p>Assuming I found the right nonce, how can I submit my result. But I didn't find how I can do that.</p>

<p>I want to make this point clear, I want to be SOLO, not mining solo, but if I wanted to write my own mining program, how could I do that WITHOUT being in a mining pool and finding information all by myself.</p>

<p>Thanks for your answers.</p>

CC BY-SA 3.0
2013-05-28T16:54:51.177Z
`I ever want to write my own mining agent` Do you mean a mining program that connects to the standard client and does a getwork request, or a complete replacement of the standard client?
Nick ODell
CC BY-SA 3.0
2013-05-29T07:59:05.297Z
The idea was, if I wanted to start from scratch, what do I have to know ?
Shitrozore
CC BY-SA 3.0
2013-05-29T16:00:26.027Z
Start with the original [bitcoin paper](http://bitcoin.org/bitcoin.pdf), then read the [hashcash paper](http://www.hashcash.org/papers/hashcash.pdf), then [Hal Finney's RPOW explanation](http://classic-web.archive.org/web/20080229154639/http://rpow.net/theory.html). Do you want to make something Bitcoin-like, or something compatible with 
Bitcoin?
Nick ODell
<blockchain><mining-software>
Technical Review of Bitcoin
Shitrozore
# Technical Review of Bitcoin

(Asked by: username_0 on 2013-05-28)

I am currently looking on how does Bitcoin work, and I would like to sum things up with your help. The point is, if I ever want to write my own mining agent, what do I have to understand in order to do so ?

First Point: The Data

Through my research, I didn't really understand WHO gives the current hash to work on. I know that it is working as a P2P network, and I think, but not sure, that all clients connected to the network are aware of the transactions.

But what should I do if I want to have access to the latest OFFICIAL (might not be the best word) block, without being in a mining pool ?

Second Point: The Computation

If I undestood this part, I have to try every nonce until sha256(sha256(data + nonce)) meets the requirements from Bitcoin.

Third part, submitting the answer

Assuming I found the right nonce, how can I submit my result. But I didn't find how I can do that.

I want to make this point clear, I want to be SOLO, not mining solo, but if I wanted to write my own mining program, how could I do that WITHOUT being in a mining pool and finding information all by myself.

Thanks for your answers.

**Tags:** blockchain, mining-software

> **Comments:**
> **username_1**: `I ever want to write my own mining agent` Do you mean a mining program that connects to the standard client and does a getwork request, or a complete replacement of the standard client?  
> **username_0**: The idea was, if I wanted to start from scratch, what do I have to know ?  
> **username_1**: Start with the original [bitcoin paper](http://bitcoin.org/bitcoin.pdf), then read the [hashcash paper](http://www.hashcash.org/papers/hashcash.pdf), then [Hal Finney's RPOW explanation](http://classic-web.archive.org/web/20080229154639/http://rpow.net/theory.html). Do you want to make something Bitcoin-like, or something compatible with  Bitcoin?  

---

## 2 answers

### Answer by username_2 on 2013-05-28. Score: 1

In fact, all these functions are implemented in the original Bitcoin client. Mining pools do only distribute it to contributors and sometimes slightly change the problem like Stratum does, but that's not very relevant.

Like I say, the original Bitcoin client performs the first and the last functions, but I'll explain what they imply.

1. *WHO gives the current hash to work on?*

   The data to work on is the header of the current block. You can build this block yourself, but the client also does it for you. Some important [pieces of information](https://en.bitcoin.it/wiki/Block_hashing_algorithm) in this header (that will be hashed so that they are confirmed by the hash) are the hash of the previous block, the merkle root of all transactions in the block (this is used to check if a transaction has been included in the block) and nonce.

   So basically what you do is hash this header and check if the hash complies with the current [target](https://en.bitcoin.it/wiki/Target). If not, you can change the nonce and try again. When a new transaction comes in, you add it, update the merkle root and continue. When a new block comes in, you update the previous block hash, remove transactions in the new block from yours, update the merkle root and continue.
2. *The Computation*

   As [explained](https://en.bitcoin.it/wiki/Block_hashing_algorithm) on the Bitcoin wiki, a double SHA-256 hash is used to hash the complete block header.

   `SHA256( SHA256( Block_Header ) )`
3. *How can I submit my result?*

   The original [Bitcoin API](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) has a method called `submitblock` that you should use to submit the block to the network. Note that you will have to create the block yourself in binary format, containing all the transactions in it.

As for

> I want to be SOLO, not mining solo

those things are exactly the same. Mining solo means that you do not rely on a mining pool. You can easily start with solo mining using many of the existing mining programs or simply by only using the original client.

Note that it is almost always required to have the Bitcoin client running and and being up to date in order to mine solo.


---

### Answer by username_3 on 2013-05-29. Score: 0

I think you have the (common) misconception that everyone is working on the same block. That is not true. There is no "official" block to work on. All miners just gather a bunch of transactions that are valid and haven't already been included in previous blocks. Usually even as you are mining a block you are adding more transactions to it. This does not make finding the nonce any harder. It is pretty much a random shot every time you increment it, even if the content you are hashing keeps changing.

When you (the miner) solve the nonce, you publish the block on the P2P network and all the other miners and clients pick it up, abandon the block they were working on and start with a new block that links to the one you just published.


---

