What is a Smart Contract?
A free video tutorial from Hadelin de Ponteves
4.5 instructor rating • 80 courses • 1,072,711 students
Learn more from the full courseBlockchain A-Z™: Learn How To Build Your First Blockchain
Harness the power of the most disruptive technology since the internet through real life examples! Master Blockchain Now
14:38:58 of on-demand video • Updated September 2020
- Why this is important
- Understand the theory behind Blockchain
- Create a Blockchain
- Understand the theory behind Cryptocurrency's
- Understand the theory behind Cryptocurrency Transactions
- Create their own currency
- Understand the theory behind Smart Contracts
- Create their own Smart Contracts
English [Auto] Hello and welcome back to the course of blotching. And today we're going to talk about smart contracts. All right so what is a smart contract. What does it just for and how does it relate to Blodget. Well despite the name the smart contracts are actually programs which are run on the block chain. It's I know it might be a bit surprising that it's called the Smart contract. Well it's actually a program where when you think about it what's is a contract a contract is a set of rules that or a set of clauses that parties agree on that govern the relationship between. So it basically says that if this happens and this should happen if if the parties decide this and this should happen after this this should happen so. And essentially if you think about it then programs are the language that's the program speak the same language so in programming you also define rules how the program operates. If this then that is that and this and so on. And so it's it's not a surprise that smart tracks are actually code code that can go on the block. Now we haven't spoken about code of the blocking before we've talked about many things that talk about data on the blog share of stories about transactions on the blotching and things like that but code the blocking sounds very very interesting and kind of very Skyfire like even how can you run code on the block. So let's talk about that a little bit more. Well some of bitcoin in Bitcoin there's a programming language called Bitcoin's script and it actually allows you to code things on the block. At the same time in theory there's a programming language called solidity and illogical things for sure. And for this tutorial for this section general the difference between the two will be a very important component of our discussions or it's like ways the direction of our discussions why we going to be talking mostly about solidity and ethereal. Well the reason for that is Turing completeness of language. The thing is that Bitcoin script is not Turing complete and solidity is Turing complete. So now you might be asking what is Turing completeness What does that mean. Well Turing completeness means that if a language is Turing complete that means you can code absolutely any logic into that turing into that language. So anything you can think of any logic you can think or write on a paper or having your mind you you can code it into that language. The how long it will take for that code to run is a different question. It might take a few minutes it might take a few days might take a few years but that doesn't matter. It's about this conceptual notion that you actually can code it. It has all of the required elements to facilitate that logic. Well why is Bitcoin's script not Turing complete and so it is complete all because it is because there is one component that is missing a very important component and that component is called loops. So loops if you're if you're familiar programming languages you know what loops are. You know the for loop or the while loop that type of thing. But if you're not familiar with programming languages it's basically a loop is a way for you to tell the program to do a certain piece of code many times for many iterations. It's either you might say do this five hundred times or do this a thousand times or it might say keep doing this until a certain condition has been met and certain state has changed and then you know and then stop or break. And the reason is not because the script is not by accident it's intentional they didn't pull the script because as a rule see for adult smart contracts or programs on watchings actually run on every single node in the chain. And they they can really slow the change down so somebody intentionally or unintentionally creates a program that has for instance an infinite loop a loop that doesn't have an end. It can destroy the whole block chain or it can hide the whole blocks and slow everything down. Or even in an infinite loop just a big loop somebody might do like a very long loop a very tedious loop and so loops in general are a in programming generally are a dangerous tool if they're used if they're in the wrong hands or if they're used incorrectly and so to avoid any kind of problems and potential problems with programs like running forever or going into infinite loops because script decided not to include loops solidity on the other hand found a way to include loops and we'll we'll see how further down in this part of the course. And interesting note here is that I think I read somewhere one somewhere that I heard somewhere that the Hollywood Daryn was actually advocating for big conscript back in the day when before the theory is Agard get over because crypto includes loops and make it complete because there's so much potential for so many things you can actually create by coding or the bloodshed at the same time they didn't see much of an update on that. And so you went ahead and just created Theertham and solidity. How interesting is that. That's one of the reasons why we now have a theory and solidity and. OK so let's have a look at this on a blockade. So there is a block chain now a new blog gets added to the chain and instead of or in addition to writing transactional data and other data we're adding a smart contract. And so what does that mean. That means that everybody in our network will actually have a copy of the smart contract. So that's that's pretty crazy right. So like one thing is to have some data copied onto machine. Another whole thing is to have a computer program or you know a smart contract or program copied to your machine which is right which will run there and everybody has a copy of it. That's like it's very is an unfathomable concept and yet it is what happens. And so each node has what has the history of all smart contracts. So if there were any curious contracts they will be present on every note just because of the nature of watching you get a copy of the blog change the whole logic gets copied every machine. So that means all the smart contracts will be on every machine. Will be a history of all transactions as we know. So if there were any actions before the probably though there were tons and there will also we don't ever know. And also every node has to have the current state of all smart contracts. What does that mean. That means well the smart contracts their programs and they execute. And so once you get in and you state and then they execute something happens you get into a new state so every node will know in which state this word contract is the smart contract this is. So there you go that's smart contracts. In a nutshell I know it's like a lot to take in right away. And so that's why we're going to like leave it here for now will continue further down. And for at this point what I wanted to share with you is an example. So here we have God's providence dot org slash white paper. This is a white paper which is discusses how or explains how they're planning on using block chain in supply chains to add transparency to supply chains. And the reason for this the prayer the premise for this is that often like we biproduct said we don't know where they come from. Like you might buy coffee that you think is from Ethiopia but it actually comes from somewhere else maybe you know just like like on a on a farm somewhere in your local country or somewhere where it's cheaper to grow it. But it's more reputable to say it's from Ethiopia. So how can you tell it's from Ethiopia. It might be a sticker but is that sticker valid. Is that sticker a true sticker. Anybody can stick a sticker onto a like a packet of coffee and that's not only to do with coffee that has to do like pretty much any product that you purchase is this meat from a free range farm or is it not from a free range farm is this. I don't know. Is this is it. Are these clothes from a proper production factory or are these calls from a factory where they use like like what is it called this sweat factory work where people are underpaid and you know they're not treated well and they have to work lots of hours and so on. So and So with that the idea is pretty solid to create a great transparency in supply chains and block chain as we know is a great way to do that is the prime kind of candidate for that because of its distributed nature because tamperproof because it's so like it has all these amazing properties. And so how would they do that. They hear they explain well basically the same thing that we just discussed the brand premise for it and here they have like a diagram which talks about what it is. So we talk about certificates how they the certificates are issued right now certifiers what happens today is there's a specific and that consumers don't have full visibility and don't have access to what they want to create is as we can see this is our network you know and all of these tific is actually still on the block chain. Well to facilitate that they would use smart contracts smart contract would say. OK so when the product is sourced in Ethiopia or let's say the coffee then and it's scanned with this bar scanner if that happens then put this checkbox you know check this check box. Then once it gets on the train check this check box once it gets on the ship check this checkbox every time it's scanned because we have like the internet of things around there is so many scholars so many checkpoints that actually can be digitized. It's very easy for these things to be confirmed that it was physically scanned in this location and the smart contract will have logic coded into it which would say you know if this then that if this and that and it's not disputable this long it's like it's hard coded logic. Nobody can come in and improve it. It's a smart contract that's beautiful. And now we can see why kind of can see you better why they're called smart controls. Because at the end of the day it's like people or companies are interacting with it as a contract and it's is treating this relationship as a contract. So once certain conditions have been met certain things happen and at the end of the day the certificate is issued and you can go on line and you can have a look you know on your phone you know what like you know like take a photo they had a good one here or something. They're like take a photo and see you know see all of the details of where this product went through what was happening along the way and get all the information and then you can be satisfied or dissatisfied and purchase or not purchase said product. So there we go that's an example of using a smart contract to disrupt a whole industry and which is you know supply chains and create a lot of things there so that's prominence. Then I also want to show you if you go to medium and you search for smart contract you will get a lot of results. So I look at the number of claps that means people are reading them. So you got billed you for a smart contract before because smart contract language that compiles because. Oh interesting. So this is something for Bitcoin script smart contracts for Dummies. Bill you first theory a smart contract with solidity. You know like they are mostly for developers and they because people are actually coding on the block chain. It is the future is the next big thing. And a lot of people are writing about this and helping each other out how to learn it. So it is quite a popular topic. It's really catching on and a lot of these are very recent like end of 2007 and I'm not sure you might wish this video like like two years later so they might not be recent anymore but nevertheless smart contracts are picking up. And to finish off our additional reading for today I really liked this article smart contract for Dummies. I enjoyed reading it. I learned a few new things from it and got almost 2000 clouds. Highly recommended. Really good in the course description of course notes. It's really funny. I like how he describes smart contracts stones like as. Let's set this in stone. I love this phrase the phrase here like there's a reason we don't say let's put this in sand. Soehardi. So and then he has that example of a vending machine and so and so I highly recommend a very short article but it will give you an additional perspective on smart contracts and show you how they work from a different angle as a whole. Kind of from a just. Same thing different exploration. All right. So on that note. Hope you enjoy this book. See you next time. And until then enjoy Lachance.