NEAR Certified Demo | Episode 1.1 -- Dice
Nothing is loaded from YouTube until you press play, and then without tracking cookies.
About this video
This demonstration was presented by the author(s) after just 1 week of working with the NEAR platform as part of the NEAR Certified Developer program.
You can find the source code to this demo here: https://github.com/Learn-NEAR/NCD-01-...
--- Follow the latest from NEAR Protocol on: Website: near.org Discord: near.chat Blog: near.org/blog Twitter: / nearprotocol GitHub: github.com/near github.com/nearprotocol #Blockchain #FutureIsNEAR #NEAR #nearprotocol
Transcript
1,587 wordsCaptions as YouTube publishes them, usually machine-generated, so product and people names can be misheard.
- 0:00
okay uh so let's go directly to the contract uh this is a a dice a rhodes project a demo it's a simple demo um this is a contractor lib dot ice we can i can see what's the point to show you so uh let's show let's talk about some of the main structure of this this one the main structure here here near dice this is the main structure we have uh owner id this one is for i see i want to make this uh we want we want to make this contract
- 0:52
have some financial you know features so not only players can play at this uh on this contract also the the owner can gain some you know some some reward the reward comes from when maybe sarah wins a game maybe he uh roll a dice six and he gets the six so he wins half of the jackpot and from his wing his uh from his reward the owner can get maybe five percent this five percent is defined as a
- 1:35
fraction here uh reward reward-free fraction so this is a numerator is the denominator so this is like the sticky sticking pool contract you know um so let's go on uh so this size number uh defined uh in one row action we can we can draw one by four wrote two dice together or three dies together this is a expand point for further work for this demo it's only one dice one action you know uh as this rolling phase defines
- 2:24
we can the user should buy buy dice first and then androidize this is a really a price of a dice so this is a jackpot it's a typo type of mistake it's a pot jackpot and the owner part is all the tips from the winner owner part belongs to the owner of this contract so there are two to you know collections wing history stores all the wing event we we choose to this this vector from the near sdk collections because we want those
- 3:12
to store as long as possible but in further work in further work we may consider about the storage fee about this vector it may may grow uh on uncontrolled you know so um this accounts this account is still used to store like user buy some dice maybe let's say when near paradise a user can block can bought 10 dice using 10-year and then the dice is recording this lookup map this account id and how many how much
- 3:58
they paid for dice so for lookup map using low customers is considered about the this map can can shrink if if user rule dies and cause the balance uh reduced to zero then the lookup map will remove this this entry to uh to save some space of the you know storage storage space and this contract we we forbidden default so we can use this new func this new message to for the initial
- 4:46
uh method to pass through owner id size number rolling fee and the tips fraction and after the initiation initialize of this contract we also have to do uh to do a action to really start this playground that is to deposit jackpot because after the initialization the checkpoint is is empty so it's the owners possible owner's possibility the responsibility to deposit some initial funds to the
- 5:28
checkpoint so you can see we assert owner so this this method and this withdrawal method is belong to the owner owner's measure only owner can call this message and just a heads up marco you're at five minutes now okay i have to speed up sorry let's see the randomness here the randomness here is the oh rhodis this function so we get randomness from this one random seed because i say uh i think randomly is written uh
- 6:14
32 bytes randomness so we have many ways to to make it to a a random number in our uh our our own range here is uh just a one way to we add up it will add up all 32 bytes to one byte with this wrapping edge and to use this to limit the random to from one to six so this is the randomness and the okay another point to mention is we split this you see two methods here biodice and the road eyes at the first version there is only one
- 7:08
one method rodize we will make the rhodius payable and but we but we uh add up front and we found a console something difficult to do because the web wallet if appear if appearable method is called from the front end the front-end page would redirect to the uh you know official web page and so the front-end cannot get any written value so we have to split to two functions by dice and row dice yeah
- 7:45
maybe it's a quite a simple contract okay so if you have any questions about this contract hey michael how are you download dessert ui i mean frontier yeah uh show the front end here is the front end we can let's move the screen sign in okay okay then then we can buy maybe 10 dice it's a payable function so have to redirect to the web
- 8:46
the the web wallet so we have i have 12 dice also i i have bought two earlier then we can roll like two i guess two and then there should be a some automation picture but it's a time limit so i lose the number is six something like that so any questions let's grow it at five row it at five put five i'm like a guy five okay see how lucky you are yeah yeah let's check it
- 9:49
yeah okay third place you want to go that's wonderful thank you marco so any questions yeah i have a question um do you see any potential like uh weak places in uh in the contract itself or it or in its integration with front end for the attacks like when people can you know can cheat because this is a little bit of of gambling application right so and you most of uh first users like you attract a lot of people who who
- 10:28
come to make a quick bug correct so anything that you can come uh obviously you know like like very fast like okay so this is where i have certain concerns or anything i think it can uh yoga can not cheating on this game because because the road eyes this one rhodes yeah it's something like kind of a atomic action you know the people cannot know they cannot predict this random seed yeah this random thing is is generated after the people
- 11:06
have taken take his guess you know this is his guess and called the causes function then the function gets those random shifts i think it's very hard to have a prediction of what what number it would be no i mean i mean if we play with uh with front end like and i i would like to uh to roll the dice like a hundred times and pay just for one time uh is it possible like there is no
- 11:39
way like whatever i use like my my hiker skills yeah yeah maybe you can just add a two heart two dice to the production because when dice is only six points you can you can yeah the checkpoint cannot maintain 10 years maybe because when the of when they grow to 12 you can die six or eight times you can win i can you always can win and get half of them go you know yeah yeah i'm not i'm i'm not asking for myself because i'm good good good asking for a
- 12:21
friend i don't need the touches right lanier always wins yeah so welcome it's all it's the only record win winners if they're winners hopefully this is great marco thank you so much really appreciate the demo congratulations on the progress um and if there aren't any other questions i think we can move on to the next demonstration um thanks so much marco uh i will fork i will fork your repo yeah i will fork your repo into the um
- 13:06
uh into the the main uh organization that we've been using uh and uh and that way people can follow up with your your source code and try and deploy the application and and is is everything in one repository or is this split across multiple repositories front end and contract how have you organized it yeah i was the man author of the contract and the robot robots write some unit tests and deploy the deploy the whole project okay another member right the front end
- 13:40
you know okay great and and how many repositories is this project two repositories okay great so i'll fork both of those into the the org so people can try and rebuild it and it would be great if you can add some instructions i don't know i haven't looked at your repositories yet so that people can try and reproduce it deploy it learn from it yeah we have a we have a very fine uh very nice uh
- 14:06
instructions nice readme.md awesome congratulations thank you so much really appreciate you sharing this thank you