Let us assume that the originator of TPCoins initially issues 500 TPCoins to a known client, Dinesh.To do so, he first creates a Dinesh instance : the
Dinesh = Client()
We then create a Genesis transaction and send 500 TPCoins to Dinesh's public address.
t0 = Transaction ( "Genesis", , 500.0 )
Now, we create the instance class of Block and name it ;block0
block0 = Block()
We initialize previous_block_hash and the Nonce instance variable to nothing, since this is the first transaction stored in our blockchain.
block0.previous_block_hash = None Nonce = None
Next, we add the above t0 transaction to the list of verified_transactions reserved in the block :
block0.verified_transactions.append (t0)
At this point, the block is fully initialized and ready to be added to our blockchain. We will create a blockchain for this purpose. Before we add the block to the blockchain, we will hash the block and store its value in the global variable we declared earlier called last_block_hash. This value will be used by the next miner in its block.
We use the following two lines of encoding to hash the block and store the summary value.
digest = hash (block0) last_block_hash = digest
Finally, we create a blockchain as we will see in the next chapter.
Above is the detailed content of Python blockchain create Genesis Block tutorial, more information about Python block Genesis Block please pay attention to my other related articles!