Creating Blockchain with Python #6 – Mining

Creating Blockchain with Python #6
Mining

today we will learn about the mining process in blockchain 😉

steps:
1. watch previous video
Creating Blockchain with Python #1 – Create a Chain with List
https://youtu.be/3QRwQ4VLdvw

Creating Blockchain with Python #2 – Adding New Transaction
https://youtu.be/cwPaN2N6nYo

Creating Blockchain with Python #3 – Genesis Block
https://youtu.be/IbnO2QLouY8

Creating Blockchain with Python #4 – Hash Function
https://youtu.be/78M86NFy-2s

Creating Blockchain with Python #5 – Validating Proof
https://pin.it/6DNctUu

2. download the code here
https://github.com/cryptocodecg/blockchain-cg/commit/e436abe506bcfc7ec0ceff8a9ab84a88d7e4f30c

how Proof Of Work Protocol works:
* the miners solve cryptographic puzzles to “mine” a block in order to add to the blockchain
* this process requires immense amount of energy and computational usage. the puzzles have been designed in a way which makes it hard and taxing on the system (the puzzle in this case is to find a hash with “00” in the beginning)
* when a miner solves the puzzle, they present their block to the network for verification
* verifying whether the block belongs to the chain or not is an extremely simple process

Update

Steve Rich's Exciting New Book: A Journey into the World of Forex Trading!

Interview

the mining process:
* extract the last block of the blockchain and put it in last_block
* hash the last block
* use the pow() function to extract the nonce
* create a reward_transaction which awards the miner, i.e., us with the reward amount which we have set earlier (10.0 coins)
* the reward_transaction gets appended to the open_transaction list
* finally, with the new approved nonce, we finally have a new block, which helps us get the metadata of the new block,
* the new block is added to the blockchain

3. now let’s see the code
4. run the code! 🙂
5. notice that there is a new transaction has been added and the miner has got his reward 🙂
6. let’s try again

ok now you have your own blockchain system 😉 you can modify it to be more complex and realistic 🙂

next tutorial will be about verifying chain, don’t miss it 🙂

please click subscribe, like and share and leave some comments 🙂

thanks for watching 🙂

references:
https://blockgeeks.com/guides/python-blockchain-2/