<p>The genesis block still must meet the proof of work requirements that other blocks must also meet. So you must actually mine the genesis block. To do this, you need to put CreateGenesisBlock in a <code>while</code> loop and just keep incrementing the nonce, and if necessary, increment an extranonce in the coinbase transaction.</p>

<p>To check that it has a valid proof of work, use the <code>CheckProofOfWork()</code> function (grep for it and you can figure out what arguments it takes).</p>

CC BY-SA 3.0
2018-02-06T16:20:19.217Z
`To check that it has a valid proof of work, use the CheckProofOfWork() function` I think this is what I was missing. Cheers!
soupdiver
CC BY-SA 3.0
2018-02-17T14:08:30.530Z
@soupdiver Please write all the code you used. I am also stuck at this stage for days...
creator
CC BY-SA 3.0
2018-02-18T15:51:57.040Z
@leegod I assume we're working on the same (demo) project as (most?) of the others who came up with that question in the recent months... In the end I found a python, which I had to modify, which "mined" a valid genesis block.
soupdiver
CC BY-SA 3.0
2018-02-19T21:20:07.043Z
@soupdiver I am working on newest litecoin source. To make alt. So what  is that python? You mean GenesisH0? How you modified and what values should I input exactly to use it correctly?
creator
CC BY-SA 3.0
2018-02-21T06:54:46.623Z
@leegod yep it's GenesisH0. I don't know about requirements/specification of the coin you trying to create. So I can't give you exact values.
soupdiver
CC BY-SA 3.0
2018-02-21T07:54:05.337Z
I just want to clone litecoin with some parameters change. And GenesisH0, I can't match right value, what values should I input there I don't know exactly, I tried various things, it just errors. so I give up using GenesisH0, just used printf method, now error says see debug.log file, debug.log says  ReadBlockFromDisk error.
creator
CC BY-SA 3.0
2018-02-22T05:39:30.853Z
and also, if use GenesisH0, it just mine in its script only, isn't it? Then no related with mycoind client? Then how make pre-mine reward to own wallet address? Because using GenesisH0 means no client-side's actual genesis block mining?
creator
CC BY-SA 3.0
2018-02-22T07:30:41.497Z
@Andrew Chow  Hi. Thanks for answering. But I am also stuck at this stage. Can you link or put he exact working code? I can't find anywhere.
creator
CC BY-SA 3.0
2018-02-22T08:02:27.407Z
@Andrew Chow Where that CreateGenesisBlock is? chainparams.cpp's original place? (line 123~5)   

and wrap this up with while loop?

And is this the code you answered?

