 Okay, shall we start? Is everyone set? Let's wait until the police is gone. Okay, thanks everyone for coming to this meetup. Lots of people here I see. That's really nice. I hope, I mean the tables look packed, so I hope there's not the same amount of people waiting outside. Yeah, so this is the first time we are in the Game Science Center here and looks like a really nice venue and I want to thank the Game Science Center for hosting the meetup here and Lea wants to say some words about what this place actually is. Yes, so hello everybody and welcome to the smart contract workshop here at Game Science Center. I wish you fun while coding and learning solidity. So the workshop will end round about 9.30 and afterwards we will open up the bar and exhibition for you. So feel free to have a beer and mingle at the bar. And also if you are planning events like networking, live streaming, esports events, then you can talk to me afterwards at the bar and we can make plans. So, have fun. Also the second thank you goes to live peer who are again providing the AV setup here and they are also live streaming this in a decentralized way to the Internet. So, that's really cool. Okay, my name is Christian Reitwitzler by the way and let's start getting to know something about how to write smart contracts on Ethereum. So, did I not test that? Oh, no I didn't. Okay, as I already said, please try to install the Metamask browser plugin. So that's not the best way to access a blockchain because it's fully centralized, but it's a very, very convenient way to try out Ethereum and to have everything running just in the browser without the need to install anything apart from the plugin of course. So, there is a version for Firefox and Chrome. I'm not sure about Safari. If you have the option, use Chrome because last time Firefox had some issues, some glitches. Okay, so, yeah, this is about blockchain, right? And blockchains, that's this weird world. We have people buying tons of GPUs and having solved them fully useless problems and people actually rent airplanes so that they can buy GPUs faster than some other people who do the same thing. And there's also this weird thing where you trick people into giving you money and promise to change the world and then in the end you do nothing. Just run away with the money. Is there an issue on my side? And then there are these companies who used to do Iced tea and then they changed their name and introduced blockchain into their name and the stock price increases, I think, 3-fold over 10 hours or something like that. Yeah, and in the end you think, perhaps this blockchain thing is something for me. So, you ask some experts and if they are real experts, then in 95% of all cases, it will turn out that you actually don't need a blockchain. So, but there are, of course, legitimate use cases for blockchains, otherwise I wouldn't be here. And in addition to that, this thing that you're wasting electricity in mining is actually not essential. There is something that is called proof of stake, which can hopefully replace proof of work really soon. And most token sales are scams, but a token sale is actually an interesting way to fund a project if it's done right. So you shouldn't be allowed to just walk away with the money and you can't build a token sale such that this is technically not possible. And there are, of course, some good use cases for blockchains in general. And let me just show you two example use cases of blockchains, where using a blockchain actually makes a lot of sense. And then we will start with writing some very simple smart contracts. And one of these use cases is the swarm system. It's a decentralized file system, so basically a way to store your data in the cloud, where the cloud just doesn't mean Amazon's compute farm, but hard disks donated by users of the system. And it uses a bit torrent-like system to distribute the data. But you can't use bit torrent right away for distributing data, so you can't use it right away for a general file storage system, because it has some flaws. And these unpopular files are deleted after some time, so only popular content stays available. And what can I do? Okay, just speak louder. You can try that. I mean, do we actually need speakers for this room? Perhaps you can use the microphone just for the streaming. People in the back, do you need speakers? Sure. Yeah, for now it's fine. Okay, good. So in BitTorrent, there's actually no advantage for you to upload files. It improves the situation. Try again, please. There's an Echo in the room. Okay, let's just try to continue. In BitTorrent, people send each other files, and usually you only want to have a file, you have no incentive, you have no gain in sending other people some files. It's part of the protocol, so people do it, and that's why it works. But yeah, for general file storage system again, why should you send some other person's backups or their own backups? And the blockchain can solve these two problems. It can pay people for storing files, so it works by you giving someone money for storing your files, and that person basically promises to not delete them and make them available, and this promise is done in a monetary way, so they send some money to a locked account, and if that person cannot provide the files when you need them, the money in that locked account is destroyed or you might even get a share in that or something like that. So, that person is incentivized and also paid for keeping your data available. And then even if your data is available, when they just send it in one bit at a time, then that doesn't help much because you need your terabytes of backup at some point and you're also willing to pay for having faster download, so people also pay each other for providing bandwidths. And that can be solved by a blockchain. And in general, coming up with these rules, who pays whom in which situations and whose deposits get destroyed and so on, this is called crypto economics or in more general the mathematical branch is called mechanism design. And then another thing that can be nicely solved with blockchains is removing the problem of you having to trust so-called certificate authorities when you browse the web. And so, this works, whenever you access a website that is encrypted, encryption solves two issues here. The first issue is that you don't want your data to be publicly visible. And the second issue, you want to be sure that you're actually connected to the correct website. This mostly works because you enter the correct name, if someone has a tap on your internet connection, then they can pretend to be that person and still intercept your data or even modify it. And this is currently solved by certain organizations. I think there are more than hundreds of them who kind of sign certificates that claim that the person you're currently communicating with ist the person behind a certain name. And this is, of course, really badly flawed because there are 100 of these organizations and any of these organizations can give out such a certificate. And most of them are distributed all around the world in various questionable regimes and so on. So, yeah, this doesn't look nice. And another problem is that domain ownership itself is not part of the system. So such a CA can issue a certificate and they are obliged to check that you're the legitimate owner of that domain, but this is not part of the protocol. So if they don't do it, I mean, someone might notice at some point, but they can just skip checking that. And also, the way, so the, yeah, the thoroughness in which this check is done on, yeah, dramatically depends on the specific certificate authority. Now, yeah, anyone, everyone can easily create fake certificates on a technical level. And a blockchain-based system and, yeah, for example, the Ethereum name system can go the whole way. So there you can build a system where the allocation of names and the issuing of certificates is part of the same protocol and cannot be faked on a technical level. So you can, yeah, the certificate that is issued will be stored on the blockchain together with the same record that states that you own that name in the name system. And, of course, the same system can be applied to something that is not about DNS but about anything that is kind of ownership of virtual things. And, for example, land registries is in a certain way it stores ownership of a virtual thing. I mean, it's not, yeah, I mean, virtual thing in the sense that an artificial distribution of land made by humans, kind of virtual, and it is already, I mean, it's already a virtual thing that is stored in digital databases in town halls and things like that. And, of course, here in Germany, this is probably not such a big issue, but there are certainly countries where land registries are prone to corruption and a system where, yeah, this is technically impossible, might help there. And, in general, so coming back to this flowchart diagram of earlier, when are blockchains useful? And, in my opinion, blockchains are useful if the application you want to add a blockchain to is already digitized. So it doesn't help with, yeah, I don't know, postal services where you have to confirm that you received a package or something like that because this is a purely physical thing. But land registries, which are already digital, can be used here where the enforcement of ownership is, of course, a separate thing. And then, yeah, participants have to have conflicting goals. If you don't have conflicting goals, you can use a regular database because nobody has an incentive to commit fraud. Yeah, even if you have conflicting goals, at least if all participants have a specific third party who they trust, then there's also no sense in using a blockchain because you can use a database controlled by that third party. So these three things, I think, yes, application is digitized, participants have conflicting goals and there's no trusted third party. And then, the fourth important thing is to be aware that using a blockchain is probably much more costly than not using a blockchain. So these three things on top have to be so important for you that you can cope with the additional costs that come using the blockchain. Okay, then let's get to the a little bit more technical part. What is Ethereum? Yeah, in general Ethereum is a database. And the interesting thing about Ethereum is that it's not running on a single computer, but it is running on thousands of computers all around the globe. And because of that, you can say it's decentralized. It's also a transparent database, meaning that everyone can take a look at the database, everyone can take a look at modifications of the database. It is manipulation-resistant, which means that if the database does not allow a certain modification, then it is very, very hard to do such a modification. It is also authenticated, which means that any modification to the database, any message-centered system is signed so it's digitally signed by the center of that message. And it's publicly accessible means everyone who wants can use the database, but also modify the database. This is also a very so very big simplification and also everything I will say in the following is probably a very big simplification. So if you have questions please ask. I mean perhaps not now, but later. So what is a smart contract? Smart contracts are neither smart nor smart contracts. They are just programs running on a database, nothing more, nothing less. Okay, a little bit more and this little bit more is that this database is a blockchain. But that's it. You can also think of them as stored procedures in a blockchain-based database if you know what stored procedures are. Okay, that's it for the introductory talk. There are some smart contracts. There are instructions behind the link there on the top. This is the most annoying part getting this link to you. And I could do that. And so who has not yet installed the Metamask browser plugin. And so I hope the setup of the tables here help. And I would ask everyone to help each other, because that way I think it works best. We have some people who will walk around a little and help out. But we have to build on you helping each other. So who has installed the plugin already? Okay, that's almost a compliment. Good, I think everyone will get along. Good. Now the next big hurdle we have to cross is getting every one of you to test that. So we won't do these yeah we won't program smart contracts on the actual Ethereum main network because that would be too expensive. But instead we will do it on a testnet where it's yeah, that is meant for testing and where the currency Ether has no value. But still every one of you needs to get some of these of this testnet Ether. And we will do it on a network called Rinkipi that's one of the testnets. And I think yeah, so I think we will start taking a look at that and now I need my second hand. So I'm not sure what we do now. Perhaps do you have something to hang that? Or should I try that one again? Okay, no worries. So these are the instructions here. Who has set up the Metamask plugin. So this little fox here and make sure that it is set to Rinkipi testnet and not to mainnet. Who is at that stage? So at least one person from each table I think. Good. Now if you ever plan to use this account also on the mainnet why is it to create separate accounts for each of the networks. And you can also name your account just put Rinkipi there just to make sure so that you not accidentally confuse these 40.000 US Dollars for real US Dollars or something or even worse the other way around. And you can switch the account using that icon here and you can create a new account here. Okay I have another Oh, yes. Someone wanted me to put that on the Meta page. I think I'm not signed in here. Nope. Can someone of you do that please? Put the link into the Meta page. Mois Can you put this link into the Meta page? Or someone else just said? Okay, thanks. So the next step is for you to get Rinkipi Tesla Ether is everyone comfortable with using one of the suggested methods? Sorry, let's just close this annoying thing. Yeah we somehow forgot to set up a communication channel for this Meetup. Sorry about that. He's just doing it. He does everything. So So who does neither use Twitter nor GitHub? Okay, so because these are the two ways to get Testnet Ether and so it works like this faucet Okay, sorry, no it's not Twitter or GitHub. You can either use one of these three methods or put a comment with your Rinkipi Testnet Count number at the bottom of the of the gist with the instructions Testnet work for everyone and then I will send you some of mine. Oh, we can also use another way that's perhaps most Yeah, does that work with guest accounts? Just paste your address here I will put this link into the gist Okay, that's an unfortunately a rather annoying process in the beginning. This is also a rather annoying process in reality with the actual Ethereum network but once we're past that, it only gets better So, yeah, if you can't use Twitter or any of the other methods to get Testnet Ether please request it by pasting your address into that thing Does that work for you? Can you edit it? So I posted that below the instructions site So, does it work for anyone? So, did you already paste stuff? Because as soon as you paste stuff there Okay, wonderful So, now we can see how that all works And so, as this is as I said, a collaborative workshop people who already have enough Testnet Ether can try to send some to the other addresses here and then mark them as already sent So, I will now This is a bit annoying, I'm sorry I think I'll switch my video setup to mirrored, is that fine? That will change the resolution, I think Okay, I just copied the address and this is my metamask plugin now I have some Testnet Ether I will send some to the address I just copied I think one Ether should be enough I click next now now I see all the information again Sorry, I can't increase the size here and then I click submit And now it created a transaction and send it via this centralized gateway but still to the decentralized Ethereum network and I can click here to get more details on the so-called blockchain explorer which is also a centralized thing but still better than nothing and it says it's pending now This means the transaction has to wait for a so-called miner to include the transaction in the next block Miners are people who are randomly selected by a certain process to determine the order of transaction and determining the order of transaction is important because in the sense that I want to send one Ether to person A or I want to send all Ether I have in my account to person A and all Ether I have in my account to person B and those two transactions cannot be valid at the same point So someone has to determine which of the transaction is the one that goes in first and that one will be the one that is valid in the end The transaction has a I can increase the font size here So the transaction has a from field which is the sender and a to field which is the recipient a value, the amount of Ether that is sent and a gas limit we will come to that later Now it's a success here which means the transaction was included in the block This is the number of the blocks Blocks are numbered consecutively starting from zero When I click on the block now I get information on the block and it has a time stamp of 51 seconds ago It includes 18 transactions so 17 transactions apart from the one I included It has a hash Hashes are rather important in blockchains but I think we will not be able to cover them It has a parent hash which is kind of a link to the previous block and this is the address of the miner the miner is awarded by Zero Ether in the testnet and on the realnet the miner gets an actual reward for working on participating in this random selection which is a computation intensive process Yes So I think that's the uncles are a complicated process which basically allow to reduce the block time from 10 minutes as it is in bitcoin to 15 seconds as it is in ethereum and if you reduce the block time then it's much more likely for this random selection process to kind of select two minors at the same time and then they would produce two parallel blocks and because of that they would be conflicting in the same way as two parallel transactions from the same person would be conflicting and this random selection process this mining in the end will find a way to select one of these two parallel blocks as the canonical block but this takes a while so you want to reduce or increase the speed of the blockchain network to converge on one of the alternatives and uncles is a way to do that because complicated I mean it's not too complicated but perhaps a little bit too complicated for this workshop so the person who requested the test and ether did you get it who was it you good now let's take a look at this dashboard that you see when you go to rinkabee.io this views the current network it has the current best block so the block height the block time which is a diagram of how long it takes from one block to the next this is a random process which happens roughly every 15 seconds so that's the reason for the variation here block propagation is a diagram that shows how the newly created blocks are distributed inside the network yeah okay, then I will send some more so this is done so you probably need 0.001 ether for this workshop so it would be fine if someone could help me distribute ether this is marked currently sending yeah, that was faster than I expected okay only 6 addresses that doesn't sound correct who has tested ether now wow, nice so I assume everyone is fine now oh, another address okay, someone is greedy probably okay, so someone who still does not have tested ether now I think you can handle that in your tables locally okay, now ether is only part of the fun of course we can now send around tested ether, which is already nice if it would be real ether, we could use it to pay for whatever pizza but of course what we all came here for was smart contracts and because there is so great support for it we will still do a rather boring thing that smart contracts can be used for and that is tokens so this is almost the same as ether but still there are big differences because you can create tokens with yeah, you can when you create a new token you create a token that is destroyed randomly or where new tokens are created at certain points in time whether it's some kind of thing that goes in the direction of universal basic income or whether it's just ownership tokens or virtual kitties or whatever okay, where are the instructions again? so let's take a look now at this example contract put here the simple contract for now it's just source code but we will create that as a smart contract on the blockchain and for that we use the IDE remix which is at remix.etherium.org let me reload that so that's a development environment for solidity but it also so where it's really strong is that it has an integrated execution environment so it can create a virtual blockchain that only runs in your browser where you can call functions and test the behavior of the smart contracts you write then you can modify some part and run it again and you can also interface with the real blockchain and deploy stuff either on the testnet or on the real network we only have to wait for it to load oh sorry i didn't meant to use firefox anyway are there any questions for now? i know you all really badly want to write smart contracts but we have to wait for the website to load an empty one i guess i mean i created the compiler so there was something to test but i think yeah it didn't start with contracts it just started with simple expressions yeah that is weird does it load for you? okay then perhaps start refresh refresh? yeah i just did so perhaps start by pasting the simple contract source code that you have here into the source code part there is a rather complicated smart contract there by default you can just erase that and replace it by this simple one yeah i can explain some aspects just on the source code so this first line just tells the compiler or yeah tells the compiler which version you want to have or which it should expect so that you aren't surprised by any breaking changes and then you have this contract keyword and that's a name for your for the contract you want to create so one tiny is that there is no there are no two different words for a contract a specific contract that is deployed on the blockchain and the source code corresponding to that contract both is called contract and the source code contract there is only one but you can have multiple copies of them multiple copies of the same source code on the blockchain in programming terms that would be the distinction between class for us and so it has a variable here called stored number this number is permanently stored on the blockchain and if you so uint means it's an unsight integer of 256 bits that's the default and public means it will the compiler will generate a function for you to read the value that is stored there and then you have a function called name which is public which means it's accessible from outside it is pure which means it's not allowed to modify the blockchain state and it returns a string and what it returns is my github username and then you have another function which the interesting part starts it's called stored number it takes a parameter wolf type unsight integer again name x it's publicly available so which means everyone can call it and what it does is it modifies the value of the number that is stored in this slot here so you can write and you can use that function to store an arbitrary number inside the smart contract here so so so let's try to run that you can run that on rinkeby but ok i think you now have to click start to compile or take auto compile then auto compile whenever you change something now if you click on details here you can get some details about the contract i'm not sure if we should dive into them at this point perhaps not and now the interesting part is when you go to the run tab here because there you can select a contract in your source code and when you click the red create button it will create a transaction that will create the contract this selection at the top is very important because that determines where the smart contract is created if you select javascript vm it will create it in a virtual blockchain just in your briser if you select injected web 3 then it will create it on the rinkeby testnet and let's do this just for now so if you click create here then the metamask plugin will pop up and will ask you to confirm it it now has a different icon here because it creates a contract instead of just sending ether and we can now click submit and we will again get a pending transaction damn it sorry so this is the glitch i was talking about if you use firefox then the browser will not properly work with contract calls so you have to go through here again click on the pending transaction and then you will see this in the blockchain explorer i will show you how it looks in chrome yeah ok so the thing is this smart contract will now be created at a certain address so everything has addresses we already talked about addresses because you got an address contracts also have an address and when you want to interact with a contract you have to know its address because that's where you send your transaction to ok metamask already says it's confirmed ether scan does not say it's confirmed yet perhaps a reload will help nope confirmed so and now it says contract created at this address and here you can see the contract bytecode so the there is a certain virtual machine called the virtual machine which has a separate bytecode that is different from all other virtual machines and this is it's hex it doesn't matter representation ok now it says contract created we copy this address or actually let's just go there i mean you all did that in parallel i guess so you have different addresses there of course but that doesn't matter now in this blockchain explorer we have a view because the address we are now looking at is a contract address which has a tab called code where we can look at the code this doesn't help us very much so that's the hexadecimal view and that's the bytecode view which is similar to some assembly code and this is really annoying to look at and because of that so but we actually know the source code behind there but etherscan doesn't know this so the centralized component doesn't know it only our browser knows it but there's a way to tell it what the source code behind this contract is and this is always very useful to use and you use this you get to that using this verifying publish link here in the code tab ok am i too fast am i too slow ok so where are you excuse me which what ah sorry i used injected web so everyone of you has the source code you copied it from the instructions can i see some hands ok good now you select injected web which should be the default anyway and you click the red create button metamask pops up you confirm so i'll do it again so click create here and metamask pops up ok now ok the step that was probably a bit too fast is how to get to the um to the other website here so i just signed the transaction and the plugin disappeared again so i i open it up again so the top entry is an entry that has these 3 dots or perhaps is already confirmed but in any case you click on this icon here which will lead you to the etherscan website and it's the website for the transaction and the transaction should say contract created with a green mark ok question yes the find similar contracts i'll just repeat your question yes so i didn't verify it yet so the question was whether etherscan has a functionality where it can find contracts with the same source code automatically or semi-automatically and the question was why is this not working in this case now and the reason is i haven't upload my source code yet to etherscan at least that's what i think is the reason ok now you click on the contract address and you see a transaction so the creation transaction of the contract you see who created it so as i said earlier every transaction every message in ethereum always has a sender it's always authenticated and even the contract creation has a kind of origin ok now you click on the code tab and then on verify and publish so did i still lose someone ok verify and publish let's click on that ok now we get to a very complicated website which will hopefully get simpler by a compiler feature we hopefully will be able to release soon so what you do is the address should already be correct you paste your source code into the bottom part here so we all paste the same source code unless somebody modified the string here perhaps perhaps next time ok we paste the thing here so because a single source file can contain multiple contracts we have to specify the name here my named account stupid example don't read too much into it and then you have to select the compiler this is most probably v0423 plus something so the compilers with nightly should not be used for such things only the one that start that have commit directly check again by going back to remix sorry or here in the top there should be the compiler version in the address bar optimizations is the second setting we need to check so we still have to go to settings enable optimization is probably turned off i think it will also appear in the address bar optimize false so if optimizes false here then you have to switch optimization from yes to no so so so BITE CODE so Also, wenn ich hier einfach den Namen der Funktion ändern könnte, oder sogar besser, wenn ich diesen X und 2 ändern könnte, dann würde dieser Funktion etwas anderes machen, als ich gedacht hätte. Und, ja, durch ein paar Gründe, ist es unmöglich, den incorrecten, es unmöglich, hier eine andere Source-Kode zu geben, aber es ist nicht möglich, die Source-Kode aus der Byte-Kode zu regnen. Die Byte-Kode verliert Informationen, weil es viel mehr kompakt ist, aber es hat noch eine Hache der Source-Kode. Und was sie tun, ist, dass sie nur reinkompilieren, die Source-Kode, die wir hier mit den Settings geben, und wenn sie den selben Byte-Kode besitzen, dann sagen sie, dass das die Source-Kode ist. Und der Rest hier kann jetzt für mich ignoriert werden. Und, ja, es ist ein zentraler Service, also es benutzt andere zentraler Services. Hm, ja, das funktioniert nicht. Lass uns das mal wieder versuchen. Ist das nicht für jemand anderes zu arbeiten? Hast du einen anderen Setting geändert? Lass uns das mal wieder versuchen. Ah, okay, jetzt ist es funktioniert. So, jetzt ist es eine Konfirmation-Page, und wenn wir zurückgehen, ich weiß nicht, ich habe es nur wieder versucht. Du klickst auf die Kode-Tab, und dann ist es hier drin. Wenn ich diese Website reloade, soll mir die Source-Kode zeigen. Ja, wenn ich jetzt auf die Kode klickte, wir haben hier die actuale Source-Kode. Es ist verified, exakt, alles ist okay. Und jetzt, so eine Sache, bevor ich die Frage komme, ist, wir haben eine Read-Contract-Tab, wo wir mit dem Smart-Contract interacten können. Z.B., es nennt die Name-Funktion für uns und die Strecke, die es regnet. Ja, das ist nicht eine sehr gute Interface, mit dem Smart-Contract. Wir können das gleiche von Remix machen, das zeichne ich dir später, aber es gibt Fragen. So, die Byte-Kode, wenn du die Source-Kode nicht verändern wirst, wenn du das gleiche Compiler-Version und die gleichen Settings nimmst, dann wird jeder genau das gleiche Byte-Kode bekommen. Also, ich glaube, ich kann das nicht... Okay, so, das sollte genau das gleiche sein für alle uns. Aber was ist anders ist das Sender-Adress. Der Person, der die Transaktion beobachtet, um den Kontakt zu schaffen, und der Adress, bei dem der neue Kontakt ist gebildet, ist der Sender-Adress. Und weil der Sender-Adress ist gebildet, wird jeder einen anderen Smart-Contract bekommen. In dem Sinne, dass ein Smart-Contract einen anderen Adress hat, aber es wird identifizieren von dem gleichen Kontakt. Entschuldigung, ich verstehe es nicht. Was meinst du von dem Adress-Contract? In der Transaktion, die den Kontakt kreiert, wie das sagt. Okay, Transaktion von B nach B, oder so, der Kontakt wird gebildet. Ja, das ist der Adress. Ja, der Adress, bei dem der Instanz ist gebildet. Okay, also jeder von uns wird einen anderen Adress haben. Ja. Und das Bite-Kode-Adress, wie das Idee des... Ist das da? Das ist das Gleiche für alle. Das Bite-Kode ist das Gleiche für alle. Ist das eine Idee für das Bite-Kode? Das ist nur das Bite-String. Okay. So, ihr könnt es sehen, ob ihr den Link klickt. Ja. Oder das ist das Gleiche. Ich meine, das ist nicht der... Ja. Ja. Es ist kompresse Information. Man kann nur... Man kann es zeigen, dass man den Weg ging. Und damit kann man zurückgehen. Aber man kann... Wenn ihr nicht das Source-Kode kennt, gibt es meistens keinen Weg zu zurückgehen, weil es fängt an Hasch-Funktionen. Okay, so, jetzt machen wir ein paar interessante Dinge. Okay. Die Leute, die Chrome genutzt haben, werden automatisch und für alle anderen, oder zumindest für Firefox, werden sie das manual machen. Was wir machen, ist, wir copy die Adresse des Smart Contracts. Es ist in der URL der Remix. Wir copy die Smart Contracts, wir gehen zurück zur Remix. Wir klicken auf die Run-Tab. Und die Leute, die Chrome genutzt haben, werden hier etwas haben. Und durch ein Glitch, in dem Connect between Firefox und der Metamask Plugin, müssen wir das manual machen. Und was wir haben, ist, wir müssen die Adresse hier in die... Inputbox neben der Add-Adress-Button und dann klicken auf Add-Adress. Und das basically tells Remix, hey, an dieser adress in der Blockchain, da ist ein Kontrakt des Types, das hier selektiert wurde. Und by that, Remix provides us with an interface to interact with the Smart Contract. It creates one button for every public function that we can call. So this Add-Adress-Button is always a little bit confusing. Create, creates a transaction, actually creating Smart Contract. And Add-Adress just tells Remix to display an interface to you that allows you to interact with a pre-existing Smart Contract. So the create button does not run method. It just creates the Smart Contract. So, any question for this step? Was it again too fast? Yeah? What do you mean? Why are we using this Add-Adress-Button? So we're using this Add-Adress-Button to get this interface here below. If you use Chrome, you already have it, because it will be created automatically. Yes. There can be multiple of these here. And depending on what you select it here in the top... Yeah, exactly. So the question was about the Contract Address and what it is. It has nothing to do with the block. It is just an Address of an account you create that is not a Smart Contract, but is derived from the public key of your public-private key pair. And for Smart Contracts, the Address is derived from... Yeah, basically from the account that created the Smart Contract. So the account that created the Smart Contract and the nonce that is incremented with this transaction. And at that Address, the data is stored. So blocks are a dimension of time and Addresses are a dimension of space. So they are unrelated to each other. So blocks are just there to group transactions and order transactions. So they determine in which order changes are applied to the blockchain. And Addresses determine where data is stored, where changes can be applied. So of course a Smart Contract is created in a certain block. So it starts existing from a certain block, but yeah, so the bytecode of the Smart Contract logic is stored in the block now. So the transaction that created the Smart Contract, which kind of includes... So the bytecode of the Smart Contract is part of the transaction that creates the Smart Contract and that transaction is part of the block. But you can't really say that the final Smart Contract code is stored in the block. It is stored in the blockchain. Add an Address. So, so we have this interface here. We can click buttons. Blue buttons are buttons which do not cause a change in the blockchain. They just read from the blockchain. Because of that they are free of charge and are executed instantly. So you don't need to confirm the transaction with Metamask. And if I click Name, it says ChrisF and stored number is probably zero, yes. And I can give an argument for the function StoreNumber here. Let's use 17. And we click StoreNumber. Then we'll execute this function here with argument of 17, which means that it stores 70 in the stored number here. I click the button Metamask will pop up. Ask me for confirmation. I confirm. Now we have to wait for the transaction to be included. Key on the left here it says transaction was included. And now when I click StoreNumber again it re-evaluates the function. It should say 17, so let's check. Yeah. Sorry. Is it more or less clear how to interact with smart contracts now using this interface? Okay. Just out of curiosity there are these buts here, Details and Debug. If you click Debug then you will get to the second big which is a Debugger. You can run that on any transactions where they are. Older transactions. It's not a debugger that executes and you can stop it at some point. It's more like an execution inspector. So you can re-run. So there's actually a slider which represents time. You can run back and forth. Yeah. Let's not get too deep into that. Okay. Now let's go to the next stage and create a token. So there's the second contract that was linked. Now we'll do it in a different way. And this time I will create the smart contract and you will use it. So. Yeah. Again? Just to speak louder, please. Yes, I have to pay something, right? To send my integer. What determines the cost of that? Who decides how much do I have to pay? You decide. So the question was what I didn't tell much earlier because we use it on the test. So when you want some execution to be performed Wenn du keine permanenten Veränderungen in deinem Blockchain willst, dann musst du die Menschen dafür bezahlen. Wenn das Netz nicht auf ihre eigene Ebene ist, dann musst du für Dinge zu tun werden. Und das ist in einer Unik called Gas paid. Gas mehr-oder-less measures the amount of computation required, and then there's the second factor called the gas price. This means how much you're willing to pay per unit of gas. And this is something you set when you create the transaction. It's not too visible a Metamask, I think. It kind of determines that on its own. But in other interfaces you sometimes have a slider where you can select to either pay more or pay less. If you pay more, then your transaction will be included earlier. If you pay less, it's cheaper, but it will take longer for your transaction to be included. It might even happen that your transaction is never included. That's kind of how it works. Did I answer your question? Okay. So, yeah, let me create the smart contract. I will verify the source code, and then I will share the address with you, and we will interact with it. Yeah, I just wrote that smart contract in the afternoon, didn't test it yet, let's hope it works. So now it looks like Metamask doesn't work, so let's do it again in Firefox. Okay, looks like Chrome isn't better. So that's the creation of the weird token contract. We can already take a look at it. So, the weird token has a name. It's called weird token. It has a symbol, which is a short version of its name. It has decimals, which we can ignore. And the most important thing is this mapping called balances. And this kind of holds the, for every possible address, it holds the amount of token that is assigned to the address. So this is kind of the balance sheet of this token system. And it also has a total supply, which is the overall amount of tokens, the sum of all tokens, the sum of all balances. We have a function called balance of. It takes an address and can be used to read the balance at that address. And we have a function called transfer, which takes a true address and a value. And yeah, what does a transfer function do? It checks whether the person that wants to send tokens has enough balance, so has at least a certain value. I already said that all transactions have a sender and you can access this sender using msg.sender here. That's a special value in Solidity, which can be used to access the sender of a transaction or more specifically the caller of a function. So transfer, so, you can perhaps see that transfer has no authentication part. So it doesn't ask whether the person, so whether someone is allowed to transfer tokens. And the reason is because every transaction is signed, it is already authorized by the signer. So when you send a transaction, you always have to authorize. So, by accessing msg.sender, this already means that the sender has authorized the transaction, so the sender has authorized the transfer of the tokens by invoking that function. And this is something I really like about Ethereum, because you don't have to think about, yeah, who can do that, and do I have to ask for a password or something. This is all abstracted away in the cryptography below. In the small contract level, you just ask for who does this, who wants to do something, then, of course, yeah, you can check if they are allowed to do that, but you don't have to check if they are actually that person. So transfer works by the person invoking the function, asking to transfer a certain amount to a certain address. So we check that the person has at least that balance. And if that is the case, then reduce that person's balance by that value, and we add the same value to the recipient. And we emit an event to tell our environment that something happened. Now, I'll get back to the two functions below in a second. Let's just check whether the transaction succeeded. Okay, now the address. So I'll add that to the HackMD and to the other one. Yeah, someone was faster. Wow. Okay, I'll also add it here. So what you do now is you use this add address function to tell Remix where the token is. Okay, I will remove that here. Okay, now we have this nice token contract. Please paste the address here and use add address. Make sure that you selected weird token. And then make sure that you have this interface here. Please do not use your own instance of the weird token because all of us want to use the same token, of course. So now you probably ask yourself, how do I get one of these shiny new weird tokens? Right? Now, let's take a look at the two functions below here. And this create token functions already sounds like it would create tokens, but it's marked internal, which means it cannot be called from outside. What it does is increases the balance of the sender by one token and also the total amount, total number of tokens in existence. But as I said, it cannot be called from outside. It is called from here inside the request token mathematically function. And that is a public function, so that's good. But it starts with two require statements. And if the argument inside the require statement is false, then this will cause the transaction to be reverted. So it will stop executing and revert any effects it might have had. So you have to think of a way to make this condition true. So multiple of 17 has to be zero modulo 17. And number used at multiple of 17 has to be false. And you invoke this request token mathematically function by, of course, clicking this red button here. And I fear that if you just click the red button now, the first person who does that will get a token. Can someone explain why? So the thing is, we don't do ... Orjan, do we do input checking here? If you just leave this input box empty, it will use zero as value, right? So if you leave this empty and just press the red button here, it will use zero for multiple of 17. And what will happen inside the smart contract here when multiple of 17 is zero? Yeah, I mean, this module is a bit complicated perhaps for people who are not used that. It checks whether multiple of 17 is a multiple of 17. So an integer multiple of 17. So zero times 17, one times 17, two times 17, three times 17, and so on. And zero seems to be zero times 17. So this check passes. And the second check is just ... So everything is false by default. So this reference is the mapping here. And this is just a means to say that no two numbers can be used twice. So if you use multiple of 17 once, then this is set to true. And if someone uses the same number later, it will stop here because that will no longer be true. Question? So the question was if two people use the same number at the same time, but one gives a higher gas price, that person is more likely to get the token. It depends. So it depends on the miners. I think they currently saw transactions by gas costs, but I'm not ... So this is a testnet. Their things might also be a little bit different. But you're probably right. Yes. So the person that uses a higher gas cost is more likely to get the token, I think. But also, I mean, it really depends on timing. I mean, if the miner is not aware of the second transaction yet, but is aware of the first transaction already, then it's ... Yeah. So it's a decentralized network, so you cannot predict anything about timing. That's the whole thing that blockchain solves. And because this is a token and it implements the so-called ERC20 standard, blockchain explorers have special support for that. And we can use that support by telling EthaScan that this is actually an ERC20 token. I will do that now. I think I just have to reload. So EthaScan will notice that this is an ERC20 token. As soon as this event is fired. Oh, yeah, it already did. So it automatically recognized that it's an ERC20 token. And we click here now. We will get more information about the tokens. Yeah, we already have 12 addresses that have tokens. And we can get a list of all token holders. One token holder is already quite wealthy. And, yeah, let's see. I'm wondering whether we can see which numbers were already used. I mean, of course, we can... I know it's not publicly visible. Yeah, we can take a look at the... I know we can't take a look. We have to look at the transactions and there we can see which numbers are used, I think. Yeah, we have to click on the... That's not too convenient, but... Yeah, here one CB in hex. That is a number. Oh, yeah, that's a good idea. The question was, can we make the token visible in Metamask? And I think so, yes. You just have to copy the contract address, the token contract address, then click on Metamask. And then you switch to the token tab here. So there's a send tab and the token tab. And you click on Add Token. You enter the token contract address, so you paste. It automatically loads the token symbol. Then we click Add and it will say that I have zero tokens. Yeah, that's a different token. So, let me get some of these tokens, too. I don't think so. Okay, how do I secretly come up with a multiple of 17 before you realize? So, we have 256 bits, right? So, if you have larger numbers here, then you put them in quotes. Larger than the precision for JavaScript. 256 bits. 256 bits. Again, please. This is 32 bytes in storage. You can choose to use a smaller one by putting the number of bits after the Uint, so Uint 80, for example. Oops. But there's no big advantage in using smaller numbers, because the Ethereum Virtual Machine has the default data type for the Ethereum Virtual Machine is 256-bit integers. Everything smaller has to add additional operations to make it work for the smaller size. It might be an advantage in storage sometimes. So, if you want to store many small numbers, it might be an advantage, but you have to try. Yes. You can't use them for sub-scripts. What do you mean by that? For array index. I don't know you can't. I wouldn't also see a reason for that. Okay, so let's see if I got some. Nice. Testnetworks. Okay. Any questions? Yeah. In the source code of the weird token, we have to change the balance of the sender and the receiver, but then we emit an event, right? What is the event for? The question is, so in the weird token, we change the balances of the sender and the receiver, and then we emit an event. And the question was, what is the event for? The event is, because it makes it easier for outside viewers to see what happens. If they want to see, so events are stored at a certain place, which is much easier accessible. If we wouldn't have events, everyone would have to rerun the execution and basically look inside the execution and see what happens. And with events, you can just take a look at the blockchain itself and notice that something happened. Does it make it more transparent? No, it's more like easier searchable. So, why does EtherScan recognize the concept of token, no? Yeah. So the question is, how does MetaMask see the concepts? How does it know that this contract represents a token? And you just told it is a token. You set a new token at that address. Right? This is just a random code that I broke. Yeah, but I mean... So the minimum requirements for a token is this transfer function that will be called... Okay, I mean, why we added this token... Yes, yes. So why we added the token to MetaMask is because now we can actually transfer tokens directly. At least I thought. Okay. Yeah, that's weird. Okay, it looks like MetaMask doesn't support that. So many Ethereum Wallets support also transferring tokens automatically. It looks like MetaMask only supports displaying that, displaying them. But yeah. Okay, whatever. So, we're going back to your question. So the minimum requirement for a token contract is this transfer function and the balance of function. And perhaps the name... But yeah, the balance of function allows you to query your balance and the transfer function allows you to transfer tokens. And then we also have this event here. This transfer event, which is also useful to... So that you don't have to search the full blockchain all the time. And if it's there in the contract, then it is a token. I mean, so having said that, of course the fact that we have a function called transfer doesn't automatically mean that the transfer function also transfers tokens. We can put whatever we want here inside the code. So we can say if it's a Sunday, then all transfer functions will send tokens to a special address. And if it's a Monday, then half of them are burned. And on all other days, we have correct transfers. We can emulate the existing traditional banking system and say transfers in Sunday are not allowed. Nice. So the question was... So the question was whether the transfer event executes any logic? No, I mean, it's just... It stores this data you supply in a special data structure that is easily accessible from outside but does not execute any code. Okay, now our next task. Try to get more than one token in a single transaction. So for now we just click this red button and we have to find a new multiple of 17 and we get one token in return. Okay? Is there a way to click a red button and get more than one token in return? I'll give you a hint. It will require a little bit more than copy-pasting. I mean, yeah, so more than one of these tokens, so from this contract. Now, the contract stays the same. But it was exactly the same contract? Yes. We what? Oh, it's not an exploit. I mean, so RequestToken mathematically accomplishes one token for every conceivable multiple of 17. So the exact task is, is there a way to click a red button here in Remix so to execute a state-changing function on some smart contract which will then award you with more than one of these weird tokens in return. Yes, very good. So we have to write our own smart contract that calls RequestToken mathematically on the token contract. And, of course, multiple times. And yes, the difficult task is coming up with code that kind of finds multiples of 17 in a different way than in the way all others in the room do it. So, let's try to find, so I will show you how a very simple contract that does that looks like. So I click on this plus button on the top left. And now, okay, what is a bit annoying? Okay, actually, yeah, don't click the plus button. It's much easier to just add another smart contract below the weird token. So just add something below here. And so the most important thing is that this new smart contract needs to know the address of the weird token smart contract because it needs to interact with it. And I do that by... What was the addressing? Was is this one here? So if you still have it here, you can just click on this button to copy the address into the clipboard. And then you paste it here. Okay, we have an error here. Yeah, okay. We can't use that address. Jan, can I file an issue? Did you see the error message here? Can you encode it in the checksum with correct checksum? Why not? Okay, so, yeah, addresses in Ethereum have some checksum, which uses upper and lower case of hexadecimal letters. And actually, yeah, if you click on compile here, they actually should show how the correct checksum looks like. Okay, I will paste that somewhere. Sorry about that. Let's also not check summed. Ah, here it is, okay. So this is the address with checksum, because it has an uppercase Fe here and a lower case E. I just can't copy it because the browser does weird things. Okay. Okay, now we need to tell the compiler that we actually think that this is really a weird token at this address. So... But so this is the most complicated part. Okay. I will put that in the HackMD. Okay, now what we do is function, getToken, public. And now we call weirdToken dot requestToken mathematically. And the most important thing now, so if we only do it like that, then of course I know this multiple of 17 is already taken. But more importantly, weirdToken will generate a token, but the token will be assigned to this smart contract. So it will not belong to our account, but it will belong to the account of the fountain contract. Okay, because the fountain contract called requestToken mathematically. And weirdToken assigns tokens to whoever called requestToken mathematically. So what we need to do is as a second step send the token further to the caller of the fountain. So we're token.transfer msg.sender and oneToken. So okay, one other complication that arises here. msg.sender in this context at this point here and msg.sender at this point here, so the person that gets at this point here. These are two different values. They always represent the caller of the current function. And if we call two functions after each other then this of course changes. Inside the fountain this is us calling getToken. But inside weirdToken it is fountain calling weirdToken. So was everyone able to copy that contract? Did you get this weird thing? If you have any red marks here on the left it means there is a compiler error so something is wrong. If you do not have any marks and you have a fountain in green here then it should be fine. Okay, let's see what happens when I create that contract. So make sure that you select the correct contract here that you want to create. Do you really need randomness? So best randomness is produced by so I just created this fountain contract and now I click on the getToken button and I get this message here. This is very bad UX because it just means that something failed. So it means one of these require statements here failed. The reason why it probably failed is because it was already taken. But I want to know the failure before I have to pay for it. Okay, let's send it anyway and then we can check in the debugger and see where it failed. But the debugger won't catch the source code correctly because I added the contract here. Ethoscan also has a debugger can check there but we already have a pull request pending that displays a nicely formatted error. It's perhaps not in guest estimation but that will improve soon. By the way, so whenever you see tooling lacking here and you can program there are tons of grant programs where you can just apply with an idea, get some money and improve the theorem ecosystem. So I think there are at least three different grant programs that are happy to give you money to work on improving the ecosystem. So there's this I think it's called ethprice. There's the ethium community fund and there's also the ethium foundation development grant program. Yeah, okay, that's nice. So Ethoscan now tells me this transaction failed and now the only reason so I want to know why it failed let's see what I can get some information there. Yeah, so Ethoscan has a debugger as a set so you can click on tools and utilities here and click on remix debugger. This will use more or less the same debugger we already saw. I think it's an older version, right Jan? Yeah, I think that's quite tricky to get. Yeah, they haven't even implemented return data copy, return data size, they don't know revert they really have to update their version. Okay, so I think we have to close the workshop in 15 min und go to the fun stuff that involves liquids, right? Has anyone succeeded in getting more than one token? How many? And what did you use? So 163 transactions or you also see where that transaction failed in the transaction list here? This is weird. 800, wow. Oh, no, someone is sparing that. Well, this is all the same address. No, it's the same transaction hash. Yeah, so there's an event for creating a single token inside the weird token smart contract which gets an entry for every single creation and then the final transfer of 100 is a single thing. Nice, nice. I'll show you an example how to get multiple tokens. Okay, how to get randomness next question just provided from outside. Yeah, rinker B. I mean, it doesn't have the source code so it's, so let's just so yeah, I mean what we could do is just copy that 10 times. Okay, so first of all we just multiply that by a second number we provide when we create the transaction. Oh, the interface is really slow. The question was whether state variables are by default public or private, they are private by default but that of course does not mean that they are secret. So everyone can read everything that is on the blockchain. And just select a random number here, then this will still be multiples of 17 and someone can only outrun me by taking a look at the pending transactions or taking a look at the screen here. So let's do that. Okay, create the contract. Sorry, what is the question? The question is whether the require only concerns the current function or whether it's cascading. I'm not sure what you mean. It's executed every single time. It's just a normal statement. Ah, right. So if a require fails everything will fail. So if one of these has already been taken then I will receive nothing. So and due to two reasons actually. So the first reason is that because a failing require here reverts the whole thing but even if it wouldn't I wouldn't be able to send 10 tokens to me here. Okay, let's see if that worked. Yep, so try to copy that. So if you agree you perhaps replace this 10 by 100 that wasn't the best idea because I think it will not work. And the reason is I already said earlier that you have to pay for everything but the reason for that is if you don't then you can easily spam the blockchain. You can just request a very expensive operation to be performed and it would take a long time and time is the important thing here because there's an upper limit on how much can be done inside a single block inside a single transaction and if you want to do more so yeah, there's just an upper bound this upper bound is kind of flexible it changes over time but it's a hard upper bound so if you change this to 100 or at least for 1000 it will certainly fail and so yeah, of course the solution to do that is to break it up into multiple transactions or one solution so okay, this was confirmed let's see how many tokens I have now yeah, it worked, 13 so I hope you learned think about smart contracts here question? kann ich das sieht? was ist denn der Fehler? also wenn der das nicht setzt nee, weil das sollte kein entschieden machen eigentlich das mul ist nicht bekannt das muss ein Argument das get token muss ein Parameter definieren dieses mul existiert nicht das wird übergeben okay, das hatte ich übergeben kann ein random number generieren oder so nee, nee, nee ja die Frage ist, wo hast du das Total Supply gesagt? also es startet mit 0 und es erhöht für alle Token, die es kreiert es startet mit 0 so Total Supply ist nicht ein fixer Number es verändert jedes Mal, dass ein Token kreiert ist dein Token, du kannst das machen, was du willst so currently es ist unlimit, du kannst einen unbundeten Token mit diesem smarten Kontrakt so wie gesagt ein Token das bedeutet nicht, dass es Geld ist so ein Token ist etwas, das kann transferred und ja das ist nicht Geld, weil es sehr leicht ist, neue Token zu bekommen mehr Fragen? okay kannst du mal kurz irgendwo einfügen, dass es noch kompliziert ist ah, jetzt kann sein, dass MUL reserviert ist jetzt hat es geklappt muss ich hier umschalten, damit er nochmal kommt danke okay, any more questions? ja ich bin just curious, how you are dividing into like a smaller transaction like you said you do fail for like a 1000 i assume i need for 10,000 is there some pattern that one can use and then have it like split it into the blocks, this like an operation in that case how one will revert if it's going to fail in the later stages so the question is if you have a long operation how do you split up into multiple transactions so that it fits into the blocks, i mean in this case it's trivial because i mean it already you can already split it up by just choosing a number and then running it multiple times but if the result of the first part is important for the second part then it's more tricky, i think there is no generic pattern you just have to save the state okay, that's the question and then continue on from there if some of the steps fail you just start over from the last successful one okay, so everything should be done manually yeah the value of the mapping of which of the number used of which mapping okay also this but i was referring to the the balances so you can't so for a mapping so mappings are yeah infinite in size kind of so you can't really get a full list of everything, there are ways but it's difficult but if you know you can look at certain points in the mapping and you can just use these blue buttons for that so you certainly cannot iterate over all the values inside a smart contract but there are ways to iterate over it from outside in a certain way so the key is you put inside the mapping, they are hashed and what you certainly will never get is the actual values of the keys it's a hash map, yes so solidity has a very low level language and it has to be extremely gas efficient because otherwise you can't do most of the operations on the blockchain and because of that mappings are the simplest thing you can think of that resembles a key value store if you also store the keys together with the values it's already much more expensive and that's why it's not done but you can build your own, use it and find data type on top of mapping that also stores the keys so how reliable is this map if there's a hash condition on two different keys would the value be it's a shard 256 so it's a a shard 3 hash with 32 bytes so there's practically no collision so but there's the risk it's not like the real hash map that has a link at least for every hash map it's not like a hash map where you cope with collisions it's a hash map that uses a large hash value where you hope that there will never be a collision so if you have a collision in the balances mapping then the whole blockchain is screwed because it uses the same hash function and if that has any collision then it's already too late this usually means that one of the requires failed one of the requires so you did something that was not allowed so for example one of your numbers was already taken wir haben gesagt zum Metamask gibt es noch Alternativen den normalen Noten natürlich von Ethereum aber sehen zu synchronisieren ist ja so painful es soll viel besser geworden sein das geht dann light sync kann man ja benutzen bis man zum ersten mal durch ist ne ne instantan also light mode geht instantan ich bin noch im Stream so i think we'll end the official part now i'm not sure what the agreements with the when you are actually so i think we can still stay but i guess let's end the live stream