Intro to Solidity 2017 Edition
Devcon·Sun, Oct 7, 2018, 12:00 AM
Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more. https://archive.devcon.org/archive/watch/3/intro-to-solidity-2017-edition Hudson Jameson gives their talk titled, "Intro to Solidity 2017 Edition" Speaker(s): Hudson Jameson Skill level: Beginner Track: Developer Infrastructure Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum Learn more about devcon: https://www.devcon.org/ Learn more about ethereum: https://ethereum.org/ Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. Devcon 3 was held in Cancún, Mexico on Nov 1 - 4, 2017 Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/
Transcript
all right so I'm Hudson Jamison I work on a startup called oaken innovations and also work for the etherium foundation part-time quick about me just for a few seconds but involved in blockchain since 2011 worked for a bank called USAA doing their blockchain stuff for a few years and then eventually worked for the etherium foundation and Oken which is what I currently do today I have one wife total on the top left and then I also have three cats is this is this for my wife or for my cats at either way if you if you like cats you you would love Vivienne Fry and Leela so that's just a little bit about me so solidity is a high-level language for the etherium protocol what what I mean by that is usually when you get down to like the low-level parts of programming languages you have a bytecode you have like assembly and stuff like MIPS and all this other confusing stuff that people generally don't know how to like right it's not human readable so what we've done is the etherium foundation has created solidity which is a human readable language for smart contracts so if you've been coding in solidity or been involved in the you know aetherium community for a while this talk might be a little bit boring so I've decided to add a trivia question the question is how many high-level languages does aetherium have we're counting defunct languages but we're not counting things like II was um so like you can't say rust and C and other ones that would compile to ewaz them so be thinking about that and we'll get the answer in a few slides so solidity looks like JavaScript but it has types and the contracts kind of seem like classes so it's a about two years old maybe a little bit more than that and it's a very easy language to pick up because it has a lot of the qualities that web developers might be familiar with the code that is written and solidity is compiled to the etherium virtual machine once it's deployed to the etherium virtual machine it's a closed environment that runs on every node on the entire a theory of network so you can write a smart contract and deploy it hey the miners to mine the contract and when you deploy code its deployed across every single node in the etherium network which is really really cool issue with that is you can't have outside sources of like information so you can't have like sports scores unless you put them in manually and have to trust the source so if you want to get more information on that look up Oracle's or trusted data feeds into blockchains so contracts and solidity are easy to write but they're very difficult to make secure there's a number I'm just touching on this briefly because there are many flaws and contracts that have caused a lot of lost funds it's a very nuanced thing to understand and there's growing resources for creating secure contracts but it's not it's it's not completely there yet everyone's doing a really good job trying to come up with best practices and create things in the language to provide security but we all you know have to keep up with that and I encourage you to look at the solidity documentation under some of there's a section about security considerations that you all can look up if you're interested so here's the answer to how many high-level languages aetherium has it is six there's mutant which is a c-like language that was deprecated around 2015 serpent and Viper or Python like languages serpent is deprecated lll is either called low-level language or Lisp like language depending on who you talk to and that's one of the lowest level high level languages we have there's solidity and then there's a new one called bamboo which is supposed to be very safe written by yo Ichi and some other contributors from the community if I got this question wrong please go on line and yell at me on reddit because I love feedback and I love internet trolls so please tell me if I'm wrong about this one so contract standards are beginning to emerge we have ERC 20 which many of you have heard about it's just a set of standards for having a token on the blockchain that's interoperable with other tokens there's also security or smart contract security best practices I put the URL on the bottom and I'm going to publish these slides to Twitter so y'all can look it up after but this is from a company called consensus and they have this on their github so I'm gonna walk through a contract from creating it to deploying it to looking at a blockchain Explorer about it just really quick in order to do this all the tools that you need to do this are online right now the Fox logo is for meta masks which is an online plugin for your browser I believe it's in Chrome and Firefox right at least it's in Chrome and what you do is when you have a transaction that you need to push to the etherium network it acts as a bridge between your browser and the etherium network we also have remix which is an online facility integrated developer environment what that means is that when you want to write and test code it provides a lot of debugging features you can run static analysis on it you can call functions it's a really helpful tool for writing contracts and then finally we have ether scan ether scan is a blockchain Explorer so you can see the contracts you've created and the transactions you processed so first let's go to either scan so this is an example of pulling up contract code on either scan that's been verified as you can see we have the contract source the amount of ether that's in the contract and how many transactions have occurred so let's just dive in and write our first smart contract so this is a very very simple contract right here I'm calling it simple store and the only purpose of this contract is to store a an unsigned integer or to retrieve an unsigned integer so it's very easy to start a contract you just declare it as a contract you go in and then you declare your variables at the top like many programming languages suggest you do and then you can go in and create functions and events events are just like log files so as you're going through and debugging your code on the blockchain you can have these log files spit out events whenever something happens in your code so in our case we have the set function we made the set function payable so we're able to send ether to it that's another important security consideration in the old days you would have to have some a lot of workarounds in order to prevent your contract from keeping ether and not letting it be able to be sent out but now we have this payable modifier that makes it so that functions have to have a payable modifier in order to receive ether which makes it a lot safer if you're accidentally sending either two contracts in the set function I'm calling an event after I've stored the data that says the data that I've stored and then on the function get I call something I add something called constant on a blockchain you can do a transaction where you pay gas and you pay transaction fees in order to change the state of the blockchain there's also something called a blockchain read or a constant function there's now newer grammar I guess or newer function keywords around that I think it's pure and a few other ones to look that up but you can still use constant for the time being what it does is when you have a constant function you can do a free blockchain read to retrieve your data which is very powerful because it's just like reading a database and I don't want to spend money if I'm just reading a database so that is the smart contract in a nutshell what I'm gonna do now is I'm gonna hit the create button that I had on the other screen and when I create the contract a meta mask confirmation box pops up in your browser again this note that you didn't have to download anything the only thing you had to install was a chrome plug-in and open up a website so we're opening up this meta mask box and we're hitting submit we're putting in a gas price that kind of sets up the transaction fee and now we go to either scan to see our transaction being mined so it shows that the contracts been creative it gives the input data how much the gas fee was and a bunch of other neat data for you to see now we're going to go and to the contract itself before we were just in the transaction that made the contract now we're in the contract itself an ether scan provides a lot of other really cool tools so we have transactions where you can see transactions that are happening between the contract and the user or the contract and other contracts we see if there's any ether in the contract we can see who created it and we can even go and publish the contract code so say I have this simple store contract and I want other people to be able to look up my contract and see the code I can go into ether scan and publish that code inside of ether scan in a way where people can read it so now when I go to contract code it'll actually show me the code that I wrote and you can like lookup functions much more easily in ether scan it's a really really powerful tool that's widely used for transparency purposes so going back here after that transactions mind we have a log basically a blockchain logged under there and what it does is it shows you that you transacted with the browser that you had a transaction mined in block one nine four six nine to eight and it shows you a bunch of other details a lot of other interesting things if you look here we're gonna go ahead and set a variable so on the right side of the screen from there before you can call the set function so we're gonna set it to a hundred so again we call meta masks and the transaction and now when you read the smart contract on either scan you can see that instead of having a value of x equals 0 we have a value of x equals 100 so we've successfully stored an unsigned integer into a smart contract we have many integrations inside of solidity remix is one that I mentioned we also have Visual Studio we have IntelliJ them Emacs sublime I think that's Adam basically I went in and if you're using whatever IDE whatever kind of browser you want you can go in and you know plug it into whatever is comfortable for you and it has a lot of things like syntax highlighting it has a lot of things like yes syntax highlighting we have tools like soul graph and solidity rebel selenium and a disassembler and then at the bottom there's Papas embark and truffle those are really cool tools they're programs you download they're usually under over NPM so you it's like a node.js program and you can write tests for your solidity contracts and things like mocha you can also have them automatically compile your contracts and redeploy them on the blockchain there's just so many cool tools in there aetherium package management was a collaborative effort by a number of aetherium software developers that involved having an NPM like interface for the etherium contracts that are very widely used such as ERC 20 we also have a soul graph so contracts talking to other contracts are very very hard to visualize so soul graph takes your contract code and your functions and it tells you all of the inputs and outputs and potential things that can happen within your contract selenium is a tool to use I think it's a linter for solidity I don't use it myself but it's very very popular on on the on the whole sublime package manager oh man so that should be saying love solidity but it looks like something is unknown less than solidity and now it's covering up my slides so you can go to Jamison now go to Hudson Jamison calm / speaking engagements to see my slides you can go to Witter at Hudson Jamison or edit you see tacular and you can find all my information on there I have a couple of minutes so if anyone wants to yell a question I'll repeat it back through the microphone and feel free to ask any questions who has one raise your hand yep I've seen some like like beta or alpha versions of Eclipse plugins it might be further along than that but I'm kind of unaware if there is a plugin for that or not just because it's not on this slide doesn't mean there's not a plug-in for your IDE these are just the ones that I've been able to very quickly find so it's definitely worth looking up good question and the question was if I didn't repeat it already is there something in the Eclipse IDE that works with solidity next question yep what do I think is the biggest problem with solidity the biggest problem is that it is a young language and the problem with young languages in general across the board is that they don't have a lot of features that programmers are used to so that causes a lot of frustration there's a lot of basic primitives and a lot of things that make it easy to start out but otherwise there's not a lot of you know advanced tools also the safety of solidity has been brought into question and a lot of people are like solidity super unsafe look at all this money that's been lost but I mean this is all a big experiment guys like this is a super new language and if anyone's complaining about solidity being insecure they should come up with a way to make it more secure and start you know getting involved in these discussions and these tools so that's kind of the approach I take with that we have time for one more question yep what upcoming feature am I most excited about so if anyone saw the presentation on zou crates yesterday there are pretty new features to get cryptographic primitives inside of the EBM and therefore solidity to do ZK snarks which are called zero knowledge proof zero knowledge proof sin Abel semi private and private blockchain transactions and I think it's a really really powerful thing for the etherium ecosystem I'm Hudson Jameson thank you all so much for listening to me feel free to visit those websites and I'm going to have Christian come up after this [Music]
Automatic transcript — names and jargon may be misspelled.