Lottery Smart Contract Tutorial Part II - Get a verifiable random number with Chainlink VRF

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • In this smart conract tutorial we use Chainlink VRF to improve the lottery smart contract that we created in Part I by replacing the pseudo-random number generator code with a true, verifiable random number.
    Chainlink is a decentralized blockchain oracle network built on Ethereum.
    Part III - Build a UI for this smart contract using Web3js:
    • Web3 Tutorial Project ...
    Source code for this tutorial:
    github.com/jsp...
    Chainlink docs:
    docs.chain.lin...
    docs.chain.lin...
    docs.chain.lin...
    Rinkeby testnet faucet:
    faucet.rinkeby...
    LINK faucet: (select Rinkeby testnet):
    faucets.chain....

Комментарии • 63

  • @rohankishibe4259
    @rohankishibe4259 2 года назад +7

    Thank you! These tutorials are amazing! I appreciate you leaving in the parts where you try to figure out what went wrong, they definitely help.

  • @prakhar_pratyush
    @prakhar_pratyush 2 года назад +8

    Really loved the way you didn't edit the video part when you got the errors, it actually helps. Thanks for the tutorial :)

  • @cmc2110
    @cmc2110 2 года назад +2

    Hey there, I have studies this code for about two weeks now. And I can confirm that it has a major flaw, first the function for fulfillRandomness is not defined that is why you get that warning. You do not need it but if your are trying to do things like the Mod of something you will need it. Also the reason mod.add did not work is because it is not defined like that, you just use a percentage it works like a charm. Thank you for putting this together I learned a lot from it!

  • @kafkahesse2606
    @kafkahesse2606 2 года назад +2

    can you make same tutorial for VRFV2? and instead in remix, can you show it in local editor, deploy it to testnet, and then fund the contract using code instead metamask extension?

    • @zhiyanli1723
      @zhiyanli1723 2 года назад

      i am also stuck with VRFV2, if there is a tutorial, or may be brief one would be nice

  • @KaraVengeance
    @KaraVengeance 2 года назад +4

    Great tutorial - liked the debugging process, really learnt a lot.

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад

      Awesome, glad you enjoyed it!

    • @KaraVengeance
      @KaraVengeance 2 года назад

      @@BlockExplorerMedia I'm so happy I found your channel - so much good content! :)

  • @pepocasver
    @pepocasver 9 месяцев назад

    Great tutorial, Im a very new guy in SCs, u help me to figure out how to handle the callback function response to make it work inside the functionality.

  • @deethekingstevens7146
    @deethekingstevens7146 Год назад +1

    Good video on chain link. But what if a user picks a number and it matches chainliks generated number?

    • @BlockExplorerMedia
      @BlockExplorerMedia  Год назад +1

      Thank you! In this lottery the players don't choose a number - they're simply added to an array and the Chainlink generated number is used to choose an array index at random, thus selecting a winner.

  • @gabrielgodspower6863
    @gabrielgodspower6863 Год назад

    Good tutorial, But since we are on gori tesnet there is no key hash, What do we do?

  • @semence2porc166
    @semence2porc166 2 года назад

    Could anyone refer me to some documentation to create a lottery for ERC 20 tokens? I am wondering how to modify this smart contract to reach what I am looking for. I am willing to learn, so no need for the full code (unless you have one handy ahah).
    In this serie we focus a lot on ETH transaction on mainnet, but I believe for ERC 20, 721 and others ; there might be different ways of coding. Thanks in advance for guiding me.

  • @sweetjimmy
    @sweetjimmy 2 года назад

    This has been very helpful for me 👐 Thanks a million 💗
    Just a little doubt that at 28:22 you said something like the delay in between requesting for a random no. and actually receiving it won't matter much because it's gonna take place "at night when nobody's looking" but later at 45:06 you reminded us that we have to wait for at least 2-3 minutes because that's how long it takes to get a random number. Isn't this supposed to happen "at night"?

  • @rompelstompelplaysskylore6178
    @rompelstompelplaysskylore6178 Год назад

    I'm glad you fixed a USB-port for the mouse :)

  • @vashitvaraj3520
    @vashitvaraj3520 2 года назад

    error message: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted { "originalError": { "code": 3, "data": "0x8129bbcd", "message": "execution reverted" } }
    I'm getting this error when I'm calling getRandomNumber function. Please help me out.

  • @hotgeckomedialtd5367
    @hotgeckomedialtd5367 Год назад

    Excellent tutorials. Really appreciate your hard work and clarity. How would I use import for @chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol as I am getting errors using V2. Thanks

  • @vsm-vaisofrermiqueinha2495
    @vsm-vaisofrermiqueinha2495 2 года назад +2

    Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted { "originalError": { "code": 3, "data": "0x8129bbcd", "message": "execution reverted" } }

    • @SamTheMan76
      @SamTheMan76 2 года назад

      Did you have any luck fixing this issue?

    • @olicrack1232
      @olicrack1232 2 года назад

      @@SamTheMan76 same question over here

    • @moustafaezz9158
      @moustafaezz9158 2 года назад

      Did you forget to set the gas value to "11000000000000000" ?

  • @tsunningwah3471
    @tsunningwah3471 6 месяцев назад

    rinkepy is down

  • @SKodiak
    @SKodiak 2 года назад +1

    this tutorial is pure gold bro

  • @Happyday-nn6rh
    @Happyday-nn6rh 2 года назад

    this contract part function payWinner maybe happen DoS with Failed Call hack i think ,
    What is the solution to prevent this from happening?

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад

      I think payWinner should have an 'onlyOwner' modifier on it. i have added this - nice observation and thanks for sharing!

  • @utopianfire1368
    @utopianfire1368 2 года назад

    Chainlink vrf is now vrf version2. Is this tutorial good to follow

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      Thanks for mentioning. It looks like V2 offers more flexible payment options, including a subscription option, but the actual random number logic and smart contract integration seems largely the same. So I feel like this video still has a lot of value.

    • @utopianfire1368
      @utopianfire1368 2 года назад +1

      @@BlockExplorerMedia Thanks for the explanation... Now I will gp through it

  • @Akhbash
    @Akhbash 2 года назад

    Amazing tutorial! Keep up the good videos!

  • @sukiratwarring6219
    @sukiratwarring6219 2 года назад

    Kudos sir you are doing a tremendous job...all i want is rinkeby faucet to work 😭😭😭😭

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад

      hey Sukirat, I think I have some extra Rinkeby test Ether...if you want to paste your wallet address here I can try and send you some.

  • @FusedDG23
    @FusedDG23 2 года назад

    Perfect man, No rehearsal and edit == perfect for learners like me.

  • @chenchou
    @chenchou 2 года назад

    Would you please share the source/Github repo if it's applicable? Thank you so mush!

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      Here's the link to the source code...I'll add to vid description as well - thanks!
      github.com/jspruance/block-explorer-tutorials/blob/main/smart-contracts/solidity/Lottery_w_Chainlink_VRF.sol

  • @mixai7
    @mixai7 2 года назад

    can add time limit or participants limit

  • @sachintharashmika4599
    @sachintharashmika4599 2 года назад

    is there any suggestion to make the random number generation process speed-up?

    • @BlockExplorerMedia
      @BlockExplorerMedia  Год назад

      Not that I know of, but I don't think it matters much in this case since the users won't be waiting for it at a particular time.

  • @ibrahimelbojairami7945
    @ibrahimelbojairami7945 2 года назад

    Great video, I love how you walk us through the errors you get. Btw, Chainlink migrated to a v2 for their consumer base contracts and random generators. I think that is why people are reporting gas estimation errors in the comments below

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      Thanks Ibrahim! Looks like I'll have to make an updated lottery contract video soon.

    • @ibrahimelbojairami7945
      @ibrahimelbojairami7945 2 года назад

      @@BlockExplorerMedia Would be very helpful honestly. It took me sometime to figure it out but I was able to eventually upgrade it to the new Chainlink contracts

  • @musaru2616
    @musaru2616 7 месяцев назад

    How to contact with you for an urgent help?

  • @davidruiz2656
    @davidruiz2656 2 года назад

    Great video, only one that explains this process well. I recommend that in the future you edit out the portions of the video where you are tying to figure out why something isn't working. Becuase it takes time from the video (21:58 - 23:30) and it makes you seem less knowledgeable ( no offense here) just saying edit them out and then make a comment saying: oh if you get this mistake, this is how you would solve it.

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      hey David, thanks and i appreciate the feedback. yes, I've been wondering what is the best way to handle that. a lot of people have commented that they like to see the troubleshooting process / things going wrong because it's closer to real life development. but maybe I should edit those parts a bit more if they go one too long!

    • @chenchou
      @chenchou 2 года назад +2

      @@BlockExplorerMedia Agree. It seems necessary for junior developers. :)

    • @getspike2716
      @getspike2716 2 года назад

      I like those parts actually

    • @WaveMrNight
      @WaveMrNight 2 года назад +1

      @@getspike2716 Yes, those parts are actually great. Don't remove them, please. You don't seem less knowledgeable, you just seem like a real dev.

  • @AdityaGupta-ke1vd
    @AdityaGupta-ke1vd 2 года назад

    I am getting this error. "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
    execution reverted { "originalError": { "code": 3, "data": "0x8129bbcd", "message": "execution reverted" } }" any help.

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад

      This error is often misleading and can have nothing to do with gas. It could be another type of error in code execution. Check your require statements and see if one of them is catching an error.

  • @apaddle261
    @apaddle261 2 года назад

    26:02 i keep getting this error after i sent LINK to contract address
    "originalError": {
    "code": 3,
    "data": "0x8129bbcd",
    "message": "execution reverted"

  • @gooblio
    @gooblio Год назад

    Got stuck, had to use "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol" and have this error
    Looks like requestRandomness isn't available in V2, maybe something different?
    Also had to change " require(linkAddress.balanceOf(address(this)) >= fee, "Not enough gas in contract");" (LINK.balanceOf)" doesn't work and I added Global variable "address linkAddress = 0x326C977E6efc84E512bB9C30f76E30c160eD06FB;"
    Goerli testnet address for LINK
    HELP!!
    from solidity:
    DeclarationError: Undeclared identifier.
    --> contracts/RandonNumber.sol:25:16:
    |
    25 | return requestRandomness(keyHash, fee);
    | ^^^^^^^^^^^^^^^^^

  • @isabelleegend
    @isabelleegend 2 года назад

    hi, I got this error while entering the 2nd and 3rd account. Any way to fix it?
    transact to Lottery.enter errored: Invalid parameters: must provide an Ethereum address.

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      hi Isabel, are you testing using the Remix editor or another way? Make sure all the settings are the same: Javascript VM, etc. I've noticed some buggy behavior in the value input before, so make sure you set it to Ether and type in 1 and click out of the box - make sure you still see the '1' before clicking on 'enter'. You can try copy / pasting the code directly from GitHub to the Remix editor to make sure there isn't any code issue:
      github.com/jspruance/block-explorer-tutorials/blob/main/smart-contracts/solidity/Lottery_w_Chainlink_VRF.sol
      Hope this helps.

    • @isabelleegend
      @isabelleegend 2 года назад

      @@BlockExplorerMedia thanks! Will try that out. Will you be making a web3 dApp for this lottery contract?

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      I wasn't planning on it, but a few people have asked. So maybe I will do this as my next video or two. Thanks!

    • @isabelleegend
      @isabelleegend 2 года назад

      @@BlockExplorerMedia yes! Looking forward to it! Will u be uploading that video soon?

    • @BlockExplorerMedia
      @BlockExplorerMedia  2 года назад +1

      Will try to do it this weekend : )