From the course: Blockchain Programming in iOS Using Swift

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Proof of work

Proof of work

- [Instructor] Okay, so let's now go ahead and see how we can create a proof of work which is going to generate a special kind of a hash that is beginning with, let's start with two zeros. We're gonna go into the generate hash function and we're gonna run a while loop and this loop is gonna run for a very long time until the prefix of the hash it generates begins with two zeros. If it's not two zeros, then we're simply going to increase the nonce by one. And we're gonna give the hash equals two block.key.shahash which is going to give you something different because now the nonce has been increased. Let's go ahead and also print it out. Okay. So there we go. You can actually see that it's trying to find a hash, a unique hash that begins with at least two zeros. And this eventually is able to find it. There we go, right at the end. Zero zero seven three see line b, so on. This is also printed over here. Now as you can see it took few seconds. Now if I was finding a hash that begins…

Contents