Bitcoin is a blockchain, and its chain has an original, the Genesis block. The whole chain depends on that block.
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):
The structure is the following:
- 01000000: version
- 0000000000000000000000000000000000000000000000000000000000000000: previous block hash
- 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a: merkle root
- 29ab5f49: timestamp
- ffff001d: difficulty
- 1dac2b7c: nonce
- 01: num of transactions
- – transaction 1
- 01000000: version
- 01: num of inputs
- 0000000000000000000000000000000000000000000000000000000000000000: tx hash from the output
- ffffffff: tx output number
- 4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73: input script: contains the genesis’ sentence
- ffffffff: sequence
- 01: num of outputs
- 00f2052a01000000: value
- 434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f1deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac: output script
- 00000000 locktime
- – end of transaction 1
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!