Implementing Proof-of-Work in Javascript (Blockchain, part 2)

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 2024
  • Adding the proof-of-work mechanism to our homemade Javascript blockchain.
    Proof-of-work will secure our blockchain against spammers and people trying to tamper with our blocks.
    ► Source code
    Available on GitHub:
    github.com/Sav...
    💌 Sign up for Simply Explained Newsletter:
    newsletter.sim...
    Monthly newsletter with cool stuff I found on the internet (related to science, technology, biology, and other nerdy things)! No spam. Ever. Promise!
    🌍 Social
    Twitter: / savjee
    Facebook: / savjee
    Blog: savjee.be
    ❤️ Become a Simply Explained member: / @simplyexplained
    #blockchain #javascript #nodejs #coding #simplyexplained

ความคิดเห็น • 328

  • @exo.master
    @exo.master 6 ปีที่แล้ว +134

    It is kinda funny how we, software developers with some knowledge about Object Oriented Programming, can understand the concepts very fast when classes are given in OOP. Between .. dear Savjee, your techniques show excellence on teaching, congratulations!!

    • @jgttech
      @jgttech 6 ปีที่แล้ว +11

      So true. I was just saying to a co-worker of mine that I wish everything was explained in OOP, then I could learn physics and anything at that point lol. OOP is how you communicate to a modern developer lol. So freaking true.

    • @fxstreamer238
      @fxstreamer238 3 ปีที่แล้ว +2

      @@jgttech If you dont understand physics you probably wont understand oop

    • @_jko
      @_jko 3 ปีที่แล้ว +3

      This is exactly I came to watch the video. I watched a bunch of other videos that tried to explain the concept, but it generated MORE questions, not less. It's easier to understand things in code, because there are no contingencies. All the ideas, advantages, disadvantages, potential for bug, etc., are all in the code, whereas spoken words are so malleable and leave a lot of room for interpretation.

    • @jordixboy
      @jordixboy 2 ปีที่แล้ว +1

      @@fxstreamer238 what has physics to do with OOP lol. It's just a way to model data, another data structure, nothing more.

    • @fxstreamer238
      @fxstreamer238 2 ปีที่แล้ว

      @@jordixboy ask the other guy. he wants to learn physics with oop. you thought you were smart but you just caught off guard didnt you

  • @jessss7792
    @jessss7792 7 ปีที่แล้ว +222

    Another solid video. Please continue this series, I'd love to see part 3!

    • @elgrimoriodelchamo1017
      @elgrimoriodelchamo1017 7 ปีที่แล้ว +5

      Same here. Amazing videos. Greetings from Venezuela, thank you very much Savjee!

    • @LeandrocBr
      @LeandrocBr 7 ปีที่แล้ว +1

      one more here!!

    • @BFFGamingHD
      @BFFGamingHD 7 ปีที่แล้ว +1

      YES, YES AND YEEEEES!

    • @austinkim1735
      @austinkim1735 7 ปีที่แล้ว +1

      one more!

    • @joaofrutinho
      @joaofrutinho 7 ปีที่แล้ว +2

      Epale chamo, yo también estoy en Venezuela, estoy interesado en hacer contacto con otros desarrolladores de aquí, si quieres nos contactamos, yo soy autodiacta. Así que sería genial poder ver en qué podemos ayudarnos.

  • @drbasavarajans
    @drbasavarajans 7 ปีที่แล้ว +52

    And finally I could comprehend what bitcoin is. Thanks for that crisp and neat threadbare tutorial. Thanks. Hats off to your skill of telling.

    • @fxstreamer238
      @fxstreamer238 3 ปีที่แล้ว

      congrats now you are 0.0001 % closer to understand btc.

  • @xCoKeZx
    @xCoKeZx 3 ปีที่แล้ว +5

    I never really understood how blockchains work until now. Apparently all I needed was an illustration in an OOP-way. Thanks a lot!

    • @waseem_498
      @waseem_498 3 ปีที่แล้ว

      Thought the same

  • @rishabhsingal9423
    @rishabhsingal9423 3 ปีที่แล้ว

    I've watched more than 6 hours worth of videos on blockchain but still never understood how it really works. But this 6-minute video quick explains how blockchain works in such an easy-to-understand way! Hats off, thank you!

  • @cameronm9968
    @cameronm9968 6 ปีที่แล้ว +8

    Seriously helpful video man! Seeing it implemented made blockchains so much easier to understand. I finally get why proof-of-work actually works and how it prevents and slows malicious modifications to the chain. Incredible work.

  • @g_pazzini
    @g_pazzini 6 ปีที่แล้ว +10

    awesome.... i'm an OOP developer... and i can finally understand blockchain by watching your videos... thanks!

  • @_jko
    @_jko 3 ปีที่แล้ว

    Thanks for the video. I watched a bunch of other videos that tried to explain block chain in plain English, but they utterly failed. You started with the basic idea, and improved it as you went on through the video to show how to address potential pitfalls. That was really helpful. None of the other videos do that. They just simply throw a definition at you and hope that you understand it from there.

  • @JackSparrah
    @JackSparrah 3 ปีที่แล้ว +2

    Just starting to learn about blockchain in 2021, and this was super helpful. Seeing it coded live made it so much more clear. Thank you!

  • @rum81
    @rum81 7 ปีที่แล้ว +1

    Thank you very much for these two videos, i have understood in 15-20 minutes what could not understand after months of blog and videos on block chain

  • @therealguanzo
    @therealguanzo 3 ปีที่แล้ว

    This is so informative for someone that knows nothing about blockchain tech. Thanks!

  • @fredkilby5535
    @fredkilby5535 6 ปีที่แล้ว +2

    Great video in explaining the technical aspects of blockchain and how to parts fit together.

  • @vsowill
    @vsowill 2 ปีที่แล้ว

    It’s wild how relevant this video is in 2022 and it’s 4 years old. 🔥🔥

  • @arsnakehert
    @arsnakehert 6 ปีที่แล้ว +6

    Damn, what a brilliant little series! This is so very illustrative! Thank you!

  • @vprnet
    @vprnet 6 ปีที่แล้ว +1

    Surah, you are a very talented instructor!

  • @kkode001
    @kkode001 6 ปีที่แล้ว +1

    Very helpful series. Awesome!!! 10 mins of code is better than 10 hrs of talk. Thanks and keep it up.

  • @nilvoidzero000
    @nilvoidzero000 3 ปีที่แล้ว

    Thanks!

  • @kp8752
    @kp8752 7 ปีที่แล้ว +1

    These videos are fantastic honestly. Also the easiest to understand blockchain intro tutorial

  • @LucasAdSantos
    @LucasAdSantos ปีที่แล้ว

    I'm a professor watching the playlist from Brazil! Tranks!

  • @yohan_aka_spof
    @yohan_aka_spof 5 ปีที่แล้ว

    Very interesting !
    There is just two small bugs:
    1) in the constructor of your block you call calculateHash before setting the nonce, which will be then undefined. Overall, I wouldn't call calculateHash in constructor as you will anyway overwrite it inserting it in the chain.
    2) in your mining function, you first increment nonce, then you calculate your hash so you will never test the case with nonce = 0

  • @jamallucas
    @jamallucas 7 ปีที่แล้ว +1

    I finally understood the logic behind blockchain. Great video buddy!!!!!

  • @chrisc9725
    @chrisc9725 3 ปีที่แล้ว +1

    Wow man I've just come across your channel, its amazing, thank you.

  • @lovebajpai5288
    @lovebajpai5288 7 ปีที่แล้ว +4

    Great work Savjee!! It simply explains the nonce, difficulty and mining in such an easily understandable way!!! Thank you!!Can you also do something around Valet and how it fits in all this?

  • @ayuthmang
    @ayuthmang 5 ปีที่แล้ว +4

    Thank you for explaining block chain and proof-of-work in the easiest way. Hope to see more videos. -)

    • @jimannothe
      @jimannothe 3 ปีที่แล้ว +1

      In the easiest way. though that's subjective

  • @DurgaPrasad3496
    @DurgaPrasad3496 7 ปีที่แล้ว +1

    This is Awesome. After watching this video i get into better perspective of blockchain. Thank You!

  • @nandusuy
    @nandusuy 2 ปีที่แล้ว

    Thank you. Learning with you is a comforable experience!

  • @Grkashani
    @Grkashani 4 ปีที่แล้ว

    you are awsome man !!!!!!!!!!!!! , after many years looking for understanding blockchain I found my answer from you , thank you so much,

  • @FreedomForKashmir
    @FreedomForKashmir 3 ปีที่แล้ว

    I LOVE your videos on blockchain ..... you are the best teacher over the internet
    You cleared a lot of my concepts

  • @whysoseriouscooking
    @whysoseriouscooking 5 ปีที่แล้ว +1

    This channel has liberated my mind! I repeat 'LIBERATE'!

  • @saumilkapadia88
    @saumilkapadia88 6 ปีที่แล้ว +1

    mind blowing brilliant video and explanation.

  • @ssiroma
    @ssiroma 3 ปีที่แล้ว

    Thanks

  • @gilbueno5181
    @gilbueno5181 7 ปีที่แล้ว +11

    Make a Part 3 please :)

  • @aeonreigh
    @aeonreigh 6 ปีที่แล้ว +1

    I love this! way better from the talks I've been to about block chain!!!

  • @cazino4
    @cazino4 4 ปีที่แล้ว

    Fantastic video, great to see a practical examples of what a block chain implementation might look like. Thank you.

  • @jobsphil9553
    @jobsphil9553 7 ปีที่แล้ว +10

    Thanks for your sharing.. You are the great.. definitely .

  • @kinershah464
    @kinershah464 2 ปีที่แล้ว

    Wow that was simple and it seems to be quite effective solution.

  • @RyanHooGeek
    @RyanHooGeek 6 ปีที่แล้ว +1

    Really nice video, it explains a lot! Words in the paper of bitcoin were so confusing before I watch this.

  • @nouhbelahcen4486
    @nouhbelahcen4486 4 ปีที่แล้ว +1

    Really amazing explain, Thank you very much.

  • @RaceBook.
    @RaceBook. 7 ปีที่แล้ว +1

    Please upload the 3rd part also. great video lecture

  • @artofchickens
    @artofchickens 6 ปีที่แล้ว +1

    I just recently found your channel. This and your previous video are awesome! I have yet to watch the rest. Thanks so much for such valuable information!

  • @mikeigoe
    @mikeigoe 6 ปีที่แล้ว +1

    Brilliant tutorial, thanks.

  • @christopheverdot9075
    @christopheverdot9075 6 ปีที่แล้ว +2

    Very nice video, doing a POS instead of POW would also be possible on this javascript Blockchain demonstration ?

  • @jazztwk
    @jazztwk 7 ปีที่แล้ว +2

    Great video, really explain clearly in the technical prospective of proof of work, please make more example video

  • @AnishSingh-st5yl
    @AnishSingh-st5yl 5 ปีที่แล้ว +1

    Merci beaucoup Xavier...

  • @rleevzlno
    @rleevzlno 7 ปีที่แล้ว +1

    Awesome content. Thanks for share it

  • @4by4rusjo44
    @4by4rusjo44 6 ปีที่แล้ว +1

    Great stuff mate. Thanks for sharing

  • @danilosampaio6493
    @danilosampaio6493 2 ปีที่แล้ว

    Someone gives an Oscar for this guy! This is simply awesome

  • @kejoe100
    @kejoe100 7 ปีที่แล้ว +2

    Your way of teaching is really good, very easy ro understand blockchain, its been 2 months u had not uploaded any video on this series, should we expect more videos???

    • @simplyexplained
      @simplyexplained  7 ปีที่แล้ว +1

      Sometime in the future yes. Been busy with the Simply Explained series. Been thinking where I can take this Javascript implementation next.

    • @kejoe100
      @kejoe100 7 ปีที่แล้ว

      Thanks Savjee!! Good to here, looking for next videos 😊

  • @yousafhassan8655
    @yousafhassan8655 6 ปีที่แล้ว +1

    Thank you so much Sir. The mining concept was very well explained.

  • @munezhans7735
    @munezhans7735 5 ปีที่แล้ว +1

    Well done. Thank you

  • @BFFGamingHD
    @BFFGamingHD 7 ปีที่แล้ว +3

    Savjee, please continue this series! I love it and I love you

  • @freddie2153
    @freddie2153 7 ปีที่แล้ว +1

    Great series so far, easy listen but packed full of info!! Looking forward to more.

  • @adams1378
    @adams1378 7 ปีที่แล้ว +3

    Amazing video dude. Please continue along that path, really interesting !

  • @gabrielmicko4771
    @gabrielmicko4771 3 ปีที่แล้ว

    Very great, solid video. Thanks

  • @jaikant931
    @jaikant931 3 ปีที่แล้ว

    Brilliant explanation. cheers

  • @Mentaleak
    @Mentaleak 7 ปีที่แล้ว +1

    Great Video, Please do another one for Smart Contracts

  • @ruiminti8528
    @ruiminti8528 6 ปีที่แล้ว +1

    Nice,Thank you

  • @نورمحمد-د7ك2ب
    @نورمحمد-د7ك2ب 2 ปีที่แล้ว

    my English is not very well but i can understand what you say, this thing not often happened ,about blockchain you do amazing job mashallah 🤩

  • @vectorfield
    @vectorfield 7 ปีที่แล้ว +4

    Thanks a bunch for this series, this has helped me tremendously in my quest to grasp how blockchains/cryptocurrencies work.
    One thing I don't understand though is how you would now allow others to make use of this blockchain.
    Coming from a web background my first instinct tells me that you need to host this somewhere in order for other people to make use of it.
    However, I've heard a lot about decentralization with regards to this technology so that can't be it. Is this where the Bitcoin protocol / P2P decentralized networks come into play?
    Also, a video on how to implement your own smart contracts would be awesome as well.

    • @simplyexplained
      @simplyexplained  7 ปีที่แล้ว +7

      Thanks for the kind words!
      Yes, in order for others to be able to use this blockchain, it would need a P2P network. Each node that has to announce itself on the network and find the longest valid chain available. Once that is found, the node needs to copy the entire chain and then he can start using it.
      It also needs a broadcast system for new blocks. As soon as a node mined a new block it should broadcast this to the entire network so others can add that block to their own chain and keep the consensus.
      I'm still thinking about extending this series with more video's (thanks for the smart contract suggestion).

    • @adldesigner
      @adldesigner 7 ปีที่แล้ว

      Hey Savjee, keep this series going. I'd love to know how to setup a simple P2P network like that.

    • @vectorfield
      @vectorfield 7 ปีที่แล้ว +1

      Thanks for clearing that up for me, I appreciate it tremendously.
      Here's another question: What happens when two random nodes successfully mine a block at the same time and then both broadcast it onto the network? How will this algorithm decide which block is the block they should continue the chain with in that situation? Does the losing block get destroyed?

    • @simplyexplained
      @simplyexplained  7 ปีที่แล้ว +2

      Chances of that happening are pretty low. But it can occur. In that case one of the blocks will go around the network faster than the other, and that one will win. The other one is then abandoned and becomes orphaned.

  • @neethucheriyan1077
    @neethucheriyan1077 5 ปีที่แล้ว +1

    sir could you pls explain how can we update the previous hash of a particular block, when the data in the previous block is updated

  • @hadireg
    @hadireg 4 ปีที่แล้ว

    excellent explanation!!!👍👍

  • @JChengZhang
    @JChengZhang 7 ปีที่แล้ว

    Explained so simple. Please continue with this!

  • @kejoe100
    @kejoe100 7 ปีที่แล้ว +1

    Thanks for the videos, I love this kind of series!!! Plz plz make next videos

  • @lapsedubstep
    @lapsedubstep 7 ปีที่แล้ว +1

    AMAZING video. thankyou! Hope to see part 3 ❤

  • @YogeshPadsala
    @YogeshPadsala 6 ปีที่แล้ว +1

    yes this is a great video. thank you

  • @ivanche8051
    @ivanche8051 3 ปีที่แล้ว

    You can also create a string of all zeros of an exact length by using repeat method
    ‘0’.repeat(difficulty)

  • @samueleagostinelli5346
    @samueleagostinelli5346 7 ปีที่แล้ว +1

    Loving this

  • @phet1574
    @phet1574 7 ปีที่แล้ว +1

    Great series! I would love to see the part3 :D

  • @Raayol
    @Raayol 7 ปีที่แล้ว +1

    Thank you!!! You are awesome!!

  • @trungkienle3714
    @trungkienle3714 6 ปีที่แล้ว +1

    thank you so much! It really helpful to me

  • @PavonDunbar
    @PavonDunbar 6 ปีที่แล้ว +1

    Amazing video. Subscribed. Thank you!

  • @buzonliao
    @buzonliao 7 ปีที่แล้ว +1

    Awesome video!

  • @potterprasant380
    @potterprasant380 3 ปีที่แล้ว

    Osm... Thank You For This video ❤

  • @awekeningbro1207
    @awekeningbro1207 5 ปีที่แล้ว +1

    what if we used settimeout function for proof-of-work instead?

  • @techtantrik
    @techtantrik 7 ปีที่แล้ว

    Well paced lab and very well explained. Thanks!

  • @shgazda
    @shgazda 7 ปีที่แล้ว +1

    Man, great video! Thanks!!

  • @john-blair
    @john-blair 3 ปีที่แล้ว

    Great video. Simply Explained. Thanks.

  • @SafalLamsal
    @SafalLamsal 7 ปีที่แล้ว +2

    great video!! part3 smart contracts?

  • @neerajkulkarni6506
    @neerajkulkarni6506 3 ปีที่แล้ว

    This is so well explained!

  • @j8577798yt
    @j8577798yt 6 ปีที่แล้ว

    Best explanation on the net !!!

  • @LeandrocBr
    @LeandrocBr 7 ปีที่แล้ว

    Fantastic!!! I would like see another videos about this...

  • @dipanshunegi9805
    @dipanshunegi9805 3 ปีที่แล้ว

    Thank you do much sir .. love you for this.

  • @maxbruhn8383
    @maxbruhn8383 7 ปีที่แล้ว +1

    Very good video. Keep em coming.

  • @sankhatvijay
    @sankhatvijay 6 ปีที่แล้ว +1

    @Simply Explained - Savjee, First of thank you for the great video. I need help from you. we are planning to create new payment gateway, is it good to implement blockchain technology for our new payment gateway?

  • @klx450dude
    @klx450dude 6 ปีที่แล้ว

    greaaat greaaat video! Best explanation so far i found online about blockchain and mining, thank you! Please continue! :D

    • @simplyexplained
      @simplyexplained  6 ปีที่แล้ว

      Working on something right now. Will be published after next Explained video 🤐

  • @juancarlosgonzalez9722
    @juancarlosgonzalez9722 3 ปีที่แล้ว

    Solid explanation my dude. Thank you.

  • @flamingwoodz
    @flamingwoodz 7 ปีที่แล้ว

    This video series is awesome

  • @jordixboy
    @jordixboy 2 ปีที่แล้ว

    good job man! im curios how would proof of stake be implemented?

  • @LeifDeJong
    @LeifDeJong 7 ปีที่แล้ว +1

    How would one conceivably implement the P2P part of this?

  • @tuanatayman3301
    @tuanatayman3301 4 ปีที่แล้ว

    is it the sha256 module that put the nonce automatically in the beginning? or the fact that we give it at the end of the return in calculateHash method?

  • @phnxbr
    @phnxbr 6 ปีที่แล้ว +1

    Hi! It was a pleasure to watch these videos, really simple comparing to others overсomplicating it. Just keep going.

  • @josephroney2014
    @josephroney2014 5 ปีที่แล้ว

    Why do you need to mine the block or calculate the hash twice? the first time at the constructor and then when adding new blocks to your chain.

  • @pietromonsorno5390
    @pietromonsorno5390 4 ปีที่แล้ว +2

    i'm having an issue with the substring function on vscode, i does not recognize it as a function. Any help?

    • @Foxlendor
      @Foxlendor 3 ปีที่แล้ว

      same

    • @Foxlendor
      @Foxlendor 3 ปีที่แล้ว

      How did you spell "constructor"

    • @pietromonsorno5390
      @pietromonsorno5390 3 ปีที่แล้ว +1

      @@Foxlendor np mate, it was 1year ago, plus for what I recall, it definetly was a typo nothing more😂.
      Thanks anyway

  • @mtiderman
    @mtiderman 6 ปีที่แล้ว

    outstanding! Thanks

  • @erik-sandberg
    @erik-sandberg 6 ปีที่แล้ว

    If it takes a considerable amount of time to calculate a valid hash, how does one quickly verify the whole chain? In the last video, Savjee's isChainValid function calculated the hash for each block, but that would take way too much time, right?

    • @erik-sandberg
      @erik-sandberg 6 ปีที่แล้ว +1

      To make it quick to verify each hash in the chain of blocks, the 'nonce' value must be included in the block's data then, right? Then the none value doesn't need to be guessed when verifying a block that already exists

  • @nicolaimartin7279
    @nicolaimartin7279 7 ปีที่แล้ว +1

    amazing thx for share

  • @i6mi6
    @i6mi6 7 ปีที่แล้ว

    Excellent work!

  • @saumilkapadia88
    @saumilkapadia88 6 ปีที่แล้ว +1

    Is there any next part of this??? Plz plz plz make it if not. With javascript only please

  • @fabiofreitas7760
    @fabiofreitas7760 5 ปีที่แล้ว

    In Bitcoin, do they define the difficulty by making the hex encoded hash of the block start with n zeros or the bits themselves?

  • @Saitama-ur3lq
    @Saitama-ur3lq 3 ปีที่แล้ว

    curious question the nonce is an integer right? what happens if it overflows