Smart Contract Tutorial - Create a lottery smart contract in Solidity

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

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

  • @python360
    @python360 2 года назад +30

    If only all tutorials were this good. Clearly explained, no BS, not too fast. Keep them coming!!

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

      Thanks Python - appreciate it!

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

      @@BlockExplorerMedia I built this for bnb and want to try and attach it to a domain for my discord to use how do i go about doing that Im a roofer so im not the smartest lol ty in advance

    • @kawaljeetsingh1657
      @kawaljeetsingh1657 10 месяцев назад

      No doubts. Loved it,

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

    This is the best channel teaching Smart Contract development in a lean, no-BS way.

  • @ssty447
    @ssty447 2 года назад +9

    very simple, always straight to the point, very useful video and there is a lot to learn from you!
    and I really loved that you never cut the video whenever u have errors! learning debugging and solving problems are the most important.
    no enough words to thank you.

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

      Thanks my friend, glad it was useful!

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

      For real as far as leaving the errors and the process a developer goes through to develop. It' s real, and anyone who's developed for any length of time knows and understands that a missing semicolon, or misspelled word can tie you up. Block Explorer has definitely earned my loyalty and repeat visits. He did a great job in this, helpful.

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

    I have seen quite a few solidity tutorials. Yours one is far far better than anyone else! Great Job!

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

    Huh, this absolutely amazing, I believe you explained this far too good and the fact that you fix errors while coding is just dope other tutorials lack that...
    I believe Design Patters should follow,... Once again thanks

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

    You are an amazing teacher, to the point.

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

    Great tutorial! Is it possible to set up an auto payout and restart of the lottery?

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

    Saved me from college examination's submissions!!
    thanks a lot sir!

  • @findy_dev
    @findy_dev 11 месяцев назад

    I had to hit the subscribe button. You are really one out of a million out there. The problem now is: I got a couple of questions from this video. How do I get answers??

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

    your are doing a great job pls don't stop....its one video for me per day!!!

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

      Thanks Sukirat! Planning to keep going.

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

      Hi Sukirat, can you recommend me 2-3 ur favorites from this channel? I am jr software developer from US aspiring become Blockchain Engineer

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

    Great stuff! Much appreciated! I'm just starting off with my journey learning Solidity. I fully appreciate such an awesome and extremely thorough tutorial, one with very real-world use as well.

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

    what if you only wanted to give out a percentage of the total balance, and not the entire balance? what would you code in line 26

  • @ДимаФедоришин-о2ъ

    Thank you so much! You really helped me! So grateful for your help!

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

    Beautifully explained everything and thank you so much for keeping it much simpler.Cheers:)

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

    One of the best it cleared my doubts. But need a simple frontend in html css or react js. Thanku lots

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

      Thanks, will do a frontend video soon - stay tuned!

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

      @@BlockExplorerMedia waiting , n pls make it a simple step by step.
      1. Check if metamask install and Connect with metamask with local blockchain.
      2. Input box to transfer ethers, display balance etc
      3.Click on Play and display winner and ether transfer to winner and display new balance.
      Thanking you

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

      hey, please check out the Web3.js tutorial released yesterday - it covers all of these things for vending machine contract - same can be applied for the lottery contract.

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

    Great video. How would you get this to accept some other Erc20 token?

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

    great explanation easy to understand!!. please make a video on lending and borrowing protocal like Aave .

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

    You are an amazing teacher.
    How to add more functionality like co.mission for the owner or referral fees. How can this be done

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

      This can definitely be one - you could transfer some percent of each user's deposit to a treasury or owner's wallet after the participant's initial deposit.

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

    The best blockchain learning platform I have come across. If I wanted to transfer my own erc20 token instead of ether, how will I be doing that. Can anyone please help me with that?

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

    36:44 You forgot to put the lotteryId next to the lotteryHistory. If you had done that there was no need to create another utility function!

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

    Hi block explorer good video but what if you creating a lottery ticket where users can input/choose a number and if theyre have the same as the random number then they be the winner.

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

    Hey, I am wondering if the order of the keywords matter in Solidity. For example, can you put "public" before "payable" when declaring variables ? Does it change anything ?

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

      While you are declaring variables you can't put visibility before payable as it will give you an error
      But you can put visibility before payable in case of function

  • @andrewshekel486
    @andrewshekel486 4 месяца назад

    As a Solidity expert do you understand that you getRandomNumber function is not random at all and how easily this code can be compromised?

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

    Hello, in production, how to you trigger the getWinner function? using JS in the front? How do you recommend to pay for expenses?

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

    Keep going with this playlist you are the best .

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

    The getRandomNumber should not be a pure function instead of a view function. I was thinking that view function were only used to read states?

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

    can u just use ether as unit instead of wei, so u dont have to copy a huge number

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

    You are a great teacher. It must be a good day that youtube recommended me your video
    Can you please how does pot balance adds up automaticaly?? because we are doing any total for balance in the code

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

    what if transaction is failed? I mean value is greater than 0.1 eth but player does not have enough balance to make payment.

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

    I have been stuck for a while now... I'm not available to pick a winner... this is the error that I'm getting
    "Note: The called function should be payable if you send value and the value you send should be less than your current balance.
    Debug the transaction to get more information."
    Works fine the first time!
    Any help?

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

      hi. which function are you calling and how much value if any are sending when you encounter this error?

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

    It would be nice to have a quick self intro (even mention of name) in the beginning so we can all thank you. Also you sounds like the chia channel I watch (coin breakthrough).

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

    At 27.01 the error you got is the same than in the vending machine tuto. I dont think it a gas issue. To fix the issue, inside the contract, instead using writing 0.01 ether, I write 10000000000000000 wei and it works. I dont have lot of experience so I dont know why it works but if someone can explain it would be great.

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

    anyone able to deploy this on a cloud like heroku or vercel. I can't for some reason. I've defined the env variables

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

      Do you mean the dApp? For the smart contract I would just deploy directly to Ethereum.

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

    Hello friend, great tutorial! Please how to split pay between winner and owner.

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

      hey, thank you! this code isn't tested but I think you could do something like this:
      players[index].transfer(address(this).balance / 2);
      payable(owner).transfer(address(this).balance / 2);

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

      @@BlockExplorerMedia Super! thank you, i will try this

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

      @@BlockExplorerMedia Yoo! thank you! works with a little edit, when paying the owner no division required as it will pay whats left after paying the winner, which essentially is the total balance. with the division, it will send half of whats left to the owner. great stuff man, cant thank you enough

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

      @@delostico can you please post your edit or refer to a GitHub / VIDEO / doc ? That would be awesome, thanks in advance.

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

      @@semence2porc166
      function payWinner() public onlyowner nonReentrant {
      require(randomResult > 0, "Must have a source of randomness before choosing winner");
      uint index = randomResult % players.length;
      players[index].transfer(address(this).balance / 5*3);
      payments.transfer(address(this).balance);
      lotteryHistory[lotteryId] = players[index];
      lotteryId++;

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

    hi, could you teach me how to make a lottery like the one in pancake swap. a lottery with multiple winners and dividing the pot in differents % depending on the amount correct numbers from start to finish max 6 or 7 numbers. please. a video of this would be great. im trying to make a crypto lottery as a project for my class. I was wanting to make a DEX but i find the frontend a little bit to complicate for me

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

    This was great, thank you

  • @S-K69
    @S-K69 2 года назад +2

    I have found your tutorials helpful
    Would love to see one on how to make an auto compound vault. Users deposit token/LP token into a vault that auto compounds for users. Could probably be done by forking off of Beefy or Pancake or something but I’m not experienced enough to figure it all out myself.

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

      I'm adding this to my list of video ideas to research - glad the tutorials have been helpful, thanks!

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

    23:55 "modifier"

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

    Direct and clear!

  • @GovindRaj-kn7vr
    @GovindRaj-kn7vr 2 года назад

    i liked this and subscribing , i would like it if you could add timestamp. it would be easy to navigate

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

      Thanks Govind! Good suggestiong, I'll try adding timestamps.

  • @單身生活
    @單身生活 2 года назад

    very good tutorial thank you !

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

    great videos! thanks dude!

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

    Hi BlockExplorer, I asked you about your contact to ask you something. Some scam guys answer instead of you.

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

    Thanks 🙏 sir

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

    awesome video

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

    thank you!

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

    Awesome

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

    god

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

    nij

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

    q¹!!!1

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

    why not add a function for the creator of this smart contract to receive 5% from each pot? Otherwise why in hell should anyone create this project? "oh no this is just tutorial purposes bla bla bla" ...shitshow

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

      If you werent dumb you would know how to add that function yourself without his help

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

      -Declare admin as payable
      -cast admin as payable in the constructor function
      -add this line in the getwinner function (before transfer funds to the winner): owner.transfer((address(this).balance)/20);
      Done ;)

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

      @@milanis7a thx a lot bratha!

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

    and I will buy around 500 dislikes and let them all downvote your video

  • @arthur-xl7ok
    @arthur-xl7ok 2 года назад +1

    I can't pick a winner it says :
    transact to Lottery.pickWinner pending ...
    transact to Lottery.pickWinner errored: VM error: out of gas.
    out of gas
    The transaction ran out of gas. Please increase the Gas Limit.
    Debug the transaction to get more information.
    I changed the gas but doesn't work
    what should I do?

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

      getting the same error and changing the gas limit before contract deployment doesn't seem to work

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

      Got any solution?