Smart Contract Tutorial - Create a lottery smart contract in Solidity

  Рет қаралды 27,828

Block Explorer

Block Explorer

2 жыл бұрын

In this smart contract tutorial we create a lottery smart contract in Solidity, guiding you through the process step-by-step. We write, deploy and test our code using the remix editor. Topics covered include sending and receiving ether, random and pseudo-random number generation and more.
Part III - Build a UI for this smart contract using Web3js:
• Web3 Tutorial Project ...
Source code for this video:
github.com/jspruance/block-ex...
Remix IDE:
remix.ethereum.org/

Пікірлер: 124
@python360
@python360 2 жыл бұрын
If only all tutorials were this good. Clearly explained, no BS, not too fast. Keep them coming!!
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
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 2 ай бұрын
No doubts. Loved it,
@netdevilzzz
@netdevilzzz Жыл бұрын
I have seen quite a few solidity tutorials. Yours one is far far better than anyone else! Great Job!
@whysokara
@whysokara 2 жыл бұрын
You are an amazing teacher, to the point.
@ssty447
@ssty447 2 жыл бұрын
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 жыл бұрын
Thanks my friend, glad it was useful!
@brandonfowler1592
@brandonfowler1592 Жыл бұрын
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.
@MananRupani
@MananRupani Жыл бұрын
Beautifully explained everything and thank you so much for keeping it much simpler.Cheers:)
@user-ne6fy5qg7j
@user-ne6fy5qg7j 2 жыл бұрын
Saved me from college examination's submissions!! thanks a lot sir!
@myan518
@myan518 Жыл бұрын
This is the best channel teaching Smart Contract development in a lean, no-BS way.
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Appreciate it - that's a great compliment! : )
@user-ny5cd4zk7u
@user-ny5cd4zk7u 5 ай бұрын
Thank you so much! You really helped me! So grateful for your help!
@sukiratwarring6219
@sukiratwarring6219 2 жыл бұрын
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 Жыл бұрын
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.
@danielmaina4942
@danielmaina4942 Жыл бұрын
Direct and clear!
@youneshariz333
@youneshariz333 Жыл бұрын
Keep going with this playlist you are the best .
@soroushhakimpour1527
@soroushhakimpour1527 2 жыл бұрын
This was great, thank you
@jbars648
@jbars648 2 жыл бұрын
Great tutorial! Is it possible to set up an auto payout and restart of the lottery?
@9535004746
@9535004746 2 жыл бұрын
great explanation easy to understand!!. please make a video on lending and borrowing protocal like Aave .
@favour_findy
@favour_findy 4 ай бұрын
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??
@nzibukarnold1486
@nzibukarnold1486 9 ай бұрын
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
@user-bj7hb3lt1e
@user-bj7hb3lt1e 2 жыл бұрын
very good tutorial thank you !
@renaudvidal5505
@renaudvidal5505 Жыл бұрын
Hello, in production, how to you trigger the getWinner function? using JS in the front? How do you recommend to pay for expenses?
@mikuter4553
@mikuter4553 2 жыл бұрын
great videos! thanks dude!
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
no problemo!
@thestratfordstore5204
@thestratfordstore5204 Жыл бұрын
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.
@DFrancia35
@DFrancia35 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
@humanscoop2085
@humanscoop2085 2 жыл бұрын
thank you!
@jatin3709
@jatin3709 Жыл бұрын
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
@luckysjluckysj6175
@luckysjluckysj6175 9 ай бұрын
Thanks 🙏 sir
@fightline7409
@fightline7409 Жыл бұрын
awesome video
@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?
@htjani123
@htjani123 9 ай бұрын
what if transaction is failed? I mean value is greater than 0.1 eth but player does not have enough balance to make payment.
@sensivityable
@sensivityable 2 жыл бұрын
Awesome
@Ak-in5cu
@Ak-in5cu Жыл бұрын
we should use mapping instead of array. Because if a participant enters multiple times his/her address will be stored multiple times and then the chances of winning increases for him/her.
@newborn7850
@newborn7850 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 жыл бұрын
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 жыл бұрын
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.
@kelvinlatouche4500
@kelvinlatouche4500 8 ай бұрын
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 7 ай бұрын
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.
@msa7202
@msa7202 Жыл бұрын
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 Жыл бұрын
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
@ahmadzafar6053
@ahmadzafar6053 2 жыл бұрын
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?
@tsunningwah3471
@tsunningwah3471 2 ай бұрын
can u just use ether as unit instead of wei, so u dont have to copy a huge number
@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.
@ajb8832
@ajb8832 2 жыл бұрын
Great video. How would you get this to accept some other Erc20 token?
@semence2porc166
@semence2porc166 2 жыл бұрын
I am interested in the same.
@despertar23
@despertar23 Жыл бұрын
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
@S-K69
@S-K69 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 жыл бұрын
I'm adding this to my list of video ideas to research - glad the tutorials have been helpful, thanks!
@amarillomori
@amarillomori Жыл бұрын
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 Жыл бұрын
hi. which function are you calling and how much value if any are sending when you encounter this error?
@tanakpek6270
@tanakpek6270 Жыл бұрын
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 Жыл бұрын
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 жыл бұрын
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++;
@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.
@tsunningwah3471
@tsunningwah3471 2 ай бұрын
god
@nqlid
@nqlid Жыл бұрын
Hi BlockExplorer, I asked you about your contact to ask you something. Some scam guys answer instead of you.
@DanOhCaptainDaniel
@DanOhCaptainDaniel 2 жыл бұрын
23:55 "modifier"
@tsunningwah3471
@tsunningwah3471 2 ай бұрын
nij
@mrcrazy3960
@mrcrazy3960 Жыл бұрын
q¹!!!1
@foreveryoung7757
@foreveryoung7757 2 жыл бұрын
and I will buy around 500 dislikes and let them all downvote your video
@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 Жыл бұрын
If you werent dumb you would know how to add that function yourself without his help
@milanis7a
@milanis7a Жыл бұрын
-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 Жыл бұрын
@@milanis7a thx a lot bratha!
@arthur-xl7ok
@arthur-xl7ok 2 жыл бұрын
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?
Solidity Tutorial - Basics: Functions
8:43
Block Explorer
Рет қаралды 9 М.
Smart Contract Tutorial - Vending Machine Smart Contract in Solidity
34:34
Kitten has a slime in her diaper?! 🙀 #cat #kitten #cute
00:28
SHE WANTED CHIPS, BUT SHE GOT CARROTS 🤣🥕
00:19
OKUNJATA
Рет қаралды 9 МЛН
Web3 Tutorial Project | Build a web3js dApp for a smart contract
1:52:33
Block Explorer
Рет қаралды 107 М.
Ethereum - Tutorial 9 - Writing Our First Smart Contract With Remix
20:32
What are Smart Contracts in Crypto? (4 Examples + Animated)
8:09
Whiteboard Crypto
Рет қаралды 516 М.
the new PS4 jailbreak is sort of hilarious
12:21
Low Level Learning
Рет қаралды 150 М.
How To Code Your First Ethereum Smart Contract
19:18
Dapp University
Рет қаралды 172 М.
iPhone green Line Issue #iphone #greenlineissue #greenline #trending
0:10
Rk Electronics Servicing Center
Рет қаралды 4 МЛН
Wow AirPods
0:17
ARGEN
Рет қаралды 641 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 3,9 МЛН
С Какой Высоты Разобьётся NOKIA3310 ?!😳
0:43
Why spend $10.000 on a flashlight when these are $200🗿
0:12
NIGHTOPERATOR
Рет қаралды 17 МЛН
The power button can never be pressed!!
0:57
Maker Y
Рет қаралды 43 МЛН