New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Dan Nolan: Learn Solidity – Chainshot | ETHDenver

Ethereum DenverWed, Oct 9, 2019, 12:00 AM

#BUIDL the future at https://ethdenver.com This talk was part of the ETHDenver 2019. ETHDenver’s features talks and workshops by top leading blockchain impactors, influencers and experts. ETHDenver is the largest Web3 #BUIDLathon in the world (fka hackathon) for Ethereum and other blockchain protocol enthusiasts, designers and developers. The community attending ETHDenver shows up to contribute to the global blockchain ecosystem, whether by #BUIDLing decentralized applications (dApps), contributing to or starting infrastructure level projects, writing documentation/tutorials/white-papers, designing UI/UX, or info-graphics, or to learn, connect, and get more involved. So bring your inner awesomeness and some friends. We’ll provide mentors, resources, and all of the educational content you can consume. Follow ETHDenver on Twitter: https://twitter.com/ethereumdenver Follow ETHDenver on Instagram: https://instagram.com/ethdenver Join the Bufficorn #BUIDL Brigade on Opensea: https://opensea.io/collection/bufficornbuidlbrigade Join the conversation on Discord: https://discord.gg/sporkdao Subscribe to our channel: https://www.youtube.com/ethdenver

Transcript

[Music] so I don't know if some new people came in but if you're looking for the website its class change comm and you could jump in right away we're still on the first stage and a class dot change shot I couldn't calm it's this one here and then Wi-Fi password DC summer 2019 exclamation mark okay [Music] yeah good question so I'll go over it once you get in there okay all right so yeah to go over this first stage guys if you want to you can jump into my workspace so I just started adding it in here so you can go to you can go to the participants list and find silver zebra there and that's gonna be me and if you view my workspace I I'm in the needs help column and you can copy kind of what I have out here for this first stage so essentially what we need to do here is the constructor is basically a special function that gets run when you deploy this contract out to the blockchain so this constructor is going to be called only that first time when you deploy this contract so it's usually a place where we go to setup something so if we were gonna create a build upon smart contract out on the blockchain we might want to have this max participants where we say at some point we're gonna cut off how many participants that we can accept into our build with on and so that's what this constructor is kind of doing right here one of the questions was a great question is why am i using an underscore here this is common convention so common convention for if you are just trying to set a variable so this is called a member a member variable inside of your contract here so if you're going to be setting something just to that value you want to use this underscore so that you don't shadow a member variable that you have in here if I were to call it the same thing then it wouldn't know the difference between this one and that one so the the main thing is here this one is pointing to my member variable my storage what's actually being stored on the contract and this one is referring to the one that we're passing into our constructor if you take a look into the test cases in here the teachers Jas you can actually see that what we're doing and so this is a great way to test your smart contracts as you guys are moving along is we're going where what we're actually doing is in JavaScript we're setting up a contract this is using truffles so if you guys get familiar and you might see it in other tutorials as well truffle is a quick way to kind of spin up a set of test cases for your smart contract and essentially what we're doing in here is we're actually deploying a a buildeth on contract a new instance of the buildeth on with a set number of max participants so I'm tossing in 200 here that 200 is going to get stored on our smart contract and then what I'm expecting is us to be able to call out to the contract wherever it lives on the blockchain and say hey how many participants how many what's the max participants that we can actually accept and we're testing to make sure that that matches what we passed in so if I go ahead and run these test cases here [Music] sorry if that messed you up guys so that's a classic mistake for me at least you're gonna want to put your unsigned integer in front of your public so public is going to be this is like I was saying before it's a visibility Center that's going to allow you to actually create that max participants getter function that we're going to be able to access from the outside I had these reversed so instead of public you went it should be you in public so if I go ahead and run that again Oh yikes okay I haven't seen that before you can if you refresh it's gonna hold all your stuff so you can try doing that yeah unfortunately I don't know if that's gonna help you yeah sorry I've never seen that before okay let's see what happened here okay so in the newer versions of solidity there it's required that you put a visibility setter on your functions as well so one other is one other mistake I made here is that you need to put a public on your constructor so that it's actually explicitly defined with the previous solidity versions you didn't have to do that and so this is kind of like the debugging process you're gonna see as you kind of run through your tests and make sure that you have it set up correctly cool sweet all right so that passed so if you guys want to jump into my workspace silver zebra I have up on here it's going to be inside okay cool a lot of people have it done before I did so if you jump into here you can look at anybody who's finished it and be able to like copy their code out so that you can pass the first stage and we can move on to stage two I'll give you guys just a minute to be able to do that cool so I'm gonna I'm gonna push forward on to stage two I actually got a login as admin cool all right so I'm gonna push this forward on to stage two now all right so Stage two what we're gonna do for this one so this one gets a little trickier so essentially what we're gonna want to do now is we're gonna want to allow people to enter our buildeth on so we're gonna so essentially what we're going to do is we're going to create a function called enter and that function is going to allow somebody to call in to this function call in to the smart contract and now join our buildeth on so there's a special property when you're calling a function inside of a smart contract that's called message sender that is going to be the address that's actually calling that function so when you call this enter function message out sender is going to be that address and we want to make sure that we store that address somewhere so that we know who's inside of our build is done at that time and then we're also going to create a number of participants that's going to allow us to define how many participants there are inside of the building and be able to call that from the outside inside of our JavaScript test cases I'll go ahead and get us a little bit started here I realized in so I'm starting from scratch but I'm gonna hop into my old workspace and go from there yeah yeah I'm always gonna do that that's the old versions didn't yell at you now it does yeah similar to our constructor which was a which is a special type of function when you want to name a new function on your contract there's this punch of function syntax that looks kind of similar to JavaScript if you're familiar and we can kind of look in here inside of our details to see how to set up a new function and we have this message dot sender here which is going to be that thing that we're going to use to be able to look up who's actually calling our function so function enter public and yeah so if you guys are familiar with this is a comment syntax I'm just trying to start you off there [Music] if you got to just toss on that collaborate sign and I'll hop into your workspace and give you like a pointer try to get you through it in about like two minutes I'll put up the solution and okay cool so we had a couple people finish this one this one was a little bit trickier so if you look into the test cases here what I have set up essentially it's very similar to what we did in the first stage is where we're creating a new build with on contract and we're putting in our max participants so it's 200 and then what we're taking we're taking this accounts this is going to get passed in by truffle in your execution environment these accounts are just addresses on the etherium on the etherium blockchain and i can loop over every single one and what I'm doing is I'm going to send over a transaction trying to enter our build it on and then what I'm doing down here is I'm testing that the number of participants equals the number of people that enter the build it on from our answer function so essentially really all you needed to do to pass the test cases for this one was actually add number of participants up so you don't have to put in an array but for the next stages you certainly will you could have done either an array or you could have done a mapping there's two different syntaxes here so one for a mapping you can do an address two like a boolean and say who's entered and so we can keep track of what what this is essentially doing is it's like a key value store so in this case this would have a bunch of keys that would map to a value and the keys would be an address and the value would be a boolean so true or false while the address is some long hexadecimal address so we can say entered message sender is equal to true and that's kind of keeping track that yep that's keeping track that this person who just under is the person who called enter they are now entered into our build with on so if we kind of run that we'll give it a second you might have to yeah that's probably what's gonna come back for me right now oh wow surprising that you don't okay oh okay good question so for a view a view you wouldn't actually be able to modify the storage so for view you don't actually modify so if I'm doing public what that's gonna default is to a function that I can modify storage so there's different visibility set setters view is definitely one of them that you want to put in there if you're just trying to look up something and those are actually it's a big difference there something like this is always going to cost gas because you're modifying something in storage and it needs to be mined by a miner who's going to pick it up and make that change for you and so it's going to cause some gas if you do something that's a view and you're just looking up Val using your smart contract like one of these like max participants and number of participants all they're doing is they're using the call syntax so from JavaScript and web three you might be familiar with you could call something like this you could say a getter dot call and this is gas list this doesn't cost me anything it's just a query that you sent to an aetherium node and typically you do that for in Fuhrer and it's totally free you just get the number of could count back so it's a great question cool okay so I'm gonna push this forward on to the next H fuel and work on it and I'm happy to help you guys out there's gonna be somebody else coming in this room so you know like we could probably work on it on the side and happy to work through it hopefully this was helpful for you guys and if you get to a point where you kind of tutorials we actually have something now so I'm gonna push forward our stage first we have something now we're so first of all you can go to change comm at any time and you could take those lessons like I was talking about in the beginning these are kind of take out your own pace and there's a couple different project based tutorials and things that you can get started on there similarly if you want to start your own tutorials we have this new tool it's called the Builder so WW github.com slash change side slash builder so if you go to get calm / chain shot there's going to be pinned up there we have this builder IDE and what this is actually it's an IDE that spins up from a node package globally so if I open up an item what we could do is all the content that's out on chain shot you can actually fork this so the tutorial that you guys were doing today you can actually download and so I'm going to go ahead and clone this repository to my local content one minute left and I can hop in here so I'm gonna go into my local content folder and I can run this chain shot builder and the instructions for how to do that is out on the github so what this is gonna do is it's gonna create an IDE for me where the lesson that we did today is the solidity buildeth on so if you guys were like I don't know that guy kind of had a wack tutorial and you want to like work on this and make it better you can actually hop in here and this is like the admin behind it and you can host this as your own and run your own class so yeah that's kind of what we're piloting here and hopefully you guys learned something new today and appreciate you coming out [Applause]

Automatic transcript — names and jargon may be misspelled.