What is mining in blockchain?

Understand the consensus of blockchains and how blocks are linked together using proof of work

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

  • |

Lesson Transcript

  • [00:00 - 00:12] Okay, so in this lesson we're going to look at a little bit more about the blockchain structure and how the blocks are linked. So first of all we have the green block which is called the Genesis block.

  • [00:13 - 00:22] It's the first block that is created and every block after that has to reference this. So it is an ancestor of all blocks.

  • [00:23 - 00:30] So it's the first block that ever gets created. It's been there in Bitcoin and Ethereum and every other blockchain.

  • [00:31 - 00:46] The Genesis block is where you know which chain you're pointing to. So when you have the Genesis block that's where the blockchain begins and then you can move to the, you can start mining blocks after that.

  • [00:47 - 01:02] In the Genesis block you can define any arbitrary amount. So if I was to create any blockchain today and I could assign and address any amount that I would like and that's perfectly fine.

  • [01:03 - 01:17] So anyone who joins this chain after that agrees to the rules that are set within the Genesis block. And if they don't follow the rules then their blocks and transactions will not be accepted.

  • [01:18 - 01:47] So after the Genesis block more blocks can be created and as you can see the block block gets created and after that there's basically two miners or two miners who create the same block but they do it at the same time. So how do we decide at this point in time which block is the one that we're going to accept?

  • [01:48 - 02:22] Well this is the case that we don't actually accept this and what happens is that the miners then start another race and say if I can create the next block and point it to my block rather than the other one then I can get the reward for both. But if no one follows this block and it's just abandoned it's called an often block because the main chain is the one is the longest chain or is the chain with the most proof of work.

  • [02:23 - 02:43] So if it happens to be the case that do miners created the same block at the same time then the main chain is the chain with the most proof of work. At this point in time when there is two blocks the proof of work is the same.

  • [02:44 - 03:09] So what happens is that you'd have to go the miners actually start another race and they say they are going to now create the next block and if whoever means that race will then go further. And you can see this happening again at this point in time where the black one and the purple one again gets created at the same time well that's fine.

  • [03:10 - 03:48] But this is what we call a fork but it's only a fork if there's quite a few blocks after that and people actually follow it and it remains alive but most of these forks which are abandoned or often blocks eventually die out. So in this case you can see that when the purple block gets created again after two blocks the black block gets followed the most and it has the most proof of work and then it further divides up.

  • [03:49 - 04:14] Because Bitcoin blocks are 10 minutes every block that's why these can actually happen quite a lot that quite a few miners create a block at the same time. They may not have necessarily the same transactions but then one of them will be orphaned and the other will carry on.

  • [04:15 - 04:36] However in Ethereum there is this concept of uncle blocks and uncle blocks actually mean that instead of throwing them away they actually accept them but they pay a lower reward. So miners when they mine they get a reward and that's what we're going to talk about in the next lesson.

Okay, so in this lesson we're going to look at a little bit more about the blockchain structure and how the blocks are linked. So first of all we have the green block which is called the Genesis block. It's the first block that is created and every block after that has to reference this. So it is an ancestor of all blocks. So it's the first block that ever gets created. It's been there in Bitcoin and Ethereum and every other blockchain. The Genesis block is where you know which chain you're pointing to. So when you have the Genesis block that's where the blockchain begins and then you can move to the, you can start mining blocks after that. In the Genesis block you can define any arbitrary amount. So if I was to create any blockchain today and I could assign and address any amount that I would like and that's perfectly fine. So anyone who joins this chain after that agrees to the rules that are set within the Genesis block. And if they don't follow the rules then their blocks and transactions will not be accepted. So after the Genesis block more blocks can be created and as you can see the block block gets created and after that there's basically two miners or two miners who create the same block but they do it at the same time. So how do we decide at this point in time which block is the one that we're going to accept? Well this is the case that we don't actually accept this and what happens is that the miners then start another race and say if I can create the next block and point it to my block rather than the other one then I can get the reward for both. But if no one follows this block and it's just abandoned it's called an often block because the main chain is the one is the longest chain or is the chain with the most proof of work. So if it happens to be the case that do miners created the same block at the same time then the main chain is the chain with the most proof of work. At this point in time when there is two blocks the proof of work is the same. So what happens is that you'd have to go the miners actually start another race and they say they are going to now create the next block and if whoever means that race will then go further. And you can see this happening again at this point in time where the black one and the purple one again gets created at the same time well that's fine. But this is what we call a fork but it's only a fork if there's quite a few blocks after that and people actually follow it and it remains alive but most of these forks which are abandoned or often blocks eventually die out. So in this case you can see that when the purple block gets created again after two blocks the black block gets followed the most and it has the most proof of work and then it further divides up. Because Bitcoin blocks are 10 minutes every block that's why these can actually happen quite a lot that quite a few miners create a block at the same time. They may not have necessarily the same transactions but then one of them will be orphaned and the other will carry on. However in Ethereum there is this concept of uncle blocks and uncle blocks actually mean that instead of throwing them away they actually accept them but they pay a lower reward. So miners when they mine they get a reward and that's what we're going to talk about in the next lesson.