Bitcoin is a blockchain, and its chain has an original, the Genesis block. The whole chain depends on that block.
The Genesir block is a regular block, and is composed of the same structure than any other block. It has a single transaction with an output that is by design not spendable.
In the Bitcoin blockchain, the Genesis block’s coinbase (input of the generating transaction, not used by the protocol) contains a single sentence, to date the block creation. This sentence is The Times 03/Jan/2009 Chancellor on brink of second bailout for banks. Litecoin’s is NY Times 05/Oct/2011 Steve Jobs, Apple’s Visionary, Dies at 56.
We can easily retrieve the complete block using bitcoin-cli (or json-api rpc):
When you want to create your own chain (and building your own altcoin), you have to regenerate a new genesis block, and a quick way but ugly is to patch your wallet source, then launch it in order to compute (mine) the initial transaction & block, then report it in the source, and recompile the wallet. This can be a difficult step if you don’t know well C++ or how chains work.
There is a few tools to do this, but I wanted to do my own in golang, and the result is a new project called generate-genesis. It is a simple CLI command that takes all needed parameters for a new Genesis block, and will iterate nonce & timestamp until a new valid hash is found.
An interesting part of the code is the block hash validity check, which differs if you are computing a sha256 hash (for bitcoin) or a scrypt hash. There another hashes, but I didn’t studied them yet. We need in this code to compute from the compact bits the target difficulty, then compute the sha256/scrypt/… hash, compare it against the target difficulty, and if the hash (which is considered as a big integer) is smaller than target, we consider the hash is valid. If not, we increment nonce and restart the process.
By default, the Generate Genesis tool will compute & a valid nonce for a new block for the bitcoin chain:
You can change nonce value, to make sure it didn’t cheat, and it will recompute it:
You can also compute the same thing for litecoin:
The source code is available on my private gitlab for registered users.
Update 2018/03/19: generate-genesis now works with the X11 proof of work!