Introduction to Smart Contracts
Ethereum Meetup Poland Talks · February 2017 · 26:24
Marek Kirejczyk gives an introduction to smart contracts at an Ethereum Meetup Poland session in early 2017. The talk explains what smart contracts are and how developers write and deploy them on Ethereum, aimed at newcomers to the platform in the Polish developer community.
Speakers
Topics
From Ethereum Meetup Poland Talks, hosted by Ethereum Meetup Poland.
Transcript
so it's going to be basically writing smart contracts 101 no weapons topic today no advanced topics today but hopefully in the future we can advise much deeper so we all know the stories it all started with Bitcoin the first group to carry one short letter can be falsified and think about it a little bit as well as a distributed database with the history of all the transactions and we'll probably a lot of you you know is that Bitcoin really supported program language called script that was executed on inconvertible machines it was a tax rate language and back free for you to
go and I was getting interested with Bitcoin I could enter beacon wiki and there would be told everything about my contract about all about as pearls and neutralized and all kinds of different businesses that would emerge as a this community program rather than company then what and I was expecting that in the next couple of years those all companies with all this to be the program's going merge but what really happens is that Bitcoin we can get a big success of the currency and the technical problems related to scaling and in general making sure that beacon gives a good quality good quality
experiences represents what it's supposed to be there was it was a lot and the distributed applications part never really happened so that was cut losses that's where experience comes into the game so it's working else to the blockchain in many in many areas the significant difference is that beautiful machine that is much more powerful than a peak current virtual machine so it's a put so for those of you who are programmers is to replace meaning you can write pretty much any program in if you are as because that we need to accept blocking and we need to
store some more information into production so besides contract themselves of the code we also we also have a storage of the blockchain so we can store the contracts may have stayed as money persisted Ismaili persisted in blocking and then we have lost in advance so we are able to notify the users of the applications that something had in the blocks and keep it up so I think that doesn't seem to be mark much more complicated than be good so how it works beneath so in a similar way in a Bitcoin as the whole ledger is being sort and every single node all the computation
from the very start of the e to blockchain are performed or everything below which always beneath that all the computation needs to be deterministic so that the result on every single computer is integration we had either the crypto currency and we have two kinds of actors in the system so likely to be beacon which they have a Wallace and well as was representing a robot a person with from analog Chris the consulate but also in the Trillium we have contracts so that's something that scenario title my mother lives in the blockchain or can interact with the blockchain anyone to do activities with them and
then the transactions you with some transactions from one person to another or from one world to another from one wall at the contractor from one contractor and are filled the transaction at the same time linkages we can schedule a call of the metal of the contract so you can think about it calling a method an officer in the program and finally one more important material before we move further is if you have a we have a code execution if galactic gas which is translated to - you mean both computations called mine shall letter with something very simple so this would be the simpler
contract possible it's written in solidity language which is like the language for receiving machine select a contract it has one method which is hello which returns title work now we can employ the contract to the blockchain and then everyone who has an oaken : up let us elope and get the result hello world nothing complicated so far okay so let's done a little bit more complicated contracting so let's accretor a little bit more complex code word 42 so before we go to examine rigor itself we're going on
markup so it is probably noticed by the syntax contract it's kind of very similar to the idea of the object oriented programming so we have a contract for pound which means it's a contract that can be killed because if we deploy a contract the blockchain and we want program that needs to destroy the contract is going to stay there forever hello we saw one information about the owner of the contract which is a type address which occur translates to address of a lot and we have a constructor contracts are going to be called the moment
contrast is employed to the block shape and our constructor will do one thing and one thing only which is we gonna store the information who the owner of the contract is as the owner of the contract is the person who created the contract and we can get it from message getting information from the make it bearable or make it object that sort of information about Buddha thunderation okay and then we have a special medical code we have a faction kill and we check is the person who's killing the meadows of the owner because we want only moment to be able to to the contract and it sells and tells us fragmental to sculpt
with one argument which is over now why do we need to whether we need an argument and total tract well creating an contract cost some eater and you like to make sure that out as little as useless information and sorted in developing as needed so each is incentivized to delete unused contract by giving some effort to the person who used to sell the scrap metal so who destroys the comic that make sense of our perfect cooping everything I'm saying is obvious okay
is that include people who coke to you and our children okay so one important we have a twitter twitter in very similar way that in our and object-oriented programming inherits from more health means is deliver it has all the metals and fields of their combo and it's going to one information which is string which is decreasing so well it's going to greet with when we ask to be greeted and again it has a contractor this time constructor has one argument which is began decreasing and and all the data
store information about region so was it an object that you do when you ask you when we ask we are a contract to query and then we have a methyl grease with complete returns greeting so we have very simple contractors which employ to the blockchain leave some kind of information and anyone stand concert and cold a medal as gap and get degrees yes if we compile the contract it's gonna deliver us two different there are two different output 1 output is 80 articles articles you can think about it a little bit as a like Heather and see maybe which is simply the interface of the
medal we're gonna call it the JSON and it's pretty self-explanatory and then we have a binary code as it's going to be deposited the blockchain so when we deploy binary code for the blockchain we still need to remember a be on our side of the blockchain to be able to call that ok and if you want to have some fun and you want to learn a little bit about how to read contracts there is a great online expert you can copy paste the code or written write your own contract and then you can see on your right that's on your right you can see the contract was compiled and two objects
are present and secure if you open it you can actually type in the parameters for a constructor your III and when you get created select create a contract and then you can see there is a metal grid green over here and we call it you can see what the result late so it's all my native origin goldenrod okay and there is e to their beef library which is a theory rivalry for connecting to the love chain to return blockchain there is not for Python there's long for JavaScript robot
either is left for as a major programming language so here's how you could here's how you could interact with here's how you could interact with loved him from two language it rose from ruin and misery so all you have to do is create a contract then you can just deploy it and then when you call it I publish their Britain so here's a simple program I wrote just to demonstrate you can collect on the creature interconnected rigid from well often it creates is it created Wizards that I think about the minute we can check on
dot blots and explore the transaction is actually happening you can see that depending you can see address for much cost and the area now we can refresh and when you refresh we can still see spending and now it's gone for a moment which means it was proved and you can see the application shows the result and then now you get the application as mine you can see it was one block there's one lot of information and it was 18 second scrolling with the close to the network does that make sense yes Oh so to recap solidity hmm pretty much
very similar learning and object-oriented language is compositing with your virtual machine with significant difference you can send literature because an ether if you receive it or you can say method it and I think it's what mentioned that you can apply to the production networks and deploy the test networks can make your own deployment you can make your own for can do your own e to the network so do you have any questions so far okay everybody remission ever get so let's examine a little bit more
complicated a little bit more complicated example so that the contract both versa you don't need to you don't need to be distracted so the idea is so they are the is there are two guys on the internet and they don't know each other and perhaps they don't even know their identities they don't trust each other and and one month of salt hopping an item to another one so let's call them color and a buyer so and of course both buyer and seller wants to make sure that you know transactions to approve the icons represent and the money is going to be paid so the idea is they a real the priceless traits an
eater can box whatever and the seller creates the contract contract and give 20 researches comfort supply these value of the items is twice the volume they read the items work that the buyer can increase you enter to contract and the way to do it is he also transfer same amount value 20 per twice the amount the value the value of the item and then the fire waits for the item to arrive to be sold and when it does he click confirm and the man agreed so the buyer gets half the money you paid back and half of the money goes to
the seller and then the seller gets all his money back okay the mix-up okay so in this way both sides are in strongly penalize the third you will go through so that's a contract purchase purchased or the value of that of the items they agree on all the other sellers that inspire the state it might be created by seller it might dissolve meaning that by your agree to enter the contract and it might be inactive meaning that you know the deal west
rules and it's down so we start with the constructor which is purchase and you can notice there's the word table here which means we can transfer other business value we transfer to do the computation we can also come for some extra money to the blockchain to the contract it's going to stop with the contract and then what we do is we can be sort information about to the fill arrange any store the information about what's the value of the items a real and as I said before it's half of the money that is being sent to that to the blockchain this to the contract and now we need a lot one thing we need to do is check if the amount of money this
basically by visual it can be divided by two because it is not we won't be able to do the compilation properly it's not then we cannot throw which is probably the gas were similar to similar instructions to what you can see in many with object-oriented programming languages which allows you to write an exception or throw an exception but there is one significant difference so the methods of the contract will a little bit like transactions in the database meaning it's either the whole matter that goes proof and everything happens and being so lost and yada yada or it's like this was never called so pro it's a little bit like canceling the
whole transaction of the matter of being called therefore if the matter is not is the amount of ether signed the contract is no dividable by two then the other one discord and the volume on the source then and in general is not repentance apology now we have first function which is confirmed purchase confirm it is being altered distinct called by the sender and we have fashioned modifiers which are inside state created meaning we can only use this metal can be successfully sold only if the contract
is personally created we acquired as missus value divided by two is the amount of value we agree on again it's going to happen if the trust and it's table because as I said before the buyer agrees to pay the same amount of value to the contractor and all we have to do is sort of information about modifier is same way as we sort information out to the suburbs and we need to serve the state to lock now once we know lock today confuses can be called by fire and again we have a modify only by your way of telling us so all the buyers in
closed mouth it only can be called if the state is law and all we have to do is update the state and send money back now we need to spend some my back to the buyer and we need to send some money to start right and only if both of those are successful then the whole metal can fruit now it's important that because as I said before there are two different animals living in our to zoom:1 one is a wallet and the other one is contract it might be that money we'll be sending to is a contract not necessarily a wallet if that happens it will send
money to the contract it means some code in the contract will be executed and this code might be successful or not and in particular is my pro-ana catchy so or it might call that method in our contract so we need to make sure that both are successful before I am over access to over Nigel okay that make sense so far any questions excellent so start of details worth discussing was going to my little dog so there is an important method so if the seller wait is waiting for the buyer by the
buyer is not entering the contract that you can afford it contracts at getting money back and here are all the modifiers we used in the previous screen require we simply check if the condition is true only buyer check to the sender of the message to the fire and all authority and got the idea okay so there were two examples and now interesting question they write so what else can we do what else can we do as a church what else kind of contract because so it seems that a lot of people think that pretty much every deeper we can think of
hats off as equivalent and distributed up and especially to to to ress business which is final and the sharing economy are to be the first one to see the drop of work with this video I think it's worth to mention because we're on polish we're all pulling it up they need to meet up I think it's worth mention that there is a number of startups that Arden recently started their way to disrupt their industry I think it's worth to mention those three because they have
that Ida polish or a half polish roots so golem that we have some gases going here so it's probably most of you know the right over eight million dollars another twenty minutes to build this to you this computing cloud I think we might have someone from noise pounds so anyone here from you know they promised to come that there are betting big star hop up with couple polish founder and they building distributed in venture capital and we have market from the other kids with one of the creators our meter so hopefully we have also found some party who is creator a lot one
artist one to the most important et voila so good help getting fat and like future looks very bright too distributed up there are some significant limitations together we had to cope with first of all everything the right to the blockchain a couple of minutes I think two minutes long time is it was the current rate in general storages execution is quite expensive so the idea that we going to store a lot of information or do perform a lot of completion inside it to you we far away from that and in general I would say the ecosystem is the Arkansas the whole
thing quickly that that means is I don't know and then it's not very stable therefore I think we have to therefore I think before they fully disability Chur future we have to think about when we built this to be real app we have to think about what people to put in the chain and what put off chain so one idea is that we put all the cordage to be the stuff in the blockchain and build normal web mobile apps around it that does not offer us some of the work or a lot of the work octane and there is a trend to combine ipfs and e2 I guess I've been
distributed third solution there is 4 which is sister protester to you which is distributed storage but also with its NT so we can say a little bit money to make a curio you're capable person and then you have Oracle's and there is a startup called aura type which connects launched into the real work by allowance to apply to the contract crew that at some point of mine somewhere there was some content on some websites and into the crystal of secrecy there are also things that there is some
pyramids are getting tired so there is much more in between want to achieve in charge it is to be the conjugation and it seems that group of work the system's behind Bitcoin doesn't guarantee distribution from get up so there is a there is an experimental project called Casper inside the serial network with goal to build proof of state algorithm meaning that everybody was both with their money not with the computational power another another very ambitious
goal is to enable scalability of interim by making possible that everything every other node just download the information they require to perform the computation with the contracts they're interested in not the whole long chain and then there is this case North privacy research project incited to you which aims to be able I might not be more precise here that makes it so that we can combine transformation to the blockchain or perform computations that are not transference and publicly available but there is a transparent publicly available proof that those computation
happens and they are correct so that's all the product that is talk about G cash people who now joining interim community to bring some of the magic behind me cash comes the crisis of the attorney who so so the question I would like to leave you with is to lock in to 0 is it is this deep loss thing you were reading about a couple years ago when we read about Bitcoin and digital occations and where we love gum and companies elected to the blockchain but not necessarily excitedly Delta okay so some useful links there's a link to
the browser tool of tunics or two after you library and as the example Ruby application I showed you before no need to take photos I will publish without that we have page - thank you [Applause]