Mining rewards & transactions - Blockchain in Javascript (part 3)

  Рет қаралды 188,929

Simply Explained

Simply Explained

Күн бұрын

Implementing miner rewards and basic transactions in our Javascript based blockchain.
Mining rewards steadily introduce new coins into the system.
OOPS, I made a small mistake! In the minePendingTransactions() method, you have to pass the hash of the previous block when you're creating a new Block() instance. This was fixed on GitHub:
► Source code
Available on GitHub:
github.com/SavjeeTutorials/Sa...
►►► Buying Bitcoin or Ethereum
Get $10 for free when buying through my affiliate link (thanks!):
goo.gl/G9NQsu
🌍 Social
Twitter: / savjee
Facebook: / savjee
Blog: savjee.be
💌 Newsletter: newsletter.savjee.be (no more than once a month)
❤️ Become a Simply Explained member: / @simplyexplained

Пікірлер: 244
@stevenrossi293
@stevenrossi293 6 жыл бұрын
Can you do the next video on how to make a peer to peer network!
@GeeksOasis_
@GeeksOasis_ 5 жыл бұрын
yeaaa please
@vlad981
@vlad981 6 жыл бұрын
Amazing! Please, keep up making this series!
@vietnambeauty123
@vietnambeauty123 6 жыл бұрын
Excellent! You made Blockchain comprehensible for children
@javierpernasalvarez2997
@javierpernasalvarez2997 3 жыл бұрын
I would say one of the best points of the tutorial are your comments on how things world in real life (Bitcoin) and the relationship with what you examplify here. Nice job!
@desireco
@desireco 5 жыл бұрын
Thank you, this series have been awesome. I am familiar with bitcoin but didn't expect you will be able to cover so much in such short time.
@mattha3787
@mattha3787 6 жыл бұрын
Please do more, love it.
@ollimac73
@ollimac73 6 жыл бұрын
amazing, please continue with these great video tutorials. Thanks for the ones you have done so far.
@itcrespo
@itcrespo 5 жыл бұрын
thanks for these videos, the simplest training for blockchain I've found
@OmarJIBAR
@OmarJIBAR Жыл бұрын
Amazing series 👍My area of interest has nothing to do with blockchains but your series captivated me. Thanks a lot.
@Loschcode
@Loschcode 6 жыл бұрын
Absolutely great and simple explanation to how blockchain actually works. Keep the good work !
@AbrarAhmed5
@AbrarAhmed5 6 жыл бұрын
These videos are amazing! Please keep them coming.
@daniellaerachannel
@daniellaerachannel 6 жыл бұрын
Excellent man! great tutorial
@malowwang6211
@malowwang6211 6 жыл бұрын
Thank you for sharing, savjee! Great videos! Expect much more videos from you
@PeterBatah
@PeterBatah 2 жыл бұрын
Thank you for sharing your time and expertise with us. I will definitely be going to bed a little bit smarter tonight. Have a safe and wonderful day!
@dec41rus
@dec41rus 6 жыл бұрын
Savjee, your explanation is great. Thank you very much
@Angelosanto
@Angelosanto 6 жыл бұрын
These videos are perfect, it would be awesome if you continued the series.
@furkanbasaran7541
@furkanbasaran7541 2 жыл бұрын
Thanks for this great series. I just joined your channel but you definitely deserve more.
@swapnilgt
@swapnilgt 6 жыл бұрын
Nice demonstration. Thank you!
@ryankdavidson
@ryankdavidson 6 жыл бұрын
Great video series, short and sweet
@ongxa888
@ongxa888 6 жыл бұрын
Thank you very much ! Your explaination is simply and easy to understand !
@leonhardeuler9839
@leonhardeuler9839 5 жыл бұрын
I followed the series until this video, now my mind is actually blown up.
@Chino747747
@Chino747747 6 жыл бұрын
great vid and tutorial, please keep on adding to these. I'm sure they'll be very popular
@frediopratamad2349
@frediopratamad2349 2 жыл бұрын
Thank you savejee, your explanation was given from heaven :D Amazing
@AkhileshJain0605
@AkhileshJain0605 6 жыл бұрын
Great work Savjee. Would really love it if you explained the ethereum blockchain in your videos!
@andreyevlawyers1925
@andreyevlawyers1925 6 жыл бұрын
Very clear, top quality videos!
@olegwarkentin2993
@olegwarkentin2993 6 жыл бұрын
is this series go on? like "how to create a wallet" or synch with clients? :)
@rleevzlno
@rleevzlno 6 жыл бұрын
Yeiiii I was waiting for this! Thanks for keep uploading :)
@5906646
@5906646 2 жыл бұрын
Fabulous! Great Work! Tahnk you
@NatCorry
@NatCorry 5 жыл бұрын
Please add more to this series!
@PendemiGod
@PendemiGod 6 жыл бұрын
Great work thanks so much!
@darrenlefcoe
@darrenlefcoe 6 жыл бұрын
works, well done. good education... look forward to next video.
@Jonathan-br8dn
@Jonathan-br8dn 6 жыл бұрын
Hi, fantastic series, I am eager to see new videos. regards!
@sunjiangkang5353
@sunjiangkang5353 Жыл бұрын
Thanks for your explaination
@18Maxic
@18Maxic 6 жыл бұрын
Excellent man , thanks you
@HomesteadAce
@HomesteadAce 6 жыл бұрын
Awesome series! Just a note, in your minePendingTransaction method you forgot to set the previousHash of the block as you did in the addBlock()
@curious_one1156
@curious_one1156 2 жыл бұрын
Yeah. Exactly, why did the function still work ?
@dotkoon
@dotkoon 2 жыл бұрын
​@@curious_one1156 In this video he didn't validate the blocks. But in the next video, the code has been fixed.
@nathanstroud4879
@nathanstroud4879 2 жыл бұрын
@@dotkoon Defiantly weird, I am getting an "invalid array length" error, so this is because of the isChainValid() or mineBlock() function?
@rd9055
@rd9055 6 жыл бұрын
Great video! Please make a video on Tor in simply explained series
@asolomon15
@asolomon15 5 жыл бұрын
This was an awesome tutorial
@ceorecdeclec9774
@ceorecdeclec9774 5 жыл бұрын
Will you add private/public keys and how can you implement the peer to peer network
@yuichibencoolenhrs5527
@yuichibencoolenhrs5527 6 жыл бұрын
Thank you for this video. Please continue this series and I look forward to (Part4) (Part5) and so on.
@agr__7
@agr__7 6 жыл бұрын
amazing man, amazing! Good job!
@Deetoya
@Deetoya 6 жыл бұрын
This really Helped.... LOved iT...
@stormhess8622
@stormhess8622 5 жыл бұрын
Thank you for taking the time to make this video...how would I implement an html frontend interface for it? Since it is to be highly secure, is there any specific calling conventions from html to the script or is as simple as an onClick() event to trigger the transaction? Cheers.
@wildtigers1210
@wildtigers1210 6 жыл бұрын
I think `getBalanceOfAddress()` should also check the balance of `fromAddress` ? before deducting coin from it ?
@IbanVan
@IbanVan 6 жыл бұрын
Exellent, one question, How i can save the blockchain (transactions) filesystem or DB ?
@ThomasOrlita
@ThomasOrlita 6 жыл бұрын
Nice video! I don't need to create a blockchain in javascript, it's just interesting to watch it... Subscribed to catch new videos! :) Btw you forgot to update this.index and this.data on line 21. (ok I see that it's fixed on github)
@Glosoliful
@Glosoliful 5 жыл бұрын
Loving video! You really know something only if you can explain it to your old mother or you can code it!
@aigerimiskakova963
@aigerimiskakova963 4 жыл бұрын
Good Explanation!
@denislupookov7895
@denislupookov7895 5 жыл бұрын
OMG! It is something amazing!
@yuefeima6201
@yuefeima6201 6 жыл бұрын
great videos, thanks
@Metachief_X
@Metachief_X 6 жыл бұрын
Hey Savjee. Can you make a more detailed video in depth about how to actually do peer-to-peer trading?
@disnelson308
@disnelson308 2 жыл бұрын
I love your tutorial. It is simply t]one of the best here. Please can you build a UI to interact with the application. And consider adding a P2P network too. Thanks
@j8577798yt
@j8577798yt 6 жыл бұрын
Very good!!!
@liatris69
@liatris69 2 жыл бұрын
This is gold!
@frankr.3413
@frankr.3413 6 жыл бұрын
Great! I wish I could coding like you.
@artofchickens
@artofchickens 6 жыл бұрын
You are so awesome!
@VagnerGon
@VagnerGon 5 жыл бұрын
Amazing!
@beunmin6
@beunmin6 6 жыл бұрын
Awesome! now i can make an ICO
@BulentSvr
@BulentSvr 6 жыл бұрын
Dear Savjee, Can you do a Simply Explained Video about "EOS"
@priteshvaviya6076
@priteshvaviya6076 5 жыл бұрын
Hey why haven't we changed the calculateHash function??
@SebLeFrenchie
@SebLeFrenchie 6 жыл бұрын
Nice video
@Hi-vt6mb
@Hi-vt6mb 6 жыл бұрын
What video software do you use?
@brianjianzhao3238
@brianjianzhao3238 4 жыл бұрын
Hey Savjee, why we still need to have prevHash as a property for each block and as part of the input for the current hash calculation? It seems to me it never gets used in this video's implementation.
@mahdipakravan676
@mahdipakravan676 3 жыл бұрын
This is Fucking Best Quality OF Learning Blockchain !
@dipanwitachanda444
@dipanwitachanda444 5 жыл бұрын
Waiting for your next video
@chrisreilly85
@chrisreilly85 6 жыл бұрын
Can you explain how luck factors into this for a miner? If I understand correctly, the miner is simply changing the nonce until the block difficulty is met (please confirm if I'm incorrect here). If so, wouldn't every miner start at nonce 0 and work up by 1 sequentially, therefore whoever has the most computing power would solve every block? Or, is it more efficient to randomize the nonce? Thanks for a great video series.
@josephnyc
@josephnyc 6 жыл бұрын
I wish everyone in life was explained in OOP, damn fun to watch. Keep it coming, create a Wallet class Savjee! I’m curious, did you make all properties and methods public just for the tutorial? The Chain and Block classes are so exposed it would be very simple to alter, no? IMHO the properties should be private at the least.
@simplyexplained
@simplyexplained 6 жыл бұрын
Yes everything is public. Javascript doesn't have 'private' properties.
@josephnyc
@josephnyc 6 жыл бұрын
Savjee I’m aware, didn’t literally mean public/private, I meant public as in own property, and thought there were ways of achieving private properties with symbols, closures, weakmaps, etc., was just curious to your thoughts on this. I dunno. Love the tutorials!
@Error404fucknickname
@Error404fucknickname 5 жыл бұрын
@@simplyexplained How do you make properties that can't be changed in Javascript then? Sorry, I'm not used to js, so not having private seems counterintuitive
@simplyexplained
@simplyexplained 5 жыл бұрын
There isn't a good way to do that in Javascript. Most people prefix private variables with an underscore to show that they shouldn't be directly accessed.
@ShogunWarrior36
@ShogunWarrior36 6 жыл бұрын
I really enjoyed this 3 part tutorial. Nice work! Xavier, do you happen to be Flemish by any chance?
@simplyexplained
@simplyexplained 6 жыл бұрын
Yes I am ;)
@g_pazzini
@g_pazzini 6 жыл бұрын
I have a question. Ideally, does a block contain multiple transactions or only one? if it's multiple, are the transaction grouped by certain parameter (e.g. contains transactions with the same fromAddress), or just random?
@yourlifeonpower
@yourlifeonpower 6 жыл бұрын
Bro! Please develop this tutorial into a course package! I will be very happy to pay for your course and learn from you!
@chregig7967
@chregig7967 4 жыл бұрын
Wow, thank you so much, I've been struggling with understanding how bitcoin, mining and the blockchain as a whole worked for a couple of years now and your videos finally cleared up so many questions! Now, if someone reads this, I have a question about one aspect that I am not too sure I understood correctly. You said the mined amount will get added with the next mined block, but in reality that would be very counter productive, would it not? Otherwise, nobody could actually make any transactions, because all of the blocks are used up to pay the rewards...? Or am I missing something?
@simplyexplained
@simplyexplained 4 жыл бұрын
Ah, well there is only 1 miner that can mine a block. So each block creates just 1 'reward' transaction in the next.
@vivekjain010184
@vivekjain010184 5 жыл бұрын
you are best!
@vasiloconnell281
@vasiloconnell281 2 жыл бұрын
The best!!!
@joeweitzel
@joeweitzel 6 жыл бұрын
Wouldn't we need a check at the transaction level that checks the total transaction is less than the coin's MAX_MONEY and more than 0? For example const MAX_MONEY = 21000000 would be at this level? Or is the coin limit handled elsewhere?
@myhandle364
@myhandle364 3 жыл бұрын
Wow, this is what I'm looking for on youtube. I'm still curious on (6.38) how p2p network a fool proof?
@curious_one1156
@curious_one1156 2 жыл бұрын
The previousHash is not included in this code. He removed the addBlock method with the minePendingTransactions, but did not assign previousHash before mining the block. Besides, he did not remove the index from the hash calculation. He is surely running git code, not this one shown. This would generate an error in the hash function.
@sikwee
@sikwee 2 жыл бұрын
Can you do a video on how to implement proof of stake in a javascript blockchain?
@rosseaux
@rosseaux 6 жыл бұрын
Can you also make a tutorial with a proof-of-stake variant?
@ShivaKumar-do5dk
@ShivaKumar-do5dk 4 жыл бұрын
Sir , What compiler sir would you used for this
@scarlettcrofts3168
@scarlettcrofts3168 3 жыл бұрын
How do I solve the TypeError: block.transactions is not iterable ??
@owaisali124
@owaisali124 3 жыл бұрын
so basically when a reward is given to a miner, it is added in pending transactions, but on second iteration it again adds reward for the miner and this will not end, the whole chain will look like reward of the miner of mining his own reward
@masoudkhoda9161
@masoudkhoda9161 4 жыл бұрын
Nice job. only one question. In your codes, as I checked, you set previous Hash by creating a block. Suppose that, "L" is the current last block in a chain. Block "A" and "B" are created at the same time. So they set their previous hash with the same hash e.g. Hash of "L". What happens by mining when both of them are mined successfully, but B was mined faster. Therefore normally the previous hash of "B" is correct, but the previous hash of "A" should be changed to the hash of "B". What I want to reach, I think assigning previous hash by creating a block is not necessary, but by mining. Am I right?
@oj0024
@oj0024 6 жыл бұрын
dose this mean you mine your one reward? is this in e.g. bitcoin also the case?
@AHoanNguyenNgocCong
@AHoanNguyenNgocCong 4 жыл бұрын
hi savjee, if i change data of the last blockchain (last block ) and calculate hash, the chain is valid, how can i fix it. - sorry if my english bad, i'm vietnamese
@rijumukherjee5280
@rijumukherjee5280 4 жыл бұрын
Hey Savjee I dont understand the concept how miners get out of the loop,Say 'A' transferred X coins to 'B' and now say 'C' mined for this transaction and now again another transaction i.e. reward transaction is obtained and so this will again be mined by 'C' so again it will create a new transaction.....This will continue...So how to break this loop....
@marcwyss8100
@marcwyss8100 6 жыл бұрын
Noob question: Line 52 when you create a new Block: are we not missing the parameter for previousHash? Because when I „console.log“ the blocks, my previous hashes are all at the default ‚0‘.
@marcwyss8100
@marcwyss8100 6 жыл бұрын
Default value being ‘ ‘ and not 0.
@AhmedAdel-ql5dt
@AhmedAdel-ql5dt 5 жыл бұрын
I followed your steps and I am facing the problem , I can't reward the miner and after mining the second block it gives me your balance is 0
@ringoyip0901
@ringoyip0901 6 жыл бұрын
This is amazing! The only question I have is: once a pending transaction has been resolved, will it get deleted? Do we need to create a method for deleting a resolved pending transaction?
@simplyexplained
@simplyexplained 6 жыл бұрын
When a transaction is added to a block, we don't have to keep it in the pending transactions. The code does this by redefining the pendingTransactions array
@Fluli
@Fluli 6 жыл бұрын
can you show how to implement proof of stake?
@gaborzsoter
@gaborzsoter 3 жыл бұрын
Hey, if you continue to run mineTransactions() again and again you actually mining your reward and get rewarded which you can mine and get rewarded infinitely? What am I missing?
@jamiegabbay7232
@jamiegabbay7232 4 жыл бұрын
Apologies, but why is that two transactions are set initially (the add1 to add2 of 100, and the add2 to add1 of 50) yet the 2nd transaction seems to be skipped over? Shouldn't both transactions be completed before xavier recieves his reward?
@hoanglinhpham984
@hoanglinhpham984 6 жыл бұрын
Thank you. I want to ask in practical, when is minePendingTransaction() called? Is that whenever the miner find an appropriate hash of new block?
@simplyexplained
@simplyexplained 6 жыл бұрын
Directly after you successfully mined a block or when the network (not implemented here) has mined a new block.
@desireco
@desireco 5 жыл бұрын
There is one more thing. address1 doesn't have anything to it, so I added a transaction to genesis block which resolved the issue.
@thejoker585
@thejoker585 5 жыл бұрын
Mining reward should be added to the current block being mined. It is logical to think that a miner would like to get paid the second she verified the block and not wait for the next block, otherwise theoretically she will have to pay a fee (in BTC network that is both expensive and time consuming).
@thejoker585
@thejoker585 5 жыл бұрын
But otherwise a great tutorial!
@WaiLiu
@WaiLiu 6 жыл бұрын
Nice video. Is there any reason why you put the miners reward in the pending transaction after its been mined? Wouldn't it simpler to add the reward to the pending transactions at the start so that it would be added for the block you're actually mining?
@simplyexplained
@simplyexplained 6 жыл бұрын
You can do it either way. I just choose to give it in the next block to create an incentive to keep mining. But you can give it straight away as well.
@focustech8225
@focustech8225 3 жыл бұрын
You want to mine your own reward, lol 😀
@thana3270
@thana3270 6 жыл бұрын
Continue this series
@simplyexplained
@simplyexplained 6 жыл бұрын
Sir yes sir!
@fungchan9216
@fungchan9216 2 жыл бұрын
When I run in terminal, it said while(this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) { ^ RangeError: Invalid array length DO you know how to sort it?
@adhoom
@adhoom Жыл бұрын
I don't know whether this changes in the upcoming videos or not. But, something that is really bothering me is that the user specifies the index for his block. Why is it not controlled by like a static field that keeps incrementing when a block is added ?
@simplyexplained
@simplyexplained Жыл бұрын
Good point. In fact, that index isn't needed at all. It was deleted from the GitHub repository but unfortunately I cannot update videos. github.com/Savjee/SavjeeCoin/blob/master/src/blockchain.js
@javajava7475
@javajava7475 6 жыл бұрын
Please make a series on making a wallet for our cryptocurrency
@jayantkhandelwal7326
@jayantkhandelwal7326 3 жыл бұрын
Hi, I have a doubt, as we have removed the reference to previous hash when we removed addblock method, then how are we implementing a blockchain without having previous hash value? Please help me in clarifying my doubt!
@curious_one1156
@curious_one1156 2 жыл бұрын
IDK myself. Maybe he ran the code from git, and not this one.
@thocodeditrade
@thocodeditrade Жыл бұрын
Thanks for your video, it was really helpful for me. Can you explain why we don't have a balance in reality? Why do we have to calculate it by going through all transactions? Thank you so much
@simplyexplained
@simplyexplained Жыл бұрын
Keeping track of balances would waste storage space without any benefits. Remember: blockchains are immutable. You can't change something that's already inside. If you want to keep track of balances, you would have to do that in every block.
Signing transactions - Blockchain in Javascript (part 4)
18:40
Simply Explained
Рет қаралды 120 М.
Proof-of-Stake (vs proof-of-work)
7:59
Simply Explained
Рет қаралды 1,4 МЛН
Did you find it?! 🤔✨✍️ #funnyart
00:11
Artistomg
Рет қаралды 114 МЛН
The best home workout !! 😱😱
00:27
Tibo InShape
Рет қаралды 9 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 118 #shorts
00:30
FOUND MONEY 😱 #shorts
00:31
dednahype
Рет қаралды 8 МЛН
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Internet Made Coder
Рет қаралды 1,5 МЛН
Smart contracts - Simply Explained
4:17
Simply Explained
Рет қаралды 1,7 МЛН
ERC20 tokens - Simply Explained
6:14
Simply Explained
Рет қаралды 422 М.
Angular frontend - Blockchain in Javascript (part 5)
49:57
Simply Explained
Рет қаралды 89 М.
5 Amazing Ways to Automate Your Life using Python
18:40
Internet Made Coder
Рет қаралды 173 М.
Sam Altman New statement On GPT-5 Is Surprising!
12:56
TheAIGRID
Рет қаралды 56 М.
Вы поможете украсть ваш iPhone
0:56
Romancev768
Рет қаралды 663 М.
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 12 МЛН
📱 SAMSUNG, ЧТО С ЛИЦОМ? 🤡
0:46
Яблочный Маньяк
Рет қаралды 1,3 МЛН
🤖Вернулись в ПРОШЛОЕ🤪
0:28
Demin's Lounge
Рет қаралды 99 М.
Индуктивность и дроссель.
1:00
Hi Dev! – Электроника
Рет қаралды 1,4 МЛН
Готовый миниПК от Intel (но от китайцев)
36:25
Ремонтяш
Рет қаралды 436 М.
Edit My Photo change back coloured with Bast Tech
0:45
BST TECH
Рет қаралды 335 М.