Okay, welcome. That's a good start, isn't it? So we've all seen these wonderful polished presentations. This is not one of those. This is going to be one of those which will probably fall flat on its face. We'll crack a few jokes and pretend it never happened, that kind of thing. Is this working? Uh, not really. It's not? It is. It is? Hello? Yeah. Okay, so here we go. Let's try that one one more time. So, you've all seen those wonderful polished presentations that go through this clockwork. This is not going to be like that. Um, so, alright. All you guys, you work in the real world and do real things, right? And you all have insane deadlines and stuff like that. Yes? Um, take one step into the cryptocurrency world and it gets ten times worse. Which is why we will wing it at times, but we will, um, we will do what we can to give you an idea of what is possibly one of the most exciting areas in software tech that exists today. And if you disagree with me, fine. You're probably a lot saner than I am. Anyway, okay. So, I will introduce Rahman. Hello everyone. That's this guy. He is young, good looking. And then there's me, Dave. I am ancient and falling apart. Rahman runs a thing called crypto jobs list, which is a site where if you decide that you're foolish enough to want to get into this kind of technology, go there, find a job and never look back. Um, I work for a little company in Malaysia called Hello Gold. Uh, we were started to try to help people in, like the countries of this region in particular, hedge some of their savings into something which wasn't quite as volatile as the currency. Right? Now, many of you are quite young. You may not remember 1997, the Asian currency crisis. I started the business two weeks before it started because I have got an amazing sense of timing. Um, in Malaysia, people, people who found their savings went down to 50 cents per value. Right? Um, in Indonesia, it was a heck of a lot worse than that in Thailand. It was a lot worse. So with, so our CEO was, was the former chief financial officer of the World Gold Council. He used to run Spider Gold, which is the world's largest gold-based ETF. And he, he's trying to bring that same concept to ordinary people because also in the countries I've named, not like Singapore, it's very hard for ordinary guys to have access to any kind of decent investments. Okay? So that's what we exist for, to allow people to buy gold, save gold. Um, you know, so if the currency tanks, you've still got something of value. Right. That being said, um, we are, we are. Yeah, we are. We are. We did. Raman created a telegram group. Um, there you go. Solidity workshop on telegram. If you, if you, if you have telegram, you join into that. Um, at some point we will ask you to send us information and we'll send you back some test ether for various networks and things like that. So when you get there, when we get there, we'll get into it, right? Yep. Enough of this sweet talking. Let's get into the business. Um, so here we go. What we're going to try to do is Ethereum smart contracts from basically zero to deployment in approximately three hours because we've wasted the first 30 minutes waffling on. Yeah. Okay. Here we go. So the roadmap, what are we going to cover? Hopefully. Right. First one. First five minutes. What's the blockchain all about? Who knows what blockchains are? I thought so. Good. Okay. Cool. Um, where smart contracts come in, um, this is like where Ethereum is really strong, something called smart contracts. If you haven't heard about them, you will soon. Um, then decentralization and a whole lot of technical stuff, you'll see it when we get to it. Don't worry about it until we get there. Right. So, so what we expect you to learn, what these Ethereum blockchains about, a very, very slight draft of the Suzy programming language, not much. Um, really, you know, during this, we'll throw out loads of random things which will, which aren't in the notes. Um, we're going to try and point you to some resources, um, one of which is going to be our telegram channel. You can ask questions. We will respond. Maybe. Um, why security is important, possibly a lot more so than in, you know, anything that you've worked on before. And the biggest thing we've got is that you get enough to get you interested to find out the next step. Right. That's the important bit. Because for a lot of people, like you take that, that first baby step takes a lot more courage than the next big leap. Right.  Once you've got an inkling of what you can do with it, you know, you then start thinking, well, I better allocate a bit more time. So that's where we're going. So basics of a blockchain in five minutes. I have a strange sense of time. If I get it wrong, don't hold me to it. Right. A blockchain is a load of signed transactions stuffed into blocks, which are signed and linked to the previous block. So that everybody agrees that it's correct. That's it. Was that five minutes? No, okay. Sorry. Okay. So what's the transaction? Well, there you go. That's a transaction. Right. Yes. I probably don't get that back, do I? Never mind. Right. So from me to Rahman, I send him a coffee and I tell him why I'm doing it. Because otherwise you might fall asleep, right? Fair enough. I've got coffee. Okay.  Yeah. At the end of the day, he's got one coffee, one coffee more. I've got one coffee left. And we keep on doing this, me to you and everything, right? And at the end of the day, we all know how much coffee everybody's got, as long as we start at the beginning. We probably have to have a transaction make coffee in there somewhere. But these are transactions, right? So, yeah, this is like an accounting ledger. Yes. So what's the big deal? Well, the big deal is that... Well, the first big deal is that that sounds actually assigned. So do you know what digital signatures are? I see a lot. Okay, let's have... Someone shout out, no. No. There we go. So you don't know what digital signatures are.  Because you never store passwords in the plane. In the plane, you store an MD5 hash or a... Or a shah, whatever, hash or whatever, yes? Yes. Good. Right, so if I take a hash of that piece of data, assuming I've got a good hash function, nobody can mess with the data, right? So now I've got something that's foolproof, right? Except for the fact that if you wanted to change the data, you'd change the hash as well. So it was still reliable, yes? So it still doesn't work. So the next thing you do is... Okay, so... But otherwise, if you couldn't mess with the hash, the hash would prove the validity of the data, right? Because you can recompute the hash on the data. The data is valid, yes? Right. So... Yeah, because I give you the piece of data, and the hash, you recompute the hash, do the two match, yes? Wonderful. Right. So, the second part is we encrypt the hash with the sender's private key. Do you know what encryption is? Kinda, right? You know what public key, private key is? It's the thing behind all the SSH technology and that sort of stuff. It's a lot of complicated mathematics. I take a piece of data. I do a mathematical transformation with one random number. From that random number, I can derive a second number that you can use to decrypt it, which I can tell anybody. That's a public key. Or you can encrypt it with a public key and I can read it with a private key, right? So in this case, if I encrypt the hash with my private key, and I let you know what my public key is, right? In this case, it will be the sender, right? Because I use my address, which is my public key. So if I say it from my public key and I encrypt it with my private key, anyone can check that transaction is valid, right? Because my public key is part of the message in plain text, right? So you can see my public key. You can decrypt the encrypted hash to get the correct hash and you can prove that the decrypted hash matches the hash that you would compute for the data. That's the digital signature. There is no magic to it. And when we talk about cryptocurrencies and all that stuff, it's the only place that cryptography takes place anywhere in anything but the most advanced blockchains, right? So it's all about digital signatures. If that goes over your head, read about it a bit. Otherwise, I won't hit the five minutes. But that's the very basics, right? Otherwise, think of it as a signature. But it means that nobody can forge a transaction from me. Right? There we go. Page two. Right, we stick them in blocks. How do we stick them in blocks? Well, I just assembled them into some kind of an array type structure, some kind of a database record. And I, who put that block together, put a link to the previous block and I sign the block. And if you put one together, you do the same thing. You sign the block so we know who did it. Right? So if you have got this block, you can go to the previous block, check the previous block is valid, go to the previous block and so on. There's a little bit more complicated stuff so you don't actually have to re-evaluate the whole blockchain. Right? But from this and that block, you can tell the entire blockchain is valid. In a manner which everybody agrees upon. And I'm sure you've heard things about how one blockchain transaction costs about as much as it does to heat the entire United States for a couple of hours or something like that. Right? The blockchain consumes about as much as the state of Denmark or something like that. I'm going to skip that. The method for having the consensus is, let's call it magic for a minute because I think it's not important for where we're coming from. But the technology is there so that the entire members, everybody, all the nodes on the blockchain agree that the same chain is valid. So that if you put on one block, you put on another block, right? You both try and add something to the blockchain. There is a means of arbitration to decide which one is valid. And then you try again to get the next block. So now we have a... I'm sorry, Mike, I'm walking around and making your life difficult. Okay. So now we have a means of ensuring that our ledger is consistent, agreed by everybody. Now once we have a ledger that agreed by everybody, we know how much everybody's got, right? There, blockchain, five minutes. Was that it? Yeah, that's your five minutes. Cool. Okay, so we're the smart contract to come into this because that's the bit that makes Ethereum worth doing, right? Because what I've just discussed is kind of like the technology behind Ripple and Bitcoin and all these other things, right? Where really all that you are talking about is a ledger system that is storing value, right? Bitcoins and things. It's not a real Bitcoin. Of course, Bitcoin is out there in the... So what's the difference, Ethereum? Well, let's have another look. I said I'm sending around a coffee because otherwise you might fall asleep. He doesn't drink coffee. He's one of these new breeders. I suppose most of you are this new breeder program who don't drink coffee. Never mind. Now, so that is a whole load of bytes, right? It's a data field. And those among you who have had more fun in programming would think, but hang on, it's a data field. We could do something with that, right? Because that's what you do. I mean, an HTML or a web page is only a piece of data but a web browser interprets it and does something fancy, right? And so on, right? So, yeah, maybe we could do something with that, like interpret it as bytecode. That's the thought, right? Now, once we got to that, we started Ethereum where we said, okay, if I send a transaction to you or you or you or you, it's a transaction to one of you people. Normal. But what happens if I send it to address zero, the address that nobody can actually own, then what it does is it takes that data and it stores it and it says and it gives it an address and says anyone can send anything they like to this now.  You know, much like, you know, which basically is interprets the bytecode, right?  I mean, typical interpreter virtual machines out there would be like Microsoft.net framework, Java compiles down to bytecodes, which is what makes it portable, right? So, once you've done that, you have a smart contract.  You can send instructions to your smart contract. You can send value, right? So, I mentioned before that Bitcoin, you know, is just a value, right? So, I send you point one of a Bitcoin or something like that. You can send half a Bitcoin to someone else. Ethereum also has its own native currency, which is Ether. That's how you send value. But you can also send messages in the data. So, the first thing we talked about was me putting a contract out there with a program encoded in the data. The next thing I can also do is send parameters like a REST call where you put the contract address would be the www. And then you've got the path, which becomes the method name you're trying to call in the contract. And after that, you encode the data, right? So, we can specify which function we want to call and we can send it parameters. Yeah, go for it. Now, code on the blockchain can be seen by anybody. So, you know, if you've been happily setting up a Node.js server, you're used to the fact that nobody can see your code unless you publish it on GitHub, right? Code on the blockchain. Everything on the blockchain can be seen by anybody. Well, at least anybody knows what they're doing, right? So, if I publish... I mean, the first step is I can publish... When I publish a contract, a fantastic little thing called a Block Extruder, Ethascan, would allow you to see the creation of the contract. It will say, this is the code, which is not that fantastic. But, I mean, that is the source code of a contract. I can't remember which one, but that's the source code of a contract, right? That gets submitted, it becomes a contract, and you can send transactions to it. And people who communicate with it. Oh, sorry. You can verify the source code, of course, because once you put it on the blockchain, Ethascan allow you to upload the source code, which it compiles with the same version of the compiler, and it makes sure that the output matches the code that you sent. If it does, they publish the source code. So now, anyone can see your source code. This is a token, and it's on the blockchain somewhere.  There is no privacy on the blockchain, right? Unless you build it in. So, I mean, of course, you can put encrypted data on there, which only other people in the world how to un-encrypt it will be able to get hold of, but people can see that you put it there. They can see who put it there, right? So these are transactions on the blockchain. It tells you they've got block numbers you've got when they were posted, who they're from, who it was sent to. How am I doing for time? Good, good. I've still got a few minutes left, yeah? Go first. Fantastic. Okay, so people refer to blockchain environments as decentralized, trustless, right? You build your Node.js application, right? Everybody has to trust you, right? If you do an online banking application, everybody has to trust that it works, that it's not going to steal your funds. Nobody can verify it unless you give them access to the source code. And since they can't see in your source code, they see inside of your server, they also have to trust that the source code you've given them is the same source code you've currently deployed. On the blockchain, you can see exactly what's been deployed. You can see every single transaction. It is designed to create systems where people can interact because they know what they're interacting with. They know how... So I can see your source code, I can see your contract. If I want to, I can get someone to audit that contract for me to prove that it actually does what it says it does. And then I can interact with it. Of course, normally I will trust that your contract is okay. Sometimes they're not. So what is more to the point? Where is that contract on the blockchain? Whereabouts? Geographically. It goes like, you know, you've got yours on a Node.js server in an Amazon center somewhere. Which will they trust they're looking after somehow, right? We trust that all of the services we use will not go down. They might get labbed. Yeah, well, I did something worse than that. Anyway, so the point is that you have central points of failure. No matter how hard you try, you have central points of failure, right?  If I deploy a contract to the blockchain, it is on every single Node of the blockchain. So it's on this computer here. It's on computers in Kansas, Indonesia, and Mexico, and Hawaii, and pick a country. Yes, right? It's all over the place. It's on thousands, if not millions, of Nodes by now. It's auditable. If you want to interact with my contract, you don't talk to my server anymore. You talk to a server near you. You talk to your own notebook. Your notebook communicates to all the other ones. It says, this is what I intend to do. And as long as it's a legal thing to do, it will get shared amongst all the other Nodes. Now, there are multiple reasons for doing blockchain. As the long-awaited blockchain company know, one of them is to make your company sexy for investors, even though you do nothing to do with the blockchain so people throw money at you. But since we're all technical people, we walk away from such things, of course, and we do it because it's fun. So, multiple actors, multiple people involved in it who do not necessarily want to have to trust each other. Or who wear... Where it's easy if everything's out there so everything could be audited without any problems. Some conflicting interests. So it would be no... There's no point, say, Zool and me setting up something to take your money and say we would give you something in return because Zool and I are best buddies. But then, if we've got a few other people involved... So in the case of Hello Gold, obviously there's us, there's our vaulting agent dealing with the gold. We allow you to pledge your gold to take loans because also we find that in Malaysia 75% of all loans get rejected so we say if you've managed to save some gold you can use it as collateral for a loan. So we've got the loan party. We've got digital wallets that we work with like Cellcom or Axiata, one of the largest regional telecommunications. We've got lots of people involved in our system now. So we have multiple actors, some conflicting interests. So for us, it's good for us to get everybody having loans approved but of course AON credit wants to make sure that the people have got enough gold and it can be locked up until the loan's paid off, right? So there's a conflicting interest there. And of course there have to be some common goals otherwise nobody's going to use it. So that is a sensible reason for doing it. If there's only one person involved in it, if you are going to be saving records for your own personal use, you can't see how anybody else would be interested in it and even if they are, you could just stick it up in a blog post. There's no point doing a blockchain, right? If only one person ever interacts with it, it's a database, right? So now we've got this bytecode and nobody, oh not nobody, there are maybe four or five people out there who are even further off into the land of praises than I am. So very few people write pure bytecode, very few people write assembler, they all use a language. Of these, the languages are Solidity, which is inspired by JavaScript. Viper was something which came from Python which they are now getting rid of because it was hard to make it secure. Viper is something which is new and unstable. LLL, lots of people have got their different names for it, low level language, lovely little language, I don't know what it stands for, not many people use it. People can use assembler, the Ethereum virtual machine is a stack machine. Most people use Solidity, which as I say is inspired by JavaScript which should get you all taking a big sigh of relief, because you've all got an advantage here. So we're going to talk about Solidity. Solidity is used to write programs or write contracts. Contracts are a little bit like objects, as in object inheritance, C++ or Java type thing. I hope most of us have been into other areas because I believe that JavaScript doesn't have objects quite like that, does it? You'll have to correct me here. Sorry, I have done JavaScript a few times over the years, but my mind has moved on. It has classes. It does have classes, close enough. Good, right. So think of it like a class, right? So a contract is a bit like a class. It has a constructor. We've got constructors. Yeah, cool. So you've got constructors, parameters. You've got functions that do things. You've got functions that don't do things. They just tell you something. Yeah, what's the price of tea today? You don't actually change anything to get the price of tea. You just, right? We have persistent state data, which you must have, right? I'm sure. If anybody can, if I'm saying something and you can think of the right word in JavaScript to describe it, shout it out, right? So what's the state data for a class in JavaScript? I have two functions. Someone calls the first function. They change something. And the second function actually can still see that changed data. What would you call that? Instance data. Huh? Instance data? Yeah, OK. So state data is instance data in JavaScript, right? And of course, you've got local variables and things which get thrown away the moment you leave the functions. We can also talk from one contract to another, just like you can have one object call another object. There you go. So it's a language that's not entirely unlike JavaScript. And if I show you that, you'd say to yourself, this is JavaScript, right? Yeah? Yeah. Good.  Laptops. Laptops. If you can't hear me, tell me to talk up. We should do like a few minutes Q&A. Are you guys following questions so far? There have been a few questions in the chat. Oh, yeah, yeah, yeah. So let's leave the caveat page, shall we? What's the telegram? What? Telegram. It's like t.me slash Solidity Workshop. Let's back it up all the way. Yeah, go all the way back. There you go. There you go. There's a bit of a tricky one. Yeah, let's do it like 10 minutes. Yeah. That's coming real soon. Yeah. You're on the training? Anybody else got anything before I... No. Come on. Come on, guys. This is like a Singapore classroom, isn't it? Nobody asked any questions. This probably cannot make any sense at all. We will now try and find exactly where I was. So, where were we? Where were we? Did you guys manage to get to the telegram group? Shall we get a few more minutes? What would be good as a cognitive example of what you're doing with these things? Okay, yeah. So, we're going to get into it. Real soon. A bit of a theory right now. Just after this page here, right? So, as you can see, Solidity is exactly like JavaScript, right? Except for the... Except for the semi-colons. Yeah. Actually, I forgot the semi-colons. There should be a semi-colon. There's quite a few. Yeah. Right. I didn't test it. I normally test my code. I didn't test that. I'm very sorry. Okay. Except for the fact that... Okay. Contracts. What do we know about contracts? Contracts are like classes. That's their gas. Now, that's the fun one. When you interact with anything on the blockchain to change anything on the blockchain, you have to pay for it. It does. The blockchain is stored on multiple computers across the network. There are computers making... There are people out there making sure that the network... But the blockchain stays consistent, and they're all doing a lot of work to do that, and they get paid for it. So, if you want to interact with a contract in such a way that it changes anything, whether it's just me sending Ether to somebody, or whether it is me changing data before something like that, have to pay for it. Because it goes into my local node. My local node shares it across the entire thousands and thousands of nodes, and they all agree and say, yep, that's fine. Or they say, no, you can't do that. So, you have to pay for it. You pay for it in Ether, and it's called gas. How much you pay for a transaction depends upon, number one, how much work is involved, some things take more computing power than others, or more storage space. So, you pay more if you're going to use a lot of storage space. You pay more if you've got a lot of computation. And the second thing is an incentivization thing, where you actually decide how much you want to pay per unit of gas. Now, you do that because if you're putting a transaction out there, someone has to mine it, and the person who mines it gets paid the transaction fees, and if you're prepared to pay more, you can get priority. Right? So, you pay for every transaction. The types are a bit different. We don't have integers, but the most common things in Ethereum are addresses, which is 256-bit value, and a 250-bit, 6-bit unsigned integer. I don't believe they even have signed integers, do they? Or if they do, I've never seen anybody using them. The chief currency is the 256-bit unsigned integer. Now, the closing points. Now, the closing point numbers are usually dealt with as 256-bit unsigned integers, where the last 18 decimal points are regarded as fractions. Right? They are talking about at some point they might have fixed point numbers just for fun. Sorry, Mike. So, every transaction, if it succeeds, can interact with events to log information that you can see. Normally, if you do something, it's the only way you can find out what goes on. You make a log, or you can examine the state of the contract. Sorry, I did mention when you interact with a contract, there is the other thing you could do. You could just, like I said, if you want to know the value of something, something that does not involve changing state, you don't need to query the whole network. You can query a local node. That is free. You don't have to pay to make a query. You only have to pay to change things, because your node should be in exactly the same state as everybody else's node, so you can query. The state memory, the persistent memory costs money in gas. Recursion, not advisable. We all know that all programmers of what have any funds start thinking about recursion. Please, not in solidity. It's only got a limited stack size to start with. Maybe you can speed up for this section, but we're going to go into practice section. There are a whole lot of other things. A lot of it is about the key ones. You have to specify if your contract is going to receive Ether. A contract that you do not specify to receive Ether, if somebody sends Ether to it, it will reject it. What else is key? This is probably the best one here. Multiple values. You can return multiple values. Can you do that in JavaScript? A function returns two values. Oh, we got that. Okay, fine. It is all right. You can throw the last very important thing. You can at any point in the execution of a function, the function can say, if this happens, roll back. Roll back the entire transaction. It doesn't matter what's happened, how much information has changed up to this point. If something happens, throw it all away. Do not change anything. So that you have to require or assert or do a revert. Okay, let's go. Where are we? Okay, so things required for a contract. The first line of your contract will say that it will specify the solidity version you're using. It has to be above a certain version. The latest version so far is 0.4.19. So if I put that as my top line, I can't use an older compiler to build it. You can have includes. We know about includes, right? You specify the contract like specifying your class. You do your state variables. We have modifiers. Modifiers are conditions that are required to execute a function. So only the owner of the contract can execute this. Or you can only execute this if it's after January the 26th. Things like that. What's happening? That means... Oh, fine. Sorry about that. We should be on silent. Imagine it's on silent. We'll look at the rest. I think we have most of the things in the next few lines. Right. Now, at this point, I'm going to take you through writing a very simple contract. Or at least I'm not going to get you to write it. If you look on Github Gists, there is a contract called Bygold under Golden Dave on...  And you open a browser tab, another tab, preferably, to remix.etherium.org. I'll share the link in the Ethereum chat. That is cool. Thank you. Now, if you do that, you have an interactive environment for messing around with contracts. And it allows you... So what I'm suggesting that you do is you create a new tab in remix. You copy the code from the Gist and stick it in there. And then we can all be on the same kind of page. Right. So I'm not going to talk about all of this contract because I've actually got two contracts there. One talks to the other. I'm not going to talk about using the second one. Just the first one that you can play with it. So the second contract is designed to interact with the first one. That's all I'm going to say there. Are we... The information is in the thing, right? Yeah. Okay, so if we can go to the next page then... Right. Now, one of... Remix is designed to not only work in an interactive mode, it can also talk to the blockchain using something called Web3.js, which Roman has promised me he's going to tell you about later. Right. But at the moment we're going to work in an emulated environment using the JavaScript VM. So on the settings page you will see... Is it settings page? Sorry, on the run page you have the environment JavaScript VM. And you have got about ten different accounts. Yes. What, sorry? Oh sorry, okay, five accounts. Enough to play with anyway. Now, use the JavaScript VM, use the first of those accounts and take the contract exchange rate and click... Now, you've got to give it two addresses here. Right, so I think I'm going to have to get out of my present mode and do a bit of showing. How are we doing so far guys? What are the questions? I did... Did I warn them it was going to get difficult? You just run through that from the top. Okay, here. Yeah, so just... Go ahead. You do the talking, I'll do the doing. You try to explain what I'm doing, because I haven't... Cool. So we're... Remix is like interactive environment where you can interact with your... That's not what people really use in like the day-to-day engineering or saluted engineering work, but it's like a really nice interactive environment where you can like really quickly test ideas and maybe debug contracts as well. So we're mixed up a theory of that work. Everyone loaded it? Raise your hands who loaded this editor in their browser, Ryan. Okay, excellent, excellent. So you've got this tiny plus here, you can add a new tab, I'm sure you've figured that out by now. You add a new tab, you paste the code into this tab. On the right hand... Everyone done that? Everyone entered the copy paste that they just... Once you've done it, you may need to compile it by clicking upon this button in the compile tab, start to compile, and it all goes well, it just says, okay, groovy, we've done it. Anyone having a... Is it not compiling for anyone? Not compiling. So, can you have a look at the guy whose code is not compiling? Yeah, it's all good. You're good? Yeah. Yeah, it's okay. Right, so we go to the run tab, there are various options here. Injected Web 3, or talking to Web 3 provider, that means you can talk to a node on your own computer. Can I zoom in? Yeah, I can do my best to zoom. Here we go. How about that? So, you have got source. We're going to use the JavaScript VM. Later on, Rahman's going to talk about using Metamask, which would be Injected Web 3, but at the moment, we'll stick with the JavaScript VM. You have got five accounts that you can use for sending transactions. Each of them has got 100 virtual Ether that you can pay for things with, all right? Is that clear, versions? So, we start with... We're going to start with the first account. Let me just clear that one off. Right, so we're going to create exchange rates. Now, under create, it says there are two addresses, which, if I was going to come over here a bit, you will see under exchange rate, it has address gold source, address cash source, right?  Right, sorry, ignore me. Right, here we go. So, I need two addresses. So, what I'm going to do is I'm going to be using three of my addresses here. I'm going to set the second address to be my gold source, my third address to be my cash source. Right? Because it wants three different accounts to interact with it. Now, it's a bit finicky. It wants addresses and long numbers to be inside quotes. So, the way I normally do that is I put my quotes in first. I'm then going to put in the third one, which is that. You can just copy the address. You can paste it in.  You copy that. You paste that in. Right, so I've got two different addresses. The addresses are 0x14, 4b. Right? Okay, then I click the create button. And it creates the object for me. So, basically, when you hit a create button, right, are you guys there? No. Okay. So, it basically creates a contract within a DM, within an in-memory JavaScript that compiles it into bytecode. And this thing is, what you see in this area is just like interfaces that it can interact with with the contract.  Later on, we're going to go into like, just like subline text and I'm going to show you guys.  And it's all going to make sense, hopefully. Right. So, you can examine variables, the gold source. This was the address I created. This was the address I put in the first one, 014. You can see the cache source down there. Okay. You can see the two variables I put in the constructor, the gold source and the cache source. You just click on these two buttons and it reveals the value. So, the blue buttons are either looking at the value of a variable or it is calling a constant function that changes nothing. All variables in Solidity are initialized to false or zero depending upon what the type is. Right. Gold price in here. Let's have a look at some of the code for a minute. We'll go back to this in terms of what I was saying. The first line tells it that we are contract in Solidity, compile it with 0419 or higher. The second line declares the contract. You can have inheritance, as I've said before, in which case you say exchange rate is something else. But if you're interested, you'll find that out. Right. I have got two addresses which are public, gold source and cache source. Now, the important thing about this is that all public variables have getters created for them. So you can read those values. So, when you're talking from one function to another, you never actually interact with the variable, you interact with the automatically created getter. Right. I have got two maps. Okay, let me tell you what I'm trying to do here now because we've launched the contract. So, this is just an example from the kind of stuff I do because I play best with the stuff I'm familiar with. So, Hello Gold buy their gold in Singapore from Pulleys Star International. We're on Northbridge Road. They're a decent vaulting agent. But we're selling in Malaysia. So, I've got two things that affect the price of my gold. I've got the price I paid in Singapore dollars and I've got the exchange rate between Singapore dollars and Malaysian ring it. We've just opened an office in Thailand which in the course of the next few months will be rolling out the product into Thailand. So, now I'm going to need to have the exchange rate from the price of gold in Malaysian ring it and in Thai Bart. This is designed to allow me to put in the two pieces of information from two different sources. Right. From the fellow who's checking out the international exchange rates and the fellow who's putting in the gold prices. Right. So, I have got the first two lines, gold source and cash source. These are the people that I'm going to authorise to put in those transactions because I don't want you putting in the fact that gold is one dollar a kilo and then quickly buying gold. Right. I mean, I know I'm mean but that's mean. And similarly for the person putting in the exchange rates we don't want you putting in that there are you know that one Malaysian ring is worth 5,000 Singapore dollars. That would have the same effect. You get cheap gold. Right. So, Okay. So I'm going to have because there are multiple currencies I use a mapping. Now a mapping is an associated array.  Right. So I can use like NYR for Malaysian ring it to give me one value in the array. Right. Other terms are an associated array. And the same thing would be cash ready which I'm simply using to say that that value has actually been set and is valid. Because I don't want you trying to do a transaction with a currency that hasn't been set. Right. I could have done structures but I didn't. Okay. So when we created it we had the constructor. I passed in gold source underscore cash source underscore which I put into those two values. Because I did that you can click on the blue buttons and see those values. We got a function called set gold price which is a public function. Anybody can call it. Which doesn't sound right because I just said only the gold source can call it. Right. But the second line says require message.sender is equal to the gold source. So if anybody else does call it the second line will cause that transaction to revert. Meaning it will stop execution. Any changes that you might have made which in this case I'm not will be unwound. So when you get past that hurdle you set the gold price and you set the flag saying that the gold price is now valid. Because I don't want anybody calling the contract until both the gold price is valid and their currency exchange rate is valid. For the cash rate well the sender has to be the cash source. Same thing. Right. The gold person can't set the cash price. The cash exchange rate. And I set the rate which would be for Malaysian ring it about three. Right. So I made entry number the entry of MYR in there to three. And I set cash ready to true which means now you can talk you can get a Malaysian ring exchange rate. And then we have the function to get the gold price. Now this one's a little bit different it says public anybody can call it. It is view. Now view means it accesses state variables but it does not change anything. So it's a constant function. Now a constant function as I mentioned earlier you can call it from any node in the network you do not need to communicate anything to any other node in the network to know that you've called it therefore it's a free call. It's still hot. These are amazing. Made in Malaysia. Lovely coffee. Okay. Right. So here if cash ready currency return. Right. Now what does that actually do? Well what it does is is a bit you can't see which is the right hand side. It returns the price and an okay flag. The price is before you change it it's initialised to zero the okay flag is initialised to false. So you can't. So if you have never initialised the exchange rate it just returns which means it will return with okay being false. If the gold is not ready it will also return so okay will be false. Otherwise price equals cash rates times currency divided by one ether.  Well obviously you can get the bit where you must buy the cash rate by the currency right? By the gold price. So three Malaysian ring it times fifty Singapore sorry three ring it to the sing dollar times fifty sing dollars to a gram. I can give you a hundred and fifty ring it to a gram. What is the divide by one ether? No it wasn't a rhetorical question. What is the one ether doing there? No? No, no. Anybody know the exchange rate from Malaysian ring it to Singapore dollars? Sorry can you shout that one out that sounded good. Three point what? Two point seventy two point nine eight three point zero seven. I'm just thinking the exchange rate could be zero. Yeah but it's got decimal points in there somewhere right? What is the price of gold? One gram of gold in Singapore dollars. Oh I've got no idea it's probably I like it used to be about fifty point three two seven black. We've got decimal places in there haven't we guys? How do we represent numbers in Ethereum? Because both numbers are multiplied by ten to the eighteen. Right so if it's fifty dollars the actual number in there is fifty times ten to the eighteen. The exchange rate is three times ten to the eighteen. So if you multiply two numbers both of which are the whole number multiplied by ten to the eighteen you're going to have to divide by ten to the eighteen to normalize it back to a number with eighteen decimal places. Yes? No? Maybe? Right because if I put a hundred to represent one so I want to put one point one it's a hundred times a hundred which is one with four zeroes after it so I'm going to have to take off two zeroes afterwards to make it equal back to equal one wouldn't I? Yeah? Bigger. So that's why I'm dividing by one ether and at the end of that I say okay equals true so that when I return we know it's valid. Does that work for you? No. Cool. No. I don't get why what would be the result of dividing by one ether? Because one ether one ether is one followed by eighteen decimal places. Okay. Yeah sorry so one ether is all one ether is just like everything else one with eighteen decimal places so it's just a convenient way of saying one and followed by eighteen zeroes. Okay. So there we go. I have a function that gets the gold price and if we are incredibly lucky it might work. It ought to work. It worked when I was sitting in the car parked waiting for Zool to get back to his hotel because he'd been off sightseeing. Oh by the way, sorry did I introduce Zool at the back? Zool is my colleague from Hello Gold. No no go look at it. Right can you please all join me and say just one thing to Zool. Happy birthday Zool. Happy birthday Zool. Thank you. Right. Okay good. Right so we've done that we've done that. What's the gold price for the type? Well have we done Tide Bart? What's the gold price for Tide Bart? Let's have a look. T. H. B. Close the quotes. Get the gold price. It's not okay is it? Because I never set the... Actually I've never set anything for the minute. Okay so let's set some values here. And I'm going to be incredibly lazy we're going to choose those things that I originally went up with. So the gold price is going to be 50 followed by 18 zeros which I always do is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 put in the quotes because it's a big number and for some reason they like big numbers in quotes. Take out all the spaces. Last one. And so what's the gold price at the moment? Gold price is zero. Set the gold price. And it says you've got all of this, all of this hang on somewhere on the left hand side look at it in a minute. It kind of succeeded but you can prove it succeeded because you can check the gold price. So now I've set the gold price in this thing and every single node on the Ethereum network if this was a live contract would know that the gold price is 50. And I could set the exchange rate for Malaysian ring it there's my double quote there 2, 3, also followed by 18 digits 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 followed by its quote we call set cash rate for Malaysian ring it and what did it say? It said I did something wrong. Ah! And the reason I did something wrong was I sent it from the wrong account because up here are the accounts I can send from I need to be sending from the cash source which is the one with 4B which is there so it says here that the transaction failed if I try to send exactly the same transaction from that account if I'm very lucky it says it succeeded and if I ask it for the Thai Ba price it will say failed if I ask it for the Malaysian ring it price if I am incredibly lucky it will tell me the price is 15 ring it no, 150 ring it per round of gold right? now that is an insanely simple example and that would be just a very small part of a big hole that you put together sorry, zoom which bit? this side zoom it why not? oh yeah that one is that the bit you wanted? zoom in there's a plus or minus do you think that plus or minus doesn't it? no I doubt it it does but it wouldn't do it that way I'm on the wrong side aren't I? what did I do there? you just like enter a... no it's there it's okay just do that it comes back, yes take that back up and let's just do that there you go is that okay? unfortunately they don't make these draggable so we have looked in here using some of the principal things that are important the first one is controlling permissions by the address from which the transaction is sent the second one is the various data types including the associative array right? it's basically it's a sparse array but you got maps in JavaScript haven't you? it's the same thing right? um... are there any questions at this point? I think a few people are still playing with it the great thing about this environment is it's just like JS Fiddler you can change something you can see the results instantly one thing I've noticed is a lot of people only make what is absolutely necessary public I tend to make everything possible public because you never know whether you're going to have to debug something you can always work out what the variable should be no point hiding it just make it public so that it's there and you can see it clearly how are we doing with that? is everybody happy? so what exactly is the difference there? why would anybody put something as private? you put functions private it's very essential to put functions private the moment you put something on the network which holds data which is important that holds ether you have to have private functions otherwise people can get in there and they're going to leak your ether public functions can be invoked by anybody private functions can only be invoked by other public functions can only be invoked from inside for variables in my view it's not terribly necessary unless you're absolutely confident everything works well if you've got something fully debugged and everything else you can set things to private just because it makes the interface clearer because you can see on the right hand side I've got everything listed there you don't want it clustered by rubbish with 500 different variables are we ready to move on from there? Ramon should be nervous because now it's up to him he's still doing something so do we have any other questions at this point? obviously at this point I've got something Mickey Mouse and you say well why wouldn't I do it on a centralized server the first thing is if I want my system to be coupling in the auditable and I want to have the different actors I don't need to give them special access to a particular server they can all interact directly with their own local nodes which gives them access to the contract second one is when you want massive adoption you're having client you can have a web client but the web client can talk directly to the net without even having a back end which is where Web3.js comes in and that is like a very brief heads up on it before we start Web3.js is a way to do all of your interaction including signing of transactions inside your browser and the only time it leaves your browser is as a signed transaction and it goes either into your local node on your machine or through an HGT port which just puts the signed transaction into the transaction port now I'm quite sure that you have heard for example about the ICO initial coin offerings one of the ways that startups are raising huge amounts of money to develop products with that is done on the blockchain people send ether to the contract they get something called a token a token is just a value in an associative array basically with functions allowing you to transfer those tokens so you can sell your tokens and stuff sorry guys how are you doing Revan I think it's helping people so he doesn't have to come up and do the next bit can contracts be upgraded after they've been launched okay now here's the fun bit can you update a contract once it has been launched from what I've said so far what do you think the answer is no kind of no you can replace them at least you can't replace it you can put in another one so if I have this contract with a pointer to the contract I'm supposed to use so the first contract becomes like a portal you can then change the second level contracts I can make it so that a contract can be stopped from working all together one of the things up there is self-destruct I can actually remove a contract from the blockchain completely by issuing a self-destruct function but I cannot change anything that has been written onto the blockchain which makes the company who put name email address and other information of their clients onto the blockchain as they registered them in plain text rather you're responsible because that information is going to be there forever so you can upgrade contracts if you build it in but you have to design it because the old contract will always be there so if you were to look for example if you have a contract where somebody made a mistake sending wrong information to it it's always there so yeah so in your set goal value function if you have locked where the company is this one is actually correct you don't need to set that value what if you want to do something like the audience bank where everybody is publishing their rights or something like that how would you get around the idea of trying to have it free publishing their views and aggregating those things having a contract that you don't get the information okay the blockchain blockchain cannot talk to anybody because the price how about logs because okay I haven't put any in here to wish me but if I had put an event in there you call an event it looks like a function but instead of saying function it says event when you call that the only thing it does is write a log that gets stored with the transaction call if the transaction succeeds you can have code written in javascript using web3js or written in Go which is my favourite which monitors your contract or a particular event so you can have a machine somewhere that sees that something has been called to make that event happen and then that computer when it recognises that it can go and do something and push the information back but one thing you have to understand if you do that is time elapses right in that time you do not come away to go outside the system get information get it back so you can keep using it it is one setting up a very digital place at some point in the future it will come back but you will be looking for business in the future just as a programme you just have to think of ways of having an active data push in the transaction or maybe each person will put in their own exchange rates so they will have these built in solar the core so right now here you have like a thousand right I'm on a tap push a tap on my arm that after turns so we've done that we did that we did that you sold that the gas if you send it into the contract if you're sending literally that is like a very brief introduction to it anybody can query it certain people will write information you can have copies that anybody can send and so on now at that point I'm going to leave it because I think if you think there's something interesting you might start taking the journey at this point as with everything else Google is your first best friend unless you don't like giving information away this is duck duck go right now is this guys turn yeah your turn mate can you come to T5 can you go to T5 how are you guys doing so far everyone's following having success failure who's compiling and everything works for them raise your hand who's having a problem with creating a contract or setting values always confused about disclaimer everything here is very confusing when I was learning it was super confusing it's okay to be confused raise your hand and ask questions all questions are good back there I think there was you just need to address this you just need to address this it takes two addresses if you want to address that it's able to set the cool value in another one what does that actually mean what does that actually mean okay so the question is what's the addresses mean so like when you're hearing blockchain there are addresses like the public addresses it's like a hashed address for a public key basically you have a private key that controls and anyone can verify that you signed a certain transaction, a certain interaction on the blockchain by looking at your public key so the address can either mean a private individual you have a private key to this address and you can just sign to these actions like you want to send someone to another address or to another contract and contracts also have the same public addresses is that more or less it's not a unique address for persecuting new it's a unique address that corresponds to a private key so you're able to change your own private key set of private keys and they're unique if you lose the private key you lose access to your to your public key basically you cannot move your funds sorry I had a question you had comments okay is it confusing, not confusing what should we explain better a pair of keys is basically they can account when you hear the rumors about people losing a ton of money on Bitcoin that actually means that this value is still there on the blockchain it's recorded there but it's attributed to a public key that someone lost the private keys to so they cannot move this ether or Bitcoin out does that make sense yeah basically address is a user but it can generate an infinite number of I think close to infinity this number of key pairs doesn't make sense not necessarily, you can create a Brazilian number of addresses it's just like a push function so you generate so the question is for each contract you generate an address when you publish a contract to a chain whether it's your own local chain Ethereum network the address is being generated for you by all the nodes I don't remember exactly what's the process of generating this address but I think it's based on the time and the block number and the amounts of that block in which the contract is being mined it's a bit more or less it's unique it's more for scientists but the probability of collision of addresses is tending to zero it's pretty impossible questions so forth shall we go into one last tough technical question I've got a few hats, who wants a hat? who wants a hat? ok, question it was an easy answer does it come in black? no, it doesn't come in black I've got more it's a transaction I've got more what we plan to do now is basically ask questions answering them and then we'll do a bit more hands on work and try to link it to our experience with JavaScript and Node does this sound like a good idea? real world real world things that people are actually doing with validity that's kind of a tricky part I don't know the most popular thing that everyone's crazy about is the ICOs they're raising a ton of money I'm actually a bit bored by that topic that's one way issue in the talk is crypto kiddies very good use cases when you have like multi-party market place where participants that are market players do not necessarily trust the intermediary so for example if you're playing online poker I don't know not in Singapore so for example, if you're playing online poker and I'm not a poker player you're playing online poker and you go to this website and you do not necessarily you might think like this website is their business then probably they might have a certain business incentive to have their backend logic play in their favor so you pick your cards and you think like what if the owner of the business modify their backend code and have some smart AI perform certain logic that there's no way or very low chances of you winning and with watching what you can do is you can basically have this backend logic you publish it to the network and when people interact with those contracts anyone can review the actual source code or what's going on behind the scenes and you can exactly see the exciting part of it is that you actually interact with real money if you have anyone build a stripe can you find that please raise your hands higher we've done dealt with money right so the exciting part with Ethereum it's like there is no API it's like baked in like I've got quite a few examples I can give you actually when you've done so like does it make sense so far so basically anyone can go even with EtherScan or other methods go into a contract address and see the exact source code of that contract and you're able to decide for yourself whether this code is doing something shady or whether it's being a legitimate code and it's being like assigning rewards in a just manner to all the participants so that's for example why CryptoKitties was like such a I mean it doesn't understand why it was like a hit but the way it works is that you can kind of buy and sell those and you can be assured that the owner of this game is not exactly like manipulating creating duplicates it's all stored in a verifiable and you can see all transactions publicly so how people are predicting against IP tests in any context okay that's I can give you that one what kind of IP well I've read the ultimate poker engine and I've published it up so nobody can take it very simple you've got to if it's going to really you can have offline parts of it but anything you put on the blockchain is public and okay so you wanted real world cases first one, Giveth okay hello girl we actually had a token sale we made some money as a result of that we supported a number of people in the community who we felt were doing good work and in the Ethereum community there are a load of people doing good work one of them is Giveth Giveth have designed a framework for charities to raise money and for they raise money so people contribute in the form of Ether but they have to lock in goals according to a roadmap as they achieve the goals along those road maps funds get released to them the UNHCR have got a private Ethereum network which they use to channel funds to refugees and refugee camps they end up talking to their banks at both sides but they target the right person they integrate the blockchain technology with iris scanners so a refugee in the camp can go into designated stores in the camp take the goods he wants he scans his iris and it registers with the blockchain he has received a certain amount of funds to pay for those goods most of what we talk about will be the public Ethereum network J.P. Morgan created a version of Ethereum called Quorum which has a level of privacy built in and that they are proposing to the enterprise Ethereum alliance as one of the technologies for inter-bank record passing fund transfers and stuff like that there is a very large very active alliance which includes many major banks what interested in using Ethereum as part of their structure because obviously you send to him you get information from him and all of that settlement and it multi-source people who don't necessarily trust each other are all protected by private keys so if you're into the big financial stuff banking and stuff like in the past they looked at other blockchain technology now Ethereum seems to be the thing of choice what about transactions per second so if you're doing a bank trading on these things it does depend we're nowhere near the right rate at the moment but you have to understand Ethereum is what four years old and it has got some of the brightest minds in the business working on it they're working on charging and don't know what else to get the rates up the first target is to be able to manage a reason I mean we're nowhere near it how much is Ethereum right now I don't know Bitcoin is like 15 or 7 Ethereum is 15 I'm not sure it's still quite slow it's a few thousand today but what do you want what's the question I think I'm wrong no it's way more than that you can get 300 in the blog now I seriously can't remember it's always going up 1200 what yeah 700 to 1000 transactions per day okay per day so it's like 15 800 800 I think they did get over a thousand certainly it's in its infancy but there are lots of technologies being evaluated to increase that the first one is of course getting rid of the proof of work mining which will speed everything up and then sharding various other things I sat in a room talking about all of these technologies that he had on the roadmap I understood one word in 10 yeah missed the key smart guys are out there they're working on it and they have yeah they have these numbers in their sites okay are you ready Elza do you guys want to do a tea break or relax for a second because we're going to go intense with a lot of more confusing stuff perhaps 15 minutes break 10 minutes break and we can make some main goal ask more questions I want to get a better sense of the room what are the questions please ask questions, speak out maybe we should do a few steps back and play some core things before we go into like more hardcore things yeah thanks for listening let's do 10 minutes and it's like 15-15 I'm probably clocked I'm going to be jumping all over the place and giving examples that relate to things that we discussed right so like when people were asking whether contracts can be seen by anyone for example of CryptoKitties one of their contracts someone else was asking about like what happens when I screw up a contract and how do you redeploy it the answer is like you cannot redeploy it once you redeploy the contract it's there forever it's going to have this it's sort of there forever unless you're self-destructed which still will remain with small amounts of it you can self-destruct the contract it will make it inactive but it still will be part of the blockchain so someone asked about what happens like what to do if you have a complex contract and you want to minimize the risks of making a bug there and you will make a bug there and it might be very dangerous so what people do is they will split one large project into subcontracts smaller apps and then deploy them independently and they will probably have a master contract that will link to other smaller contracts is that right Dave? if you can if you can, ok also get your code audited this is one of the most important things if there's any value in what you're doing if you're really dealing with real money and for example CryptoKitties are dealing with not a lot of money here but like $20,000 but basically you split it into smaller contracts and anyone can security is very important so if you're doing something of real value and dealing with real money and you advertise it to people and you want people to send you ether or play with your game or do something like make sure your contract is being audited by people who've done it before and who know what they're doing so if you audited it again and then again and again and maybe you will be secure our latest goal is to have two sets of audits it's a very complex thing so for example when we talked about that contracts are public EtherScan is a company and it's a project that's very popular and people use it to look at transactions and discover what things are going on on the blockchain there is a different blockchain explorer like other chains for like Monero or Bitcoin etc and you can basically see all transactions that happened to this contract so like this contract has an address and you can see all the pending transactions that are happening right now from where they initiated with if they're sending any value so the interesting thing when you see that contracts are having like zero ether sorry the transaction is having zero ether is that probably someone is calling a function or like setting a function they're not transferring the value they're just like like maybe setting a certain value within a contract um internal you can look at the code of cryptokitties and copy it basically and someone asked about like licensing or someone else asked about what happens to your property rights of your code I had a discussion with another dude who does like VM work for Ethereum and he like probably you can license it but you'll probably impossible to enforce it like that it's like your private license but I don't think it's even possible to enforce it because it's all open in a while Ethereum clients themselves there are like several major clients like nodes like death there is a party client those are the main most popular ones they are under GPL license and one of them is under lesser GPL license so yep you can copy base the code onto it it's pretty complicated another thing that we probably did not go into detail is like it's important to understand that there are different types of networks right that you guys had in remix I think that caused a bit of confusion it's important to understand so we have here like environment set JavaScript VM that means it's like a virtual machine of Ethereum that runs within your browser within this remix and there are other networks there is like live Ethereum network which where if you go to a coin market cap that's where you will see the Ethereum value at your price that's kind of value derived from the real network and that's what you see in EtherScan there are other networks where transactions do not cost money there is a you can run your own node on a real Ethereum network transactions take a lot of time because they get mined and they cost actual real money if you're running again in your VM it's free and it's very fast what shall we do? shall we go and like step by step explain this contract a little bit yeah, raise hands up if you want to get more understanding of what this means what are we doing here in general do you guys want to it's impossible to do that bring it up on the guest that's right what I wanted to do the main thing that I was preparing to do is link what you've seen so far in remix with more day by day the coding experience that you would probably have and expect because no one, none of you guys probably coding your JavaScript in your job in a web-based ID what you do is you use subline text and there are quite a set of tools that will help you actually have your contract in Git and compile it and be able to deploy it to the test networks, to your local network and to production network as well so let me go someone's asking questions here no questions alright, so I'll do a brief introduction around what tools are all there outside of remix and again, remix is like an ID where you can just play everyone see me, everyone can hear me okay, excellent where you can just play with contracts and fill the data really quickly and deploy them within your local VM, within your browser but it's pretty limited so what you want to do is you want to do several things, first you want to run a local node there is this thing called testRPC which is basically a local node that will be running on your everyone see this on your machine board and you can just do this by npm install gtestRPC okay, if you're in canary let me copy paste this and of course okay, so I know it might get confusing there are several there are several types of networks there is the mainnet where the actual real stuff is happening there's like public test networks and you can run your own local network which is basically one node that is not going to be really connected to the internet and it's really really fast so you'll be able to test your contracts really quickly so you can install this but I'm going to show you a bit more interactive because if you run testRPC questions? questions? it's on what? on instagram on telegram what about it? can you ask the question or is there a question? can you explain orchestrating can you explain if this could be used for orchestrating the actual changes what do you mean? which are changes if the example that we used can be actually to orchestrate the real changes sort of if you have a source of exchange rates that everyone in the network agrees to trust you can basically use that in production would it be reasonable? it would be reasonable to say that a contract is basically like a stateful service if you don't need to run on any server it just uses a chain to handle their requests between responses or do certain connections with the exception of the fact that every single transaction is recorded it's absolutely right everything is public everything is recorded everything is immutable I'm sure you've had things you built your database schemas and stuff and you're messing around and you're testing things you get to a certain point and you think how did I end up with those values? right with a blockchain you can replay everything and find out so every one installed I'm talking about running a local node this is going to be a preparation for us doing a bit more complex stuff another one is ganache this is a bit visual it's basically one blockchain it runs a test or PC node and it just adds some UI you might or might not want to use it but I want to use it right now on this workshop because it's a bit more visual and you can see what's going on in a more entertaining fashion rather than just looking at boring logs like this it's the same thing as here so again this is like a test environment that is useful and handy to use so you remember in remix when you were switching between accounts those are like test accounts with 100 ether it's just like for testing purposes on real network on real ether network it's really going to give you 100 ether for free unless you want to pay like 10K but on your own one node on a network you can do whatever you want so basically you have all these accounts mining is happening automatically we have blocks right now we have zero blocks that are mined transactions zero transactions and this thing is running on your like local server okay so I'm going to be jumping different topics so we covered briefly builds so this is running like everyone is installing this everyone got access to Gnash right everyone installed it I hope it's running so it's pretty useful when you're developing another thing is like one thing that we didn't mention is MetaMask MetaMask is a very important piece of software it's actually a problem plugin MetaMask.io so what this thing does is basically I think there are several Ethereum enabled browsers out there one of them is Brave there is MetaMask I think there is MytherWallet I have a Chrome extension as well so when you install it it creates this extension and it kind of serves as like you're able to sign transactions on different networks with this extension so for example if I go to Ethereum Mainnet so right now I have a certain okay I don't have any Ether I think not Ether in any of these accounts so I have some this is like actual Ether on Mainnet if I want to send to someone I'll know okay that's right and there are different everyone's installed MetaMask right okay yeah okay so like actually an actionable thing if you have a Gnash installed everyone's installed it and if you have a MetaMask installed you're actually able to connect to your local test RBC environment and have 100 Ether here so oh okay so here's a great example let me actually send some Ether from this account into this account how can I make this microphone fixed I don't want to volunteer and hold the microphone I can repeat okay okay thank you okay so okay fantastic wonderful okay so if it's confusing raise your hand and ask questions so I just want to give you an example of the magic that's happening so I'm going to use an imported account in a MetaMask Gnash is zero and I want to send some Ether from this account to this account send a recipient amount that's sent 10 Ether so this is actually like the assigning process if you're going to be doing Ethereum development you're going to see this quite a lot if you're interacting with real chain you're going to see this quite a lot so you can see the summary of transactions but we are on private network we're just connected to this and if I submit it transaction failed I think it failed because I didn't had enough gas let's see the address amount 10 gas price let's do more gas submit why is it coming it's not connected to the right network yeah that one is I think you need to connect to local rules yeah that is connected to local rules the one above that what the one with the 485 no no no it's running on the south bank so correct aha I'm about to give a nice example no it's not one why is it running failed doesn't have the correct nonce do you know why it might not be working what you connect to local I don't know the use of the local node what's it going to do no no 5.7 7.5 it's the nonce the only problem is with getting a nonce from the network yeah it's going to connect to the right network for example if you want to connect to that you can use this for example what's the amount of that one I don't know what's the amount of what's the amount of what's the amount of that one actually I'll do the same thing in Rockstein I have some ether I changed to another network which is like a public test network called Rockstein and I can send some ether this one I'm confusing some ether to this address for next send, submit success maybe it was a bit confusing I'm using Rockstein it's one of the test networks out there it's out there to test you can actually get like ether that is not worth anything but you can just an example of me sending some value from one address to another that is like signed by me to mask on the Rockstein network okay so okay we have Ganesh installed, we have me to mask installed I hope there is more of us understanding something or maybe at a certain point we'll come there and another thing that I want to introduce it to is Truffle Truffle is a framework that does all the Truffle does all the compilation and like managing and testing contracts for you is that clear, everyone's good everyone's good I want to see your eyes, I want to see everyone's good questions, problems? I don't see the Ganesh network in Qatar so okay when you went around Ganesh you will see like test RPC server you copy this you open me to mask and you do custom RPC you add RPC URL and don't forget that 1-2-7-0-0-1 is different from local host if you're running into this issue that's probably the only network is being mapped is a word different okay how do I hide this it's like a lot of italic stickers can everyone see this? success? everyone's there? wish address? RPC RPC address he need you to paste inside the telephone are you running Ganesh or are you running like a test RPC or something it? you will see it right here you need to launch it you need to launch it and you will see which port is it running on but I think if I post it on telegram people will get confused are you guys succeeding at this? everyone succeeding at this? having fun? okay, questions? everyone running problems? you got a problem or something? yes okay another thing is that you need to import an account if you just connected a private key and if you go into Ganesh this is the key thing so this is your private key sorry, there was this confusion the way you when you just stored a meter mask you don't have any accounts like this what you do is you import an account and you have an option either JS file or private key and if you go to Ganesh you do show keys and it will have a key and then you copy that key and paste it in and copy an account so if I connect back to my environment I'm on zero, it immediately shows that I have hungry ether does it make sense? guys in the back, how are you guys? are things clear? good, thumbs up, thumbs down okay, I'll get it no, someone is having a problem yeah okay, so no, no, that's good we'll do this okay mm-hmm okay, yeah so this is like your key so this is private key go see any of their tasks make sure yeah another very important and secure thing guys, make sure you're going to create right now a ton of private public key pairs and the ones that I'm showing on screen do not ever use them in production because if you use them in production and someone sends you real ether it's going to be stolen be careful with that um um okay, there how do you download ganache? just go to the ganache website I think there are other sites that you see uh no, no, no a lot of you guys went to the ganache github, gizgo to ganache truffle framework for ganache yeah, yeah windows download windows all good? questions? yeah can you talk a little bit more about gas limit and gas price what does that mean? yeah, more about gas limit and gas price right so, okay all transactions if you're setting a certain state value in your contract or chain, they cause gas gas is like a variable that costs ether um also, it's important to understand that ether is not the lowest denomination of value on a 3rd row chain the lowest one is weight and gas it has a variable value of weight gas price, one gas what's the average there is a gas station website that tells you gas price on your real network usually one gas costs five ways about this Dave, is that correct? gas price gas price is 25, how much is it? probably about 5 giga-way 5 way giga-way one gas yeah, so basically that's like a variable thing in your local environment, you can set like gas price to whatever arbitrary number you can set but in real production network if you go to the Google it will tell you the real-time gas price and the reason why gas price is important if you use mid-mass, see here when I was sending a transaction when I was signing a transaction okay, I'm receiving it I'm not receiving it you said gas price, how much weight but this is the only interest in what I'm learning and gas limit, if you run out of gas while executing transaction the whole transaction is not going to go through it's going to get reverted and your gas it's not going to get burned but it's just going to get reverted as well all good so far? shall we go further? questions? everyone's learning things if you go to your official website you will see the ton of documentation about how much is one weight okay so so again making a step back we played around with with remix a little bit and truffle is their real deal it's like what you will actually be like git committing, excited to say just for the reference, there is another framework embark I think that's another alternative I'm not going to go into it but it has some sexy stuff with IDFS and ton of other things but we're going to play around with truffle okay questions? embark so basically what I'm talking about right now I'm showing you embark and truffle those are like they're building JavaScript but they are frameworks that have rails it's like an environment set of tools that abstract common things for you they basically glue testing environment they glue mocha to your tests so you can actually test your salinity contracts in JavaScript how awesome is that and you can just run a few functions in your console like let me give an example of some other thing that I have I can do truffle test and it's going to deploy I'm jumping forward a lot it's failed so those are the frameworks something for your homework that you can explore at home we can look into truffle right now and again it's like set of tools to help you test, deploy keep track of your contracts when you can commit them and you feel more professional and confident expert yeah so I hope by now everyone's got truffle installed life coding, I think it's not going to work even for me now if you felt that you were confused you can't be even confused how can I make them ask the Gnash did that question get answered how did it I think it was this did that get answered is that clear now no one's complaining silence is good silence is yes, everything is good yeah good question I wish change your life change your life it's going to take forever I'm thinking do you guys want to do a contract from scratch or do you want to continue with ooh the irony a different button can we we'll try to do a contract from scratch this time you just made some great new director no one can see my character and I'm doing truffle in it oh shit what is it truffle in it so the god damn why is this my screen for some reason so the weird thing about truffle I'm not sure why they haven't fixed it when you do truffle in it it creates any project in your current directory so you need to create a directory first just on a facility cd into that directory and only there do you truffle in it I'm missing something because it doesn't move okay please someone help I'll help sorry the neighbors can help you out shoes yeah cool did truffle in it what it did you can see a few things contracts, migrations test, truffle config and truffle gs and if you allow me I'll just use sublime flexible so you can see can you see we can zoom contracts tests, no tests Michael is it safe for me to play with the resolution I'm not sure okay so when you run truffle in it it will create a basic structure for you contracts is where you actually keep your cd in contracts migrations is where you it's like it's like a file that deploy your contract to the network it might be a local network it might be a public network it might be a test network so they are pretty important and because your contract is going to be evolving over time it's important to ooh I'm scared now I think it's too dark it's like cold and dark just a bit cold but I'm going to be losing this game so and we'll try to it will increase this migration contract which I haven't actually used it, how embarrassing which helps you keep track of your migrations on the actual chain but let's do a new file what shall we do what shall we do what shall we do I'm not sure what are they doing they're still having a problem okay I hope it's not overly overly complex but what's the contract that I was going to try to write I'll let's write a game how much time do we have an hour it's a game it's like a multiplayer game where everyone can vote on a number between 1 to 100 and whoever gets the closest to 50% of an average value wins Ether doesn't make sense it's like a medium contest but you have to guess what everyone else will pick is there everyone votes from 0 to 100 and whoever gets their number places to 50% of the average wins okay so we create contract solidity um getting stressed we'll create a second migration just in case so we have two migrations we won't be doing tests for now it's really pretty good to do them I'll probably show them some how to find out and I'll be focusing on another contract that I haven't finished so I'll be cheating a little bit but I hope it will be easy to follow more of this come again zoom in light things gonna take forever is that any better a bit more demanding sir is that any better can you tell you my content you know my public address you can send me some ether one ether is one point um okay okay video content we're gonna do contract is gonna help I'll try like this nope alright it's public what is this so can I do it oh sorry good idea I'll probably get a fail um Chris Murray again it's hard enough to go in this but it's really hard so um we'll basically have a main function like vote getting into a bit more complex Michael did you turn off ACX okay um what should I I think I'm getting too complex um I didn't think of a simple example that I can show you guys okay so I'll try to get this right so what are we doing we're having an owner the person who created the contract just in case like a security measure that you do in case there are some value in the contract you want to like just someone just make a contract and the value can be sent back to the owner um voting is basically um we'll like let people have different accounts and um we'll need a function that will like repeat the mean there is this like convention you start with the underscore for all like uh arguments it's just like easy to distinguish and because you can load once we'll make like e-files some logic oh interesting thing like um compared to um javascript you know if you in javascript you just like to like variabilitcaleration it's going to be undefined in salinity everything is zeroed out so like the value of sum is zero it's defined here by default the same thing with if you have like a public owner address the value of owner will be uh zero it's going to be zero address okay what does it pay for the what does it pay for okay payable means that the function can receive funds okay um that's pretty important public means that um I'm not sure that we're actually going to get into the payable part but basically um what are you able to do is for example if there were like money bold right and I could have another um like mapping um of address um value right I could I could do something like this um message value um something like this right that will add um add more sorry not net goes um does it make sense so this is going to be a hexadecimal number of like for example if if this participant of the network sends um calls this function with an argument and with either value um this contracts can execute some logic it will set uh this internal state as value and assign it to the address of the sender and it will also um add more value into the um into the balances of for that for that work trip right and we can do um yeah um so we'll make sure that we're just going to do what we want um so in this regard the values I just want to keep it as simple as possible so no one gets confused I don't get confused as well so we need to do here I'll cheat I'll look at my previous content sorry now I need to remove yeah oh yeah okay so another important concept in insulated age like you know in in in jobs where there is a console log uh in insulated there is like no console log there is um this concept called event um and you have to like declare that right and they can return like on a specific um that type so I can do and and again those logs are visible by everyone um let me actually look at an example maybe maybe um maybe um initial transactions certain transactions might have um no logs here how I do today any comments what should I okay okay the first thing we've got a transaction which is returning something your both function the only way for you to one is the result what okay what's KTUI and some I mean I understand this is gonna be very efficient at the previous game but I hope it's more or less make sense are there um questions cast my code usage uh sorry I don't know so I'll check it out later we can discuss later um we can we can um just check whether it compiles maybe I can copy paste it real quickly where was that uh thing okay um how do I I was someone selected or something I have no idea what's question I'm sure I can't it's just gonna it's not like my comfort zone so it's already pretty bad so like I want to like avoid confusion I like it's pretty bad that you guys are confused it's gonna be even worse if I can't use it you know I wonder I don't know wonder um pizza french fries stay here so um they just paid to the actual cycles they use or do you put a price on it um with the payable function so that means that this function can receive if ever ask people how much they do yes so for example if it's like uh if you're um if you're buying something or you're like betting on something what you do is validate and you're turning that amount to make sure it's yeah you can like actually have a little variable that is um um like says the price if the if the if this like yeah yeah you can actually just like um um uh you and no I'm not gonna use that um you're in price and if like yeah yeah yeah I mean I find it's pretty exciting because like if you do that in like you know in if you if you receive payments with strike or anything else like you have to do ton of like you know authorization like you know callbacks keys uh back and forth between uh the server and here's just like everything's there where does that expect semicolon um uh unexpected semicolon somewhere I need to add one after the lock screen oh after yeah after the lock I'll just add one to the other one there's one more lock screen oh right thank you I I I don't see dead pixels and semicolons okay more or less success so that means that contract compiled okay and the interesting thing like when contracts compile they get built and you get them in in this can you still see this in this build directory and it's an also important part like I'm gonna be again jumping things so like we cover quite a bit of ground when contracts compile they create this like json a bi files and they are pretty important so because they basically contain your like quite a bit of information about a code they contain all the interfaces um about you know all the functions so for example I have this vote function uh and it's gonna have come on somewhere okay here we go uh it's gonna have some information about what like attribute is it it's not a constant hold on ah here we go okay a bi thank you Dave um so into this it comes down to false inputs okay so in a bi this actually kind of provides information um about your contract and function and you can see that the name of the function is vote, certain outputs that we just declared um so we have a type of inputs uh type of um outputs whether it's playable it's playable and so like the video of this thing it's not really beautiful the interesting thing about this is like type of function uh when you when you build and deploy a contract you're gonna receive this and also it's gonna contain somewhere like the actual address where it's being deployed if it is deployed um this one is just combined and deployed um and you can build like a UI based or a dynamic UI based on on the ABI array so in fact when you when you look at um um yeah at the what we've been doing with um with Dave's example with the change rates when you solve the contract here that like the um um the outputs like the way UI was generated is because thanks to that ABI um uh JSON file and that ABI information so it's just basically the dynamic based on on this and we will need this later if we'll if you'll guess if you guys you know last if we have an application okay um so that's what happens again we haven't developed much yet I know it's pretty empty, pretty boring right now I don't think it's really happening that much but I just want to cover like different steps since they just you know with this basic stuff so the migration that we wrote is only for deploy right it's nothing to do with compiler uh yeah it's it's for deployment, it's nothing to do with compilation sorry for jumping things it's just like a lot of different things that it's a bit of hard to puzzle them together maybe you'll eventually puzzle them so basically when I when I compiled when I when I did uh couple compile it basically went through the code it investigated if there were any like really bad errors in it um there are some warnings uh and it generated um what a compilation actually does is like generates a ton of bytecode which you can see somewhere in the ABI file come in yeah here we go, ton of bytecode so this is actually what's being deployed on the on your either local network or um yeah that's all the numbers that we saw earlier so I mean I know this pretty low level stuff but it's it's pretty important that it's actually I mean like I used to be doing JavaScript for many years and I never actually do like went in depth of like you know compilation stuff and now it's actually pretty exciting um so I know we haven't done much yet but I just want to go through all the steps uh and let's just like publish this contract with Truffle to your hopefully running uh test RPC environment or Gnash Gnash is just like a UI on top of test RPC in our France test RPC um so another thing it's like the confusing thing about Truffle it has to like to if I do Truffle help um it has uh Truffle migrate and Truffle deploy it it's the same thing um I used to be confused initially whether it's confusing to you guys or not um so before I hit Truffle deploy you can't do it any better okay um so okay we have this contract I hope everyone has it as well and um and I have a sorry migration setup sorry add a main migration which basically takes the beautiful um contract and deploy deploy there's like way more that you can do here you can like set like for example with example that Dave gave about exchange you can like add um additional parameters here with which you deploy the contract but for now we'll just keep it easy if I do Truffle deploy oh I think it's gonna fail um I know it's gonna fail we'll deploy okay no never specify another important thing Truffle can fail okay uh here you actually specify how Truffle like to which network it will connect to when doing deployment of the contract uh it should be pretty simple I'll let let the removal require um so okay that's config file I can actually delete this thing so I keep it simple and not confuse anyone because they're all confused already um let's see okay so we have Truffle.js right everyone can see it everyone everyone has it any confused faces yes problem this thing uh can I I'll send a telegram to you guys in a while okay okay I heard you oh someone deleted everything okay is it good? yeah okay so basically what this thing does um because we're running test RBC network in ganache so we have this server that runs an accessible on this board this RBC server and in Truffle we'll be connecting to this environment and in network uh and let me run Truffle deploy once again ooh match success exciting are you guys excited? okay um exciting thing okay you can actually see stuff happening what just happened is uh Truffle went out and performed this uh sorry performed the uh this to migrations it deployed the default migrations contract ignored for now and the contract that we just wrote it's like super simple this dummy contract that doesn't do much yet at all but basically deployed it and it's kind of important for you guys to get started we can see some output here um this is actually the code or like the public address of that contract uh is there in our local your local test RBC network and we can see some changes that happened in test RBC itself um and you know I'm using ganache again because it's like UI so it's a bit less confusing that just like running the same piece of code in um in command line so what just happened because test RBC is pretty fast it's like one transaction per block right now usually it's like multiple transactions per block and we can see like contract creation contract call this is a thing like the migrations contract and this is the actual um the actual um the actual contract that we just developed uh in a beauty contest so this is that um okay okay everyone everyone's following any questions so far everyone's excited we deployed a real contract to your local network contract call again contract call which one um to be honest I'm not sure what the call is going on here Dave do you have any comments you know why it's like me creating a person that has been uh so like I just deployed a contract um and then it's additionally makes a I think it's like no that's the tx hash right yeah but it's not a contract creation hash it's uh that's the hash of that's the hash of the transaction right it's a this is a creation transaction the code of play creation transaction this is the single one that doesn't have much oh I don't know that's a truffle thing I think maybe it's like a truffle thing um to see oh okay okay so this is a it sends so it first created um migrations contract is the truffle thing it's a bit confusing uh it created this migrations um this migrations contract and it sent uh status update to that migrations contract that we performed yet another migration but the most important part is this so like this is the actual um contract that we just deployed this beauty thing and um so okay um I'll try to explain a few small things um um if we go into like beauty contest ABI file json file um the bytecode here is pretty much gonna be the same so if I if I copy paste this that's that's the bytecode so it's exactly the same and somewhere here will be the address so this is the uh contract address this should be the contract address and you can see it here as well so it's the same uh it's the address of your contract that you just deployed on your local network and this is the address that you're gonna use to extract this contract okay okay um and um okay which should I do next is this is this clear so far okay what's the point of the migrations contract I mean why do we do it this way why not just publish our contract okay so the migrations contract keeps track of the previous migrations that you've done like you in-depth explanation will be provided by Trump hope the commutation yeah but uh could we have used just the first initial migration to deploy both of these contracts yeah you can you can deploy multiple contracts in one you can actually do I think then and uh you know do miracles uh deploy a second contract and passing like so like contract address and you can actually like token sale and coin yeah simple like you basically can do I don't know stuff like deploy deploy migrations I don't know it's like let's not use migrations abc whatever just abstract abc abc one and you can make them interdependent um the address of the other yeah like if this contract depends on the other contract you can um um you could do something like this if like you remember you guys someone asked about like whether like what happens if the code goes wrong and like that's basically initiated the contract and one is another one uh that's sort of how you do it um and you can get way more complex of course but I'm just like I'm trying to keep it simple questions questions questions questions yes gentlemen no more yeah good question um I think it's like we're moving a few steps forward so shall we go into this right away 3js please that's like a very good question I think that's probably one of the best one of the things which everybody here has a direct application for immediately okay so okay I wanted to do a few things here but I think that's a very good question because we're running out of time and I think people are running out of patience so quick answer is uh there's this thing called web3 um and metamask is written in jay through web yeah and metamask is a web3 provider right so in your in your code in your web application basically you will have a you will be interacting with this variable like web3 variable okay like if I'll I'll cheat again I'll show you something like JavaScript finally I'm excited to see JavaScript finally some react code I'm the only person excited sorry okay so okay this is some JavaScript code finally right I'm just jumping many steps I hope it's not going to confuse you a little bit more okay so basically there was like some magic here um web3 is this library that you go to there's amazing people from web3 foundation seven out of them at this conference maybe next time they were in Singapore though um so this like it's like a library that provides you connects your code your JavaScript code in the browser to to whatever um network that you connected to in metamask okay I'll simplify again um okay if I give a few on a dance party so I'll give a few ideas what it's like to find what you're looking at a few ideas okay um let me just try to someone's doing stuff here okay um how to interact back to the question how to interact with your contract that you deploy right okay so we have this web3 thing um and the important bit you need to use um like a few things you install you do like mpm install web3 you do mpm install travel contract right and then um from your deployed so this is actually a bit more of like a mature what does the same thing it has like this my beauty contest contract okay thank you sir thank you sir fantastic okay we are team now okay uh so remember when we did the deployment we got this um okay I think you should I should I we got this uh contract state verify so this is the one that you also going to keep in your frontend project repository and you will actually require it in your um in your frontend code right and then it's you use your project sorry your uh your contract like bg pageant or your contract deploy instance and then you basically can interact with like vote um and I can do vote one from from one of the from the main account is that more like I know I'm skipping a ton of stuff but that does that like more or less clear you're getting like a few bits of pieces more yet okay okay so the accounts are coming from remember when we were setting up uh metamask so um well it's nice to play hash sort of um you're picking one of the for example if you're using metamask as your worth three provider in other words it injects you a connection to the network you can use the uh you end up using the accounts in metamask anytime you want to submit a transaction however metamask will pop up and ask you to sign the transaction so nothing happens without you saying so right if you're running parity a parity node at the back end you use the parity signer in exactly the same way so the parity signer will come up and ask you to sign the transaction so the account that we select there is the one that will be used um yeah so okay like here's an example so um okay I'm sorry to use scripted keys but I think they did a pretty good job so cheers to them so for example I am in metamask right and um I am connected to Robson text network what metamask does um yeah it's cool it's equivalent okay so it injects this like web three oh you can't say it either um okay huge success it's a web three library and you can do a ton of interesting stuff here is metamask sorry it's a straight and this thing there's like a huge accommodation around it and you interact with it to do a ton of to like sign different transactions like using this library you can like get um your ether balance in your uh in your account you can send transactions so functions that's like your gateway this here like gave a drug to blockchain develop to to solidity develop um so you can be interacting a lot with it right does that answer a question for us right so okay an example with um with uh scripted keys so um so we're now connected to to like Robson network and like metamask their code is uh you know calling back three gs and it figures out that it's a normal network and even connect to for example to main network is like oh right you're on production network and like lets me lets me sign in right and for example i'm you can also switch your networks and you can switch your accounts you might have different accounts on account volume is like whatever random key okay and it kind of arises me there but it sees that i don't have any i don't have any keys because i don't have any keys on on this on this account it's like a nothing just like an empty if i switch to like my what am i in like real accounts um it will like metamask will listen to changes on web 3 and will actually like get all the information from blockchain that are specific to this account does that make sense more or less is that descendable shall we go in depth on something everyone's clear i can see you have faces okay um yeah so i jumped question like topics what would you guys want to dive into something shall i continue where i dropped off you make it like yeah contract when you send money to that address it'll live there right i mean contract has its own private like funds yeah contract has its own balance and storage of course there are exceptions but you can refuse your money if it's if the function fails throw an exception okay so contracts are addresses just like any other address in that you could accept that contracts will only accept ether if you explicitly allow them to accept ether so you saw the function the word payable up there you never own the private keys to a contract right you never own the private keys to a contract so if you've got ether inside the contract you have to have code in the contract to send it out right in the contract in this contract there is no method in the one you put out earlier there was no method to withdraw that ether so all that would happen is people put ether into the contract and you'd never get it out again which is dangerous which is you don't want to have it right that's called trapped ether like and no one it's the same thing as like lost keys you will not be able to but you can put code you can allow it to transfer you can have functions in there to transfer which is exactly how proud sales were you put the mentions address in there so it just comes in from one account and then forwards it to another account yeah indeed certainly yeah you can have like something like this message sender transfer and the number of value so like if I call this function okay let's say I'm like just like super simple super silly yeah it just really pays the stranger so come again signs into that and then they fetched something on that public app and how did you link how did you get them to send the money in the first place I missed that sorry how do you get how do you put ether into it yeah I come along and I want to buy something on the side okay so you've got you've got your website created so like normally you'd have a plugin for PayPal or something like that so you want to write a plugin for Ethereum so your plugin for Ethereum would normally be expected to be Web3 enabled this is not making it right I'm talking about front end I'm talking in your javascript on the site so you build a plugin that uses javascript which is Web3 enabled yeah so in order to use it just like crypto cases it would say you have to have a Web3 provider which metamask is one of the most common right so then when you get there it will know what your metamask account is automatically it will say okay this is your account this is your balance and then I want to buy five so it calculates how much you have to pay and when you click buy it will send the buy transaction to metamask to sign and you will see it coming up in metamask saying I want to send 5 E3 to this address or 3 E3 to this address and you sign it in metamask so that's your security you actually have to press it let me do like a super shameless blog about crypto jobs if you guys are going to be really good actually like people hiring regular engineers like I don't see those blogs but I wanted to do like a super simple the name button right it's just like spaghetti jQuery code but it's very easy to understand let me even like dumb it down a little further oh okay no analytics, let's remove all this so what's going to happen I have this what's the name the name button so basically when I click where's my this thing goes in and I can like enter one after and if I send okay metamask comes in and I'm on a real network right now and I just entered that I want to send one E3 to myself to whatever address it provided and if I click sorry I don't have sufficient funds that sucks but okay not a big problem but it's okay let me try to do actually finally use the local network so here I have a ton of funds I have a fantastic amount of actually no no no okay let's use Rofstein let's use a Rofstein department this is a commercial site that's set up where you can write details or details or details yeah you can do that so what's the name they're otherwise like he changes it's like okay let me just finish this real quick okay come on connect okay Rofstein network so if I do I have money here okay I have some funds here the name of the metamask I enter one I click okay signing with metamask I'm on Rofstein network I'm sending one E3 to this account from this account I have funds okay all safe and secure I click submit and the transaction hopefully goes through yeah okay see the transaction is pending just now I confirmed and take myself on the test network which is not much but it's tough and the way it's been accomplished it's like super simple so web 3 is coming like you don't have to import it in your frontend it's just being injected by the metamask extension so like basically if I don't have metamask installed it's gonna do nothing so basically right now what I've done it's not even gonna show the donate button if I open this up in incognito mode yeah it just doesn't show anything because there is no metamask here it's not even showing the button so okay and when I click the button it's loading you get them out from prompt and then I convert this amount to way from user and I send it to this account right so this is the account where I want to send money so this is like a super simple thing this is the account that received the money this is the transaction that received it from this address it's that simple questions? you're asking about providers the only one that work that actually sorry okay the only provider actually the two providers that I know of that work with accounts encrypted in them are parity which is a lot more or metamask where metamask's USP is basically that they protect your keys and they inject web3 into pages and apart from that all you can ever do is send ether however it is also possible to write applications with web3.js where you handle the keys yourself so one of the most popular sites in ethereum is myether wallet now myether wallet is completely javascript web3.js but they but you can use private key you can use adjacent wallet which they will then use the appropriate functions to do the scanning with or you can use something like this which is a hardware wallet if you have any ether worth keeping you should consider getting a hardware wallet and then they communicate this using the relevant API to communicate this and in these devices your keys never leave the wallet the transaction goes in through the serial cable it comes outside again so there are plenty of things using web3.js some of them do not need to use an external to use another app to contain the keys you can get the keys in another way and of course another thing you can do with web3.js if there is something going on you can just write things that monitor them they don't need to always send transactions so what's the state of a sale contract and you just extract the numbers and you don't need any signing at all yes oh, alright I think we are officially we are ending at 5 but we are happy to stay here as long as you guys want and we can do more Q&A and maybe code more if you guys want I can answer a few questions right in the middle in telegram I got some t-shirts some questions yeah, who could get so yeah, it's like I'm just giving you a super dummy like sneak.code just to illustrate how simple it can be to just receive or send funds so basically this is like sufficient as your destination address for example your store you have a store you have your wallet and you specify this too and then you specify the value of your product and when this function is being executed the one that is sent in you can actually see it in a browser the metamask confirmation is going to go up and when people click buy that means the transaction is being signed and you get the user and you get this transaction verification sort of confirmation thing that everyone can see it and everyone has access to it and you can see that it actually happened so if you can actually navigate to the transaction you can explore it, you can play around with destination, two address you can see what happened here you can go to my site and play around with it, there is actually an independent food I made it super dumb and simple so you just can see the person somewhere there was I think you just want to copy paste it and I think I made it somewhere on YouTube where you can just follow the food and understand payments is only really one usage I mean if you have to say thanks for the styling stuff and I know there are payments through this they'll just if you get the fact that you don't need some money to go into the transaction and then use that to claim it offline come again so say you have two banks settling something that they made to close the deal with the settlement conduct the act of transaction, not transfer any money or Bitcoin, so just get the record if we agree to pay them amount to each other you can do that but it kind of doesn't make sense for me I mean if I want to transfer US dollars and you just want to get a history of that you can do that and I think there are other blockchain projects that make sure that they're pretty well known you can just Google them and they specifically design for banks specifically for the ledger they're a control bank ledger specifically designed for bank ledger with higher throughput they're way faster than Ethereum they have some downsides I don't think the ASX is doing that maybe I'm not sure more questions that's a very good thing so the cool, really cool thing about this Web3 provider why is my UI messed up why is this one like that so what you can do remember you had this section at the end you can actually use your Web3 provider and oh hello injected Web3 so now Remix is connected to whatever network my Metamask is connected okay so if my Metamask is connected to my local to Gennash environment it will basically be interacting with Gennash and so the cool thing what I can do is let me connect it to directly oh thank you and I can do some magic where's my super complex no it's not that just some facility okay so we have this remember we deployed a contract earlier I can can I come on did I spell it right probably didn't I have no idea spelling is not my forte hold on I need to keep it exactly the same so what I can do is I copy pasted my code and remember that we deployed this contract and it was sitting at this address I can actually load it at this address and it will compile again this thing in memory and it provides some lovely interfaces okay so I can basically from remix I can interact with my contracts that are on my local machine basically I'm interacting with the contract that is here and I can call its functions and if I call it get an owner it will get the owner of the contract which was set to this when I was deploying it if I get me nothing is going to happen if I vote there's going to be a vote because I'm not there was no function to retrieve the vote but it happened I voted and everyone can see that so okay there was even an event happen like voted remember we had this lock string so this is the lock string that's event lock string event happened okay okay sorry okay so okay no that's going to be confusing it gives no pick up a contract how do you create your own how do you create your own that is going to be interacting with your own contract right okay come again okay sorry no worries so basically again when you are you following me when you compile and deploy the contract you receive this JSON object you need to require it as part of your front-end app like your JavaScript app you're required and you have to have a few other things like Truffle contract web3 which is like it's not a web3 provider but it's not a library that kind of provides this like equally with the blockchain and then you set like a pure provider which basically assigning giving access to your contract to the blockchain environment that's a wrapper around the contract it's like a wrapper around the contract right and then when you use your contract you have this like your contract deployed and then you have an instance and then you call the actual functions more or less if you're doing the function like if you're calling a function that is changing a stage in your contract yes it will cause it will trigger this mid-mask signage pop-up window where you can accept or reject to read data you do not need to you don't need to sign and like the new one has the problem in mind that when you read data the read call is actually happening only on one node and it doesn't cause any ether if you're having a certain function like load because it changes the these are the state variables if you change any of this you will have to spend gas on changing them if you're reading them, if you have a function like get my load it just like loads retrieves your load it causes zero ether and it doesn't require any signage come again is it possible to deduce there's no cost of doing it to deduce what? to deduce reading no no no you connect it to the node and there are millions of nodes thousands of nodes are there you can bring down one node it's not a problem it's costing the node owner well, yeah but the network doesn't go down the node owner is burning true, but you're more like you're more like bringing your machine down than your others who's paying for the what? sorry? the guy who's running that that function yes to run the node to run the node yes most people do it to keep the environment alive because it's in their interest to keep the environment alive it's not a significant like electricity waste if you're just reading really popular but if that specific node again you can bring the node down but it will not bring the network down can you connect to any other node coming in most of what goes on is submitting transactions when you submit transactions it costs you money and you're going to deduce by spending money that's the whole crux about gas in the first place the other thing about gas is because you have the gas limit it stops you having like infinite loops and things like that gas if you have a function that's providing a gold price that's going to be querying that function yeah but they'll be querying it on different nodes right you end up querying it on the one which is closest to you most of the time if everybody is going to a single web page which is talking to a single provider then you've got a centralization which wasn't what you're after in the first place so there's no benefit actually sorry, coming in okay if you're paying shall I check okay now comes the bit which I avoided talking about everybody heard about mining so running a node is not that expensive I run a node most of the time on my MacBook the moment I turn it on for the only time it cost me I did it on mobile and I used up all of my mobile allowance in my node um mining is something different um the whole concept of mining we're still using the same concepts that were put in place by bitcoin which is called proof of work and the aim is to make sure that no one no matter how powerful his machine mines all the transactions because if you mine all the transactions you can rewrite the blockchain right and nobody would know so in order to do that then there is an artificial contest was in place for proof of work and what that says is that in order to submit a block you need to make the block hash meet an artificial um what's the word conditional so for example we can say at the moment the numerical value of the block hash has to be less than 1,500 or something like that now obviously if you just randomly select blocks that's very unlikely to be true so you're going to have to reorganize you're going to have to change non-sys you're going to have to keep on trying until you have a block that meets those conditions but as a reward for that you get the certain amount of Ether which at the moment is 3 Ether for the block plus all of the transaction fees now the transaction fee that you pay is the gas you use multiplied by the price you offered for the gas right so also coming into it if I as a miner want to mine a block I will choose the ones which offer me the highest gas price most out of that block right so the miners get paid that's where your transaction fees go to the miners to keep the system fair now they're up there working on something called proof of stake which is supposed to be another way of keeping it fair it's not quite there yeah the Ether goes to the winning miner yes the one that got it right first ish and published it and was accepted by the network correct yes we don't distribute it to everybody no you don't you distribute it to one block so frequently that it eventually is because it's a difficult thing to win that it relies as much on chance as it does on computing power it tends to get generally distributed amongst different miners right does that kind of ask for your transaction fees go? yeah the functions are they evaluated once by the miner and then the results of the function the new state is that part of the block or like the function need to be evaluated every time they're computing a hash okay you submit a transaction which changes the state of a contract the miner will prove that is valid he'll either prove it succeeds or fails but whatever happens he will include it in the block every node on the network the moment they include it in the block they will compute the state of the Ethereum machine the reason I asked you that is does it cost the miner more if you have a function that's very expensive versus a function that's cheap like you said I mean every block has got a gas limit so you can either have a few really expensive transactions or a lot of really cheap transactions because the whole point about the gas price of a transaction is that if you've got a repeated loop which takes a lot of computing power then that will cost more than just a simple piece of code if you've got something which uses a lot of state variables that is more expensive than using local memory because the computation of moving information out of state variables is actually higher so the gas the gas limit you have to provide is actually based upon how much work has to be done so to compute a block the miner is also computing these hashers yeah it's called catch up 2, 5, 6 years it's close to a char3 so I mean and they're doing this millions of times billions of times so how does the cost of doing that compare with the cost of computing a function even if it has a loop that runs to a thousand inside it in fact might have a function that runs to a thousand but that's still really cheap in the scheme of things for the miner compared to computing catch up to 56 like a billion times really cheap as in what I have seen electricity time well the point is now we get to economics for most miners it's still economical to do so otherwise they wouldn't be mining I mean I haven't mined Ethereum for about a year and a half but I mean I was making money out of it obviously other people are people are looking at reducing the cost there's one project called HydroMiner where they take industrial containers full of miners they park them right next to hydroelectric dams in Austria and they buy wholesale electricity from the dam it's far more ecologically viable for the simple reason that they're not burning anything to get the electricity but I mean yes that's why we're trying to get away from proof of work on Ethereum it should be sometime in the next year hopefully that there are one or two networks out there the Qtum network uses prudent stake which means you're not doing as many computations you don't need graphic cards to do it in fact on Qtum they say you can actually do mining using it rather than buy if you want to as effectively as a mainframe questions so far does the proof of work increases the complexity when the block increases it doesn't have any impact on the blockchain it's just it generates a lot of heat it uses a lot of power it contributes to global warming which is why I'm trying to get rid of it but it increases the complexity of the proof of work yeah as far as I know I really don't go into that I'm afraid how are you doing Roman? yeah I'm good I mean we're over time but I'm happy to be over time we are happy to ask for more questions do more coding do whatever you guys want let's make a mouse cover never trust anything okay security rules in working on blockchain if you're dealing with any value don't leave a coin coming exchange exchange get hacked integration if anything's got a server side it means someone can steal your keys right when you create a metamask wallet it gives you is it 12? 12 words? it gives you a mononomic 12 words just like the ones you see at the top there using those in a formula called BIP39 you can regenerate the private key, public key pair so metamask tells them you're supposed to write them down don't be like the clever person you just stored it in ether and it was called evernote and then evernote got hacked so she lost her private keys and she lost all her ether yeah there's some magic here for example if I use the same mnemonic this is a popular mnemonic do not use it if I enter it here okay do I have a mnemonic Y where's the mnemonic is there an extra line yeah maybe there's an extra line BIP39 in the wrong one where is it it's a root key it's a root key so I use this 12 words not 15 right thank you sir if you're going to paste that if you're going to paste the key that is creating some things basically in theory it should be creating the same key pairs as I have right now which technical code we connected to it doesn't matter it's just a function that takes these are the ones you're pointing for where you play you might be But given the BIP39 function, that phrase does not give you one address, it gives you a sequence of addresses, right? So Metamask has it, and I say, do not store it on a computer, write it down, take a photograph of it with a real camera, develop the film yourself and put it in a safe, whatever you want to do, but it certainly does not store it in Evernote or something which could be hacked. You have these wallets that I showed you before, which are the, this is a Ledger Nano. This does the same thing, your software can talk to it through a USB cable. This does the signing, you've got little buttons on here. When you first initialise it into a random state, it gives you a 24-bit phrase. When you write it down, you don't, right? And if you do that, you might also want to think about some way that you can distribute it to a few relatives so that if you pop off, wife and family can be looked after, or husband and family or whoever, right? Security is very important. Right, so that now brings us, so like, your wallets should never have a back end. Most of the phishing attacks that take place are fake sites, you know, fakes of sites like MyEtherWallet where they put a back end on it. They ask you to upload the JSON file, put in the password, which is exactly what MyEtherWallet does. MyEtherWallet does everything in the browser. The moment they've got a back end, you know, they've got your file, they've got your, they've got your password, the next thing you know is you've lost all your ether. Yes? Questions? Oh, clear on like requiring this, the ABI file and we'll track with it. Further? I have one or two. I still have one or two T-shirts, but I have XXL and X, I think XXL and XL. If you've got any big people here who'd be like T-shirt, come and see me. Okay. Shall we call it? Okay. Okay. Okay. Cool. Thanks you guys for coming. I hope it was not too overly confusing. If it was confu