https://pastebin.com/EC4tVZQZ
creator
CC BY-SA 3.0
2018-02-22T16:09:12.083Z
@leegod I don't have any specific code that I can provide you. I have not written it nor do I plan to. I am not in the business of creating altcoins or helping people make altcoins.
Ava Chow
CC BY-SA 3.0
2018-02-25T12:53:14.673Z
@AndrewChow So I did at chainparams.cpp file like,  
const CChainParams& chainparams = Params();
while(!CheckProofOfWork(genesis.GetHash(), genesis.nBits, chainparams.GetConsensus()) { ++ genesis.nNonce; } 

But this does not even compiled. I added #include "pow.h" at top of chainparams.cpp, but when I try 'make' for compile, terminal error says, 

chainparams.cpp:127 : undefined reference to "CheckProofOfWork(uint256,,,,, )'

How to pass this?... Plz.
creator
CC BY-SA 3.0
2018-02-25T16:11:25.047Z
You will need to modify the Makefile.am file so that the generated Makefile can find pow.h and link it when it compiles validation.cpp.
Ava Chow
CC BY-SA 3.0
2018-02-27T13:22:22.057Z
@AndrewChow So I revised Makefile.am, so now that [undefined] error solved. But now I get new error, says, 

lee@newlite:~/Desktop/BitcoinEssence/src$ ./bitcoinessenced bitcoinessenced: chainparams.cpp:524: const CChainParams& Params(): Assertion `globalChainParams' failed. Aborted (core dumped)

Here is detail. https://bitcointalk.org/index.php?topic=3031897.new#new
creator
CC BY-SA 3.0
2018-02-06T16:09:53.273Z
2018-02-06T16:09:53.273Z
Ava Chow
<p>I'm trying to create a new genesis block, you know for science.
I saw a lot of write ups online but most of them seem kinda outdated.
I found the function <code>CreateGenesisBlock()</code> in the source code.</p>

<pre><code>    genesis = CreateGenesisBlock(1317972665, 1337, 0x1e0ffff0, 1, 100 * COIN);

    std::cout&lt;&lt; genesis.GetHash().ToString().c_str() &lt;&lt; std::endl;
    std::cout&lt;&lt; genesis.hashMerkleRoot.ToString().c_str() &lt;&lt; std::endl;

    consensus.hashGenesisBlock = genesis.GetHash();
</code></pre>

<p>This is my current code. 
When running my <code>coind</code> it fails with <code>ERROR: ReadBlockFromDisk: Errors in block header at CBlockDiskPos(nFile=0, nPos=8)</code></p>

<p>From my current research it seem the genesis block failed the PoW criteria somehow.</p>

<p>I thought about putting the <code>CreateGenesisBlock</code> in a loop to generate blocks until I found a valid one but I'm not sure how to check if the block is valid.
Can someone gimme a tip?</p>

CC BY-SA 3.0
2018-02-22T05:30:49.670Z
I met same problem. Have you solved? How?
creator
<bitcoind><altcoin-development><genesis-block>
How to create a new genesis block using CreateGenesisBlock() function
soupdiver
# How to create a new genesis block using CreateGenesisBlock() function

(Asked by: username_0 on 2018-02-06)

I'm trying to create a new genesis block, you know for science.
I saw a lot of write ups online but most of them seem kinda outdated.
I found the function `CreateGenesisBlock()` in the source code.

```
    genesis = CreateGenesisBlock(1317972665, 1337, 0x1e0ffff0, 1, 100 * COIN);

    std::cout<< genesis.GetHash().ToString().c_str() << std::endl;
    std::cout<< genesis.hashMerkleRoot.ToString().c_str() << std::endl;

    consensus.hashGenesisBlock = genesis.GetHash();

```

This is my current code.
When running my `coind` it fails with `ERROR: ReadBlockFromDisk: Errors in block header at CBlockDiskPos(nFile=0, nPos=8)`

From my current research it seem the genesis block failed the PoW criteria somehow.

I thought about putting the `CreateGenesisBlock` in a loop to generate blocks until I found a valid one but I'm not sure how to check if the block is valid.
Can someone gimme a tip?

**Tags:** bitcoind, altcoin-development, genesis-block

> **Comments:**
> **username_1**: I met same problem. Have you solved? How?  

---

## 1 answers

### Answer by username_2 on 2018-02-06. Score: 4 | Accepted answer

The genesis block still must meet the proof of work requirements that other blocks must also meet. So you must actually mine the genesis block. To do this, you need to put CreateGenesisBlock in a `while` loop and just keep incrementing the nonce, and if necessary, increment an extranonce in the coinbase transaction.

To check that it has a valid proof of work, use the `CheckProofOfWork()` function (grep for it and you can figure out what arguments it takes).

> **Comments:**
> **username_0**: `To check that it has a valid proof of work, use the CheckProofOfWork() function` I think this is what I was missing. Cheers!  
> **username_1**: @username_0 Please write all the code you used. I am also stuck at this stage for days...  
> **username_0**: @leegod I assume we're working on the same (demo) project as (most?) of the others who came up with that question in the recent months... In the end I found a python, which I had to modify, which "mined" a valid genesis block.  
> **username_1**: @username_0 I am working on newest litecoin source. To make alt. So what  is that python? You mean GenesisH0? How you modified and what values should I input exactly to use it correctly?  
> **username_0**: @leegod yep it's GenesisH0. I don't know about requirements/specification of the coin you trying to create. So I can't give you exact values.  
> **username_1**: I just want to clone litecoin with some parameters change. And GenesisH0, I can't match right value, what values should I input there I don't know exactly, I tried various things, it just errors. so I give up using GenesisH0, just used printf method, now error says see debug.log file, debug.log says  ReadBlockFromDisk error.  
> **username_1**: and also, if use GenesisH0, it just mine in its script only, isn't it? Then no related with mycoind client? Then how make pre-mine reward to own wallet address? Because using GenesisH0 means no client-side's actual genesis block mining?  
> **username_1**: @Andrew username_2  Hi. Thanks for answering. But I am also stuck at this stage. Can you link or put he exact working code? I can't find anywhere.  
> **username_1**: @Andrew username_2 Where that CreateGenesisBlock is? chainparams.cpp's original place? (line 123~5)     and wrap this up with while loop?  And is this the code you answered?  https://pastebin.com/EC4tVZQZ  
> **username_2**: @leegod I don't have any specific code that I can provide you. I have not written it nor do I plan to. I am not in the business of creating altcoins or helping people make altcoins.  
> **username_1**: @AndrewChow So I did at chainparams.cpp file like,   const CChainParams& chainparams = Params(); while(!CheckProofOfWork(genesis.GetHash(), genesis.nBits, chainparams.GetConsensus()) { ++ genesis.nNonce; }   But this does not even compiled. I added #include "pow.h" at top of chainparams.cpp, but when I try 'make' for compile, terminal error says,   chainparams.cpp:127 : undefined reference to "CheckProofOfWork(uint256,,,,, )'  How to pass this?... Plz.  
> **username_2**: You will need to modify the Makefile.am file so that the generated Makefile can find pow.h and link it when it compiles validation.cpp.  
> **username_1**: @AndrewChow So I revised Makefile.am, so now that [undefined] error solved. But now I get new error, says,   lee@newlite:~/Desktop/BitcoinEssence/src$ ./bitcoinessenced bitcoinessenced: chainparams.cpp:524: const CChainParams& Params(): Assertion `globalChainParams' failed. Aborted (core dumped)  Here is detail. https://bitcointalk.org/index.php?topic=3031897.new#new  

---

