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?

  • I met same problem. Have you solved? How?
    – creator
    Feb 22 '18 at 5:30

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

  • To check that it has a valid proof of work, use the CheckProofOfWork() function I think this is what I was missing. Cheers!
    – soupdiver
    Feb 6 '18 at 16:20
  • @soupdiver Please write all the code you used. I am also stuck at this stage for days...
    – creator
    Feb 17 '18 at 14:08
  • @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
    Feb 18 '18 at 15:51
  • @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
    Feb 19 '18 at 21:20
  • @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
    Feb 21 '18 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.