How to create a new genesis block using CreateGenesisBlock() function 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&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();


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