Smart Contract Development: CryptoDoggies Token Game | Nathan Glover | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Smart Contract Development: CryptoDoggies Token Game

teacher avatar Nathan Glover, I love technology, I'm a maker at heart!

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Welcome to the Course


    • 2.

      What Is Ethereum?


    • 3.

      Introduction to Smart Contracts


    • 4.

      Development Setup - Windows


    • 5.

      Development Setup - MacOS


    • 6.

      Development Setup - Linux


    • 7.

      CryptoDoggies Contract


    • 8.

      Version Pragma


    • 9.

      State Variables & Math Operators


    • 10.

      Structs - Defining our Doggies


    • 11.

      Arrays & Functions - Location for our Doggies


    • 12.

      Mapping - Storing our Doggies


    • 13.

      Events - Tracing our Doggies


    • 14.

      [Optional] Testing Smart Contracts with Remix


    • 15.

      Setting up IDE for Truffle Development


    • 16.

      Layout of a Truffle Project


    • 17.

      Ganache & TestRPC Usage


    • 18.

      Web3 Unit Testing


    • 19.

      ERC721 Tokens


    • 20.

      Adding ERC721 Interface and Libraries


    • 21.

      CryptoDoggies DNA Explained


    • 22.

      Adding Required ERC721 Variables and Data Structures


    • 23.

      ERC721 Token Creation and Access


    • 24.

      Generate Random DNA


    • 25.

      Token Purchase and Balance Withdrawal


    • 26.

      Token Pricing Steps


    • 27.

      ERC721 Token Function Overrides


    • 28.

      ERC721 Private Function Overrides


    • 29.

      Refactoring Unit Tests and Crushing Bugs!


    • 30.

      Introduction to Remix, MetaMask and Ropsten Testnet


    • 31.

      Getting Started With Frontend Development


    • 32.

      Creating the Doggy Cards


    • 33.

      Write the loadDoggy Function to visualise the Cards


    • 34.

      Contract Load from JSON ABI


    • 35.

      Handle Doggy Purchase


    • 36.

      Load Doggies from Contract Function


    • 37.

      Deploy CryptoDoggies to Ropsten Testnet


    • 38.

      [Optional] Deploying to Mainnet


  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

I'm sure you've heard of CryptoKitties, the first highly successful Ethereum Smart Contract and Distributed Application (DApp) that took the world by storm!.

There is no denying that Ethereum and the amazing opportunities that come from writing Smart Contracts will only get bigger and more disruptive in the coming years as it continues to grow.

Learn How To Use:

  • Solidity - The programming language used to write smart contracts

  • Truffle - The most popular way to develop smart contracts

  • MetaMask - Browser extension to interact with your smart contract

  • Bootstrap / JavaScript - You'll build your own website using common web frameworks and languages.

  • ERC721 Token Standards - You'll build your own ERC721 compliant Token that can be traded on the Ethereum blockchain.

I wrote this course for people who want to step through each of the steps required to implement their very own ERC721 Token called CryptoDoggies. Each of the Doggies created is completely unique and can be sold and collected on the Ethereum Blockchain.

By the end of this course you will have deployed your very own CryptoDoggy contract, and be fully capable in creating anything you can dream of using the amazing power of Ethereum Smart Contracts.

Meet Your Teacher

Teacher Profile Image

Nathan Glover

I love technology, I'm a maker at heart!


Creator of ALL things AWESOME!

Bachelor of Technology with a Major in Computer Systems and Networking, I've always had a strong desire to make amazing things with the technical skill I learn.

I've recently taken up developing Ethereum Smart contracts using the Solidity programming language and have deployed a number of small successful distributed applications (DApps).

When I'm not writing distributed and immutable code, I'm usually soldering electronics and writing code for some of my IoT home automation projects, and also working on Unity3D game development.

See full profile

Level: Intermediate

Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Welcome to the Course: How's it going? Welcome to the smart Contract Development course. We're gonna be building our very own crypto doggies. Token game. I'm nothing, Glover. I'm computer systems engineer who's been working on Blockchain applications specifically on the ETHEREUM network for the last six months. In this course, we're gonna cover the basics of Ethereum. What is a theory? Um, on what a smart contracts. How do we interact with them? And how is data actually stored on a Blockchain? We're gonna go over the basics of solidity, which is the programming language that's allowed us to write smart contracts. We're gonna learn the basics of operators variables, struck's arrays and functions and then finally cover meth things and events which will allow us to build fully fledged smart contracts that integrate well with websites. And speaking of websites, we're gonna be building our very own site for character doggies that allows you to make purchases off TLC 7 21 compliant assets or tokens on the Syrian Blockchain. So that residue let's get started 2. What Is Ethereum?: to start with, we should explain what Ethereum actually is and how it compares to something like Bitcoin, for example, because the theory is quite similar in the respect that we have a balance that is stored inside a wallet and that balance is stored in a public ledger with a series of transactions . When a transaction is made, it's propagated to all the other nodes of the network and verified. The difference with fearing, however, is we have these things called smart contracts. If we open with the smart contracts, we can see that there's more to it than just money. We're actually storing coding this block. Here is the code of the theory and start contract. There's being deployed to the Blockchain. Someone can interact with this code. If they have this contracts address, this contract will have a series of functions that we can interact with and that the allies basically the biggest difference. Being Ethereum and a lot of other cryptocurrencies. There is the functionality off building distributed applications, which is what will be building in this tutorial 3. Introduction to Smart Contracts: following on from the recent video explaining what Ethereum Waas Let's actually go into more detail What a smart contract is, what it looks like. Here's an example of one that deployed, called Napster. You can view the contract code here and then below it. We could be the condensed black code. This is what's actually written to the Ethereum network and store. This is not contract hip to interact with that code through this bullet address. Well, through this contract, address what you call it. We have a series of functions that this could actually presents, some of them public and some of the prophet, but also has a set of hard coded variables that are completely immutable Once their contracts written to the theory Blockchain. It's there forever, which means we have to be really careful with what actually publish 4. Development Setup - Windows: Hi there. Welcome to the course on developing celebrity smart contracts. In this video, we're gonna go through the installation process for your getting your development environment. All set up on Windows operating system. There are a number steps, that number of steps for this that makes a little bit more difficult than when you're using a Mac OS or Linux, but will work through it and get it all running for you to stop with what we're gonna do within stole a Windows Package manager called Chocolatey. Now, to do that, you go to draw clear oak, forward slash install, scroll down click and still chocolatey. Now you can either use powershell. Oh, command line. We're gonna use command line. Click this little like on the copy. Then if you open a man prompt right click and run as administrator, it'll prompt you with you. I see. And within this window, simply paste in what was in this box here and hit. Enter the rates of fusing chocolate. Is there a number of different dependencies we're gonna need in order to get the developed environment up and running chocolatey makes it a lot easier for us to manage our packages through it because it does only strange insulation processes for us. Fantastic. That shouldn't be done. So, you know, to install a first package, we're gonna install the truck that he could do. I So we go trucker, install chocolatey geo. This will just make things a little bit easier to develop with them to use for anyone hasn't uses to before. When we get to this, we're gonna hit. Yes, and it should be installed. You can close off this terminal and going to start menu, and you should find chocolate E g a y click. Yes. And I'll give it a little minister of privileges within this tool on the left click chocolatey. I'm going to search for some packages that we want to install specifically, we want to install, get, and we're gonna go with Get in, stole. So it's installed on trial system. The other option installs it as I'm not basically a minimal install. So it'll just give you the binary. We could open the console to view status once that sun will install the next dependency. In this case, we're gonna install visual studio code. Now, if you prefer to use a different idea. By all means, go ahead and use that. But for this story will be using BS code. Some of you might use atoms, sublime text or just a text editor I cannot pay. Plus plus. Yes. Good. My mistake. Cool. We'll find visual studio code, right click. And still, once it's on, we're gonna close off the truck with the menu. Next. We're gonna still node version manager for Windows. This is going to allow us to manage our versions air no more effectively. We're gonna go into the get help edge and never get down and click releases from here. We're gonna download the NDM, set up zip, and then once it's done, we're gonna extract it and then run the set up toe click next a couple times, and that's what installed next. We're gonna have to install al version off note. Now that we've been in Vienna to do that, we're gonna open up how command line again. You don't need to run as an administrator this time. And then we're just gonna simply run N v m and stole 9.7 point one, which is a version of noted that we would like to install. This will also install known package manager, which is what we're gonna be using in order to install a dependencies. Once that's done, we need to activate our version of no using envy M use and the version we use before 9.7 point one. Fantastic. That except system Interpreter to use Vote node, version 9.7 point one. Next, we're gonna be installing the windows build tools, which is what we're gonna need not to install of it. Some of the NPM dependencies on windows. To do that, you go npm install G, which means global. We're installing its any global scope on your system rather than local to a project. I'm gonna go windows build tools. Now this person's can take a Sorry. I have messed up lashing you to run this through power show. Um, So what we'll do is we'll close this off Taipower shell and then we're gonna run. It is administrator now within how? Show command window. Quickly. Run NPM, install G windows, build tools. This process will take quite a while. So much as well. Go get a cup of coffee. Well, right for this to finish, that person's probably took a very long time. But what is done is installed parking for us has installed visual studio build tools and, like, secrets with bindings. Just everything you need to basically get started develop on windows. Really helpful package eso Next. What we're gonna do is pull down a couple appendices that we're gonna leave later Specifically, ganache, which allows us to have store in private Blockchain development Blockchain while we're developing. So we're gonna do is restaurant closes when you often jump back into standard command line ? Because we don't need, um, administer of privileges to this stuff. So Kennedy npm install global ganache. You can also do npm Um actually, we'll do is we're gonna back out of that because what I'd like to do instead is installed that you see a lie you can install ago if you'd like. But for this course, you can get away with just using the Saleh and I would actually recommend it. Fantastic once said since told were to close that off, we're gonna pull down the crypto doggies base repository, which is what we That what we're going to be working out off through the rest of this course going to rehab the next man from I'm going to you, You know, we're gonna use a different map. We're gonna use git bash. It basically gives us, um, or UNIX style command line toe work with, which will make things a little bit easier for you. Just see what we are. We're gonna change, directory into some way like ducks. Then we're gonna make a director cold, get we're changed, Director. Using CD and to get ls just views the currents. What's in the current holder? I'm gonna go get clue. So I think I'll just copy this, man. It's get clone. And then the repose your real Hey sitting fantastic. Next, we're gonna change director into Crypto Doggy Spice and I'm gonna run in PM in stole. Now this prices will take a little bit of time. What it's basically doing isn't stolen everything that's in the package dot Jason file within their the directory off the project. While waiting for that, we're actually gonna open official street code and load in the folder. Some type B s good. Give it some time in the first time to launch to set itself up. We'll close the welcome page. We'll get file, add folded workspace. They were going to computer, see? And then I use a And when this girl too. The photo that we created. She's on documents. Get open project. Now If you have been packaged, Jason, you should see what I mean. You'll see Dev Dependencies, which dependencies installed as part of the development process. He's only get used while we're developing the application. And then we got off standard dependencies, which are actually loaded at Renton and pushed out with the project when its life. And we got a series of scripts that we can call using NPM run. And in the name of this script when I jumped back over here and we're gonna wait for this to finish, it will take some time. Fantastic. Once that's done, you might notice that you'll have a few warnings. You can ignore these for now, as long as you didn't get the errors, which, if you fall little us that all these steps you shouldn't You're good to go now. What I'll do is I'll bring these notes back up and just basically say if you do have any problems, especially with the installation of the windows bottles. Have a check out this page here. Well, just look it up. This is one of the dependencies that caused a lot of problems for some people who used the old guide for this course. If you follow through basically, if you if you sold this and I have any problems, don't worry too much. But if you do have to continue, have some problems. Just follow through these instructions and run these command here. And I'm hopefully we'll sort any problems out you do. You have eso, but without further ado, we'll get on to the next part. Of course. Thanks Falling along. 5. Development Setup - MacOS: in this video, we'll go through installing the requirements for running small contract development on a Mac. Let's get started. Start by installing node version manager using the coconut and found here. This is available naked home which is available there. It's jump by patrol terminal. Don't pasted it the cyclone that NDM repo into your home directory. It will also add this export in VM directory command to your bashar See file. You will need to relaunch your terminal after you've done this or you can simply run Source that Marcy the test. Make sure this has worked. Go command. See India in your output should be India. That's how we know we've loaded Nothing's told the latest version of note. We could do this by going Indian and still note once it's installed, you'll need to select your default version of note. We're doing this Goa India use and the note This will activate the vision and arteries downloaded. You also have access to NDM. Now, listen, stole dependencies that we're gonna need one stole ganache organ. Actually, a lot in our case we're gonna use can actually alive, cause we don't need the full you experience. However, the fifth affair not to use the command line for 30 years. Do I feel freedom? Still just ganache. We can do mbia NPM install g can actually alive the G stands for global meaning. It will be available to all projects and not just the one year old currently working in this person's can take some time, depending with half assed retune. It is once that's installed, what we're gonna do is pull down decrypted overseas based repository. We can grab this from my ghetto. You can just perform a get clone on the Republic. Make sure you do this inside a directory that you're willing to work in. I'm doing projects you to me, unencrypted Toby's base. Once that's pulled down change directory into that new folder and running NPM install. This will go through it and still older required dependencies that come in the package Duck . Jason, Within this project, this project this process can take some time, so you'd be willing to white Well, that's running. What we'll do is we'll open up the i d that we're looking to use. In the meantime, I've decided to use V s code for these projects. We're just gonna wait for this to finish. We're just gonna be prepared to add the fault with the work space once it don't. Well, low this it You're now ready to have been moving to the next section. 6. Development Setup - Linux: that was going. We're gonna go through the installation process for out development environment on going to limits, not to get started. What we're gonna do install no diversion manager. Similar to what we do on Mac Os. This is an easy way for us to manage our instance off. No, Jess. And subsequently in him. So use this Coke plant to who? Down this Reaper. And then what will notice to the bottom here is that this thesis full lines will be added to our national. See, we can confirm that they are, in fact, there by going and looking it up and just down the bottom here, that should be there. It's now what should happen is if we close off Elterman rape in it should now have access to the coach and the employment. You could test this by going command enzian. Fantastic. Now let's install the latest version Note. We can do this by going in via and stole. No. Once that has been done, we need to activate this version and going in VM use. No, If you didn't start a specific version, you need to replace this. I would note with whatever you decided to use. We should now have a node in our show. So we should go to run in camp to start with, we're gonna be installing a global package tickle. In our case, we're gonna be using NFC, Ally, because we don't need the full. You are healthy if you'd like to. Up to you see or feel free to use that instead. NPM install g g for global. Basically, it means it's available to any show rather than just the one within your project. Oops. These can take some time to anyone who has been the Internet and a computer. Well, once that's complete, we'll move on to the next stage, which is to pull down the base. Scripter doggies. Repository. No, not to do that. We're gonna use Get Klein to start with a lot of coupon. Two boxes definitely come with getting stock. Nor do they have built essentials Apartment. So what do is in Seoul lies three dependencies fest sudo apt and still get bison build essential. No, I've actually over to your clothes. Three packages and still but yours might need to install next. Let's pull down this reply. Well, simply get climb in the repository and the position of all system we'd like to use once that's done. Well, strange directory into that new folder and then run NPM install. You'll need to have run the previous tapped install commands for build a central before you're able to install all dependencies within the packaged up Jason file that the MP in stole is pulling from this purpose tent can take some time. Once that's complete, you can open up your chosen idea In our case will be using V s code watching this in the background and with, um, we're just gonna add a folder almost like that folder. And now you're ready to go. We'll see in the next chapter. 7. CryptoDoggies Contract: we're writing us. Good welcome. Making it through the introduction. Now let's got stopped by creating out fists, Not contract. Have to do this. We're gonna create a folder within our workspace, cold contracts. And within this, we're gonna create some about various contracts. Will be using the stop will stop by one by doing fun. We'll do that is crypto doggy start cell. Now the extension soul professed solidity, which is the Turing A plate and very, very similar to Java scripts. JavaScript like programming language that is used to write code for the ethereum Blockchain . So now within this solidify, we're gonna define Al contract. In this case, we're gonna make it crypto doggies as well. Now, I should mention that you don't need this name here. Toe match the name of the file. I'm just doing that because it makes sense in our case. But you can have many contracts within this lippy fall crypto keys and as it because you really want to be perfectly honest. What I'm trying to say is basically, don't think that because you gotta find them here. It has to match the contract name here. Fantastic. In the next session, we're going to be discussing version of our contracts 8. Version Pragma: now you might have noticed if we hover over this contract you're gonna see no pregnant directive has been specified. Now these tool tips are coming up because I have a special extension. It's installed NVs code called solidity. This basically just does syntax. Highlighting gives you some quick tips relating Teoh best practices around riding contracts . I would highly recommend looking up to see if your I d has an extension is very similar because, especially when you're writing code, that is gonna become immutable and you never will be able to change it. Once it's on the Blockchain, it's important that you follow assist standards that make it so. If you do make a mistake, it's not gonna be a massive for So now let's talk about version of contract files and for this I'm gonna jump over to an example. Let's look at a contract that I've deployed in the past Cold game cards on Eat the skin as you see at the top here. I've got pregnant solidity and inversions. Europe went for 18 defined. Now that's the compiler version that was used to compile this month contract. At the time of that, I deployed it to the ethereum Blockchain. Now why that's important to have up there is basically because we need to know if there is a major version of the compiler that if the compiling jumps to a major version and changes fundamentally how this mark contractors processed, we need a way to be able to work backwards compatible. E So we need to know that this contract worked on this. Compile a vision. And if we do need to run this version of smart contract in future, we should be targeting that compiler version. It means that if we do break stuff in the future, we have a way of going back. So let's actually jump over to ask my contract and use the same compile a vision. So I'm gonna make a copy and then at the top off our contract file, we're gonna define that version is the one that we want to use. No, If you're watching this video in the future, there's very good chance that they might be more upstate version of the compiler available . And basically, in order to check that, see which version of solidity you've got installed on your system, it will be the one that's defining the package. Doc Chase on file of your project 9. State Variables & Math Operators: already. Now let's talk about state variables and basically variables in general and how they're used within spot contracts. So when I when I say state variable, what I basically mean is when a variable, for example, age, he was added to a contract like this. It is going to be stored with the contract code when his deployed Blockchain. That value is to be immutable. We have no way to change that currently, and that age 10 is is accessible and viewable Within this smart contract. When it is deployed, we can manipulate variables. For example, we could have Max. Age is equal to age times five, and we would end up with max Age of 50. We could have unsigned int min. AIDS is equal to age minus five. And then we could have another unsigned int cold ultra eighth, which might be equal to age to the parallel to So that's the exponent operator, Um, and finally we could have make use of the motionless operator, and we could say moder age is equal to age, Ma. Jealous to that's how many times there's to go into 10. And what's the remainder? Um, we have access to other types of variables as well. So we've got a string variable which were illegal to make would make up a name, Doug. And we can also be really specific with how big we want our data tops debate so we can have uncertain int uh right. Um and that would be an unsigned int off eight beats. So very, very, very specific on you can go all the way up to 206. With that, you'll typically see this used with, like, an address because we want to be really, really specific. And we wanna only stole the value that we only want to store to 1 56 bits. That's all we want. No more or less. Um, you can also use lights fired, for example, we'll be using DNA. Um, and that's basically five bytes of data we want to stool as the d n. A. So there's a lot of different data types that we can use. Just be wary that if they defined like this in this form, they're going to be immutable. When they're pushed luxury, they're going to be defined, and currently we have no way to change them. So we're just gonna have a set of variables that are probably accessible through any functions, and they're just gonna be part off contract code in the next section, we're gonna talk about Struck's and how we can better format this various data into little object packages that we can more easily use and work with. 10. Structs - Defining our Doggies: Okay, now we've got a variety of different variables, but we have no really easy way to access them. For example, if we have two different dogs, we're gonna need basically away Teoh store like Carl in a separate variable together way. Need to package this information into one sort of abstract, different data type that we can access and use throughout out, code on and instantly it new versions of it where we need it. We use trucks for this structure Really similar to objects. If you ever used object oriented languages like Java on and we're gonna find any structure now as a doggy and the structure is gonna have three data types of it, it's gonna have an unsigned int for its age. It's going to have a string for its name. It's going to have a bite. Five variable for DNA. Fantastic. So now we've got a custom data tuck here that we can use to store this information. It's up there now. I want to do this. We're going to you. We're gonna in stance, see it. An instance of destruct are calling doggy and then was called Dougie. One is equal to don't he And then we're gonna put out three different variables inside these brackets here. So we're going to define now. Now, Aged is up with, you know, age is gonna be equal to the global age. Just for now, we're going to have our name, which is equal to name. This variable here just is a test, obviously. And we're gonna have our DNA, which for now we're just going to define a in one piece of data. It's going to be Mm. 12345 five blocks long Animal was closed off destruct groups and supposed to have time. But it's not bite cause about five bites go now. We got doggy one and this dog is Doug. With an age of 10 and a blocked field that is completely zeroed out. We could do this exact same thing with Dougie, too. Will have its age equal to see something a bit different. Will do. Its age is equal to to max age. Just to show that with access, different variables, its name will be equal to name two. And it's but five. It's like five is sorry. That's why it's DNA is equal to We'll change it up a little bit. Well, dio General, Texas Office 50 and close off. And then we what? We have defined two different variables off to different doggy objects with different variables that we've taken from here and placed into here. In the next section will talk about how weakens door this information in a much more clean way and create some functions that will allow us to generate doggies and automatically store them within a raise on the battery. We'll talk about that next. 11. Arrays & Functions - Location for our Doggies: now that we've got obstruct, which is an easy way to store abstract data as an object that we're familiar with a doggie . We're gonna want a way to store a number of those doggy objects within a smart contract. You know what to do that we're gonna make use the race? No, no. Just use arise and solidity. It's It's very similar to how you, Dusan array and pretty much any other preparing language. So you to find the name of structure when it is the day time, and then the two square brackets indicating that's an array then will define the name of the array, which in this case is gonna be doggies. Cool. Now, in order to add items, this array, you're going to be using the push method, which is something similar to this. But I'll show you doggies dot push and then you posit in a doggy. In this case, it'll be Donkey One how this isn't gonna work. And it's also not a very reusable method of doing this. What we want to actually do is create a function. So let's do that now. We're gonna create a a private function indicated by the underscore the star. That's sort of just a way that you can remember that that's a private function. Solidity will also one year if you prefix a private function and then don't declare private . But we'll get into that a little bit later as well. So we'll create, Create Donkey and we'll pass it in the variables that you need in order to create Dougie, which in our case, is an age. I've also prefixed it with the other score here just to indicate that is a different age to the age that we're passing into Destruct IE, different name convention that's just making a little bit more readable. We have onside in age. We have our stream. No, and we have out. But it's five. Do you know, And then we'll also need to do is declare dysfunctions private, and we can now start writing our function. So to start with, we will create A. Whenever we call this function, we want to create a doggy object, and I'm gonna use the prefects memory now memory and storage a tube that you will actually see a little bit when we're writing these contracts. Now, memory just means that we only want to stool the outcome of whatever we use this doggy object for within the memory of the systems that are executing this function, we don't need to persist. It went one. We're only using this temporarily to get some data out of it, and I'll show you what I made in a sec. So, donkey, we'll find out Doggie's name on, and we will create out of the object using the's variables age people to age. Your name is your name and DNA is to deny. Fantastic. Now that we have our doggie item, we need to use it as we just, you know, being want there. So use it. We are going to basically just pushed onto the stack. But we're also going to store the outcome off this token. I either tokens number in another variable will started an unsigned into your 256 bit length called New Doggy I d. Now the doggy idea will allow the past the owns a doggy to remember that I have doggy number six alive. Don't you number seven or 10 or 25 eventually we're gonna map these ideas to an address and the address of the person who purchases the donkey, for example. What we get instead of it later as well reference out doggies, right? And we will push on your doggie onto it and then subtract one, because raise our next ad zero. Um, however, we have gotten sorry, we're dealing with the previous index elements, because when we call the doggy idea that we get out of it, we get the next item number. So we need the previous item number to get the actual, like, a number of this doggy. Fantastic. So now we've got our doggie i d, and we've declared it, but we have not used it on DFO. Now, we're going to ignore the error until the next chapter, which we talk about, um, nothing. 12. Mapping - Storing our Doggies: women last left off. We had just gotten the idea of Al Doggie out of the array push. So in this case, we'd have doggy I d. Zero. We've got no way of mapping right back to the owner of the person who called this function . In order to deal with this, we could have an array off owners addresses and then try to match them to each I d. But it's sort of cumbersome. What we want is sort of a one way relationship between some variable and another variable. And for that, we can use a mapping. So all the Clarin we'll see how we go. So we create a new mething, and this mapping is gonna be from a and sort of an unsigned integer. So this is the unscented. Should we get out of this? And we want to reference it back toe address. So we're gonna use an unsung in 2 56 and we gonna map it to an address or the address of the person who calls this function function below. We're going to Third is private because we just want to do with it internally, and we're gonna call it doggy. I D to owner. This will allow us to get in owner out of the tokens. I d. Fantastic Millets referenced the mapping in l function blow. Now we've already created out doggie. We just need to sit this variable within the mapping. Let's go. Don't be I d to, you know, and we're gonna sit the new i d that we just, like, declared before we'll have an equal to the message. Dr. Sender now, actually was a little bit in the future. That message don't send it basically takes the address of the person who calls this all these the account with the address, the wallet that calls this function and sets it as the owner off this doggy by basically referencing its i d In this mapping, you're basically only ever going to get one outcome of this because you're gonna have each I d isn't gonna have one owner. So whatever you want to update this mapping, you can do so and you just change the address. You basically will make sure your only storing one owner per each doggy and that's basically how things work. We're gonna use a few more. Nothing's in the future. Make one. Now, is it example we're gonna use it to store. How many different doggies? An owner as so we'll have a and address, and we're gonna have a map to. Mm. Well, using address your Web address will have a map to an unsigned integer to 56 cold. No. Oh, doggies. And this is gonna taken address of an owner, and they were turned a total number of W's. Does that own a house? Now, that was about the number of donkeys we need to make sure that we object that when we do do a push into this, it's for a good number. Doggies. We're going to posit the send his address, which will get us the number of donkeys based on this mapping, we're gonna have that equal to this same address. Plus one. Basically, What this is gonna do is it's gonna take the current number of donkeys, add one to it and store it back into the method. And this will allow us to keep track of how many doggies and owner owns, while also keeping track of which owner at Doggie is assigned to 13. Events - Tracing our Doggies: Now that we have out Matt Things and instruct and basically away to stole these doggies when we call that function, we want a way to alert the person who sent the request off the fact that this action just took place. And for that, we're gonna use this thing called Event. Let's create one now. Great event. Okay, Doggy created is named the event, and we're gonna take the unsigned int 2 56 off the i d of the doggy that we've I've just created. We're gonna take the name of the Dougie and what's gonna pretend the age. Mm. Actually. Sorry. What's wrong? A analysts returned of bites. Five. The DNA. This is just gonna return the information relating to Adobe when it was created. Your trigger, an event we go down into our now create doggy method, and we just call it We could create doggy after we created will pass it the I D. Which in this case is the new Dougie I d. Then we posit. We called it the make sure we're calling it in the order. Yep. So you get the idea that we have the names will pass it the the name, then posit the does the age. And it was positive, and I and this is triggered whenever the great dokey function is from what's gonna make some other small changes. This for starters, we're going to make this function public. Now, this is basically so that we can call this function within remix, which is the next tractor off this tutorial. But we're just gonna prepare for that by first making this particular function public. And what that means is that this function well to cold by vehicle. But anybody on anybody, ever anybody who wants to call this this contracts function create doggy is not a safe passage in these arguments. And in the next section will look at how we can create adobe using remix. 14. [Optional] Testing Smart Contracts with Remix: Okay. Now, in order to just quickly show you that the code that we work does work I'm gonna be using remixed over the road at all, which is an online solidity compiler in order to deploy all contract to the, um, the Robson test net, which is another tests, theory and block. Shame that we can use for development. So I'm just gonna quickly create this contract. And what this will do is using met a mosque. It will charge us some money, which we've had wheezing world since. It doesn't cost us anybody, um, to deploy this contract onto the look train, we actually follow the status of this. So it is successful. Um, and we can see the function that we have successful publicly Great doggy can now be interacted with. It's literally create. Let's create a doggy. So if you go to set the age to 12 we'll set its name to Doug. Emel said it's DNA to zero F zero F zero, Syria zero, and then we hit. Create Dougie. This again will ask us if we're happy with the transaction. We will go through all of the meta mask stuff in the lead editorial So for now, you can just signal that piece group. That transaction is pending. If we want some more details, we can open, made a mosque, click the transaction and it will show me that that transaction isn't back spending. We can view the status of it. We can be the biker that's being set sent to the contract. I this address here, this is the contract. This is a contract code that we just created and eventually that will finish. And yet cool. We've seen the event come through here. If we scroll down, have a look, we'll see that the decoded import is in fact, the input that we put in. And this data is First, this page was successfully written, converted to asking We can kind of make up the text that was written. And if we click on the contract, we can see that transaction did, in fact, go through. We can see where it came from, which is my address. The contracts address is the to, and the block that that data was stored in can be viewed here. And yet that is basically was proof that the work we've done does in fact work on and in the next section will start to go through reflecting out we've already done and replacing it with the code that we need in order to create our token. So I hope to see that. 15. Setting up IDE for Truffle Development: Now we have a very simple contract set up. We're gonna begin to learn what truffle can offer. Truffle is a JavaScript library that helps us interact and boil contracts onto the ethereum Blockchain. It can also help us run side test chains for development. And it will also help us and assist with deploying to those. So I want to get started. We're going to great a folder cold my operations and also a folded within the contracts directory called Life Cycle. No one in the left circle directly directory. We're going to create a new contract. Cool migrations felt. So we're actually gonna copy the code for this directly from the truffle website. Now, this code above here is very, very standard. What it actually does is it assists us in migrating out contracts to a Blockchain and assigning an audible flag to them. So basically, when the contract is deployed, it will assign whoever deploys that as the owner of his contract Now, being an owner is very important because it means you're you have access to certain potions that general, public and the rest of world don't have access to. So we're just gonna use this code here. Feel free to pause the video and copy it all in. We're also refering representing the Zeppelin solidity library, which we imported in our package. Ought Jason. Sorry. Now the O noble dots slid Lee or sold file is very, very standard. You'll see it used across the board when If you have a look at other people's contracts, you're gonna see it. Used a lot of different places just to keep things clean. We're actually just gonna be importing it directly from this NPM import off the top here, Este, Do you think that next we're gonna jump into our migrations directory, we're gonna create two new files. Now again, these are very standard truffle, and you're gonna you'll see these used all over the place. And the naming convention is is pretty much gonna be the Samos. Well, you'll have your initial migration script now. This will run first. So this number, that prefix, is the order that these migrations will run in. So to start with, we're going to migrate the the migration contract across that it's the first migrations equals rt fax don't require, and then our contract with you discredit just that which is life. Psycho migrations. Thought so and then module dot exports This is just making it available. Teoh Global Scope off. How application deploy reckons is us. We're docked, boy and migrations. And that's all you need for the initial migrations. Pardon me now we're gonna cut a 2nd 1 and this one is going to be cold. Previous them too. Deploy contracts? Yes, you can call it whatever you like, just as long as you prefixes to. So it comes after the initial migration script. Within this, we're gonna do pretty much exactly the same as before, But we're going to instead declare at the contract. We wanted a place which is crypto doggies and then artifacts. It's not require he's and notice how here and I have included the soul. And here I haven't, um it actually doesn't matter in both cases, just to keep it standard will probably include the soul. Here's well, would you Exports We're talk deploy and then critter donkeys. And that is all we need. In order to get started with you think truffle eso next video will actually be executing and confirming that our contractors actually deploy 16. Layout of a Truffle Project: excellent. We now should have our projected stage where we can run a deployment or migration with truffle and successfully see it deployed to a test Blockchain. So let's actually run this test down to see how it all works. No, to start with, you're gonna have to make sure that you've installed all the packages that come along with this project. To do that just talked at PM, Install in the root. Both decrypted overuse based directory knows purses can take a while. Um, mine was already done. That's why it took so quickly. But money, quite a sector that once that's old on you should just go to run in PN run test. And what it will do is execute a test fall within the scripts directory. Now this is my final and I'll tell you why. Just one sec, as you can see, can't read properly. Feel toe. Long story short. You need a test directory with new project for it to recognize that there are no tests card . So let's do that. Create another folder cold test, and then let's go ahead and traveling that again. Now it leverages a and Pam package called Test RPC which spends up an instance off a ball training used to test with over RPC and then outlook code is connected to that. Contracts compiled and then migrated. In this case, we don't have any test, so we get zero passing. But we have to get agree. They're opposing because no test but no tests fail. So great anyway. So let's have a look at exactly what happened here. See another Boehner here we've got truffle config and truffle Js. In reality, these are both exactly say there in the reason they're split into 27 follows because as of rocking, this truffle on Windows currently needs truffle configured Jason and truffle on UNIX systems just needs trouble about jazz the other way around. This, currently for projects that you want to support by platforms, should have the same file twice. It's to do with not being allowed. Space is, I believe, in the winner's file system. That's why I mean but best, the one of each. You also need to notice that we've got the dot M package that's loading a on instance often demonic from a end foot file. In your environment, we actually don't have that currently so maybe we should add this. If you have a look at the end of dot example, you'll see it as an example of the demonic that we load in. Um, now, this pneumonic is what to use to generate the private keys for our project while we're developing all testing. Now, if we use the same demonic each time, we're always gonna have the same set of private keys in the sensitive accounts, which makes it really useful while attesting because we know what to expect. And if we do need to test anything that relates specifically to a specific owner of a contract, we can be sure that we're using the same demonic. We're always going to get that address generated. So go ahead and make a copy and then rename this end file to simply dot can then rerun in him test, and you might not see it, but it will now use that new monarch in order to generate the address is that it will eventually use for our tests. Um content missile work still and perfect that when we run into him run test. What we're actually doing is running a script within this package dot Jason file. So if you open up the packaged up Jason Scroll to the bottom to the scripts, you can see a list of scripts that are compatible without project. So if you do, MPM wrote death. We're going to speak of an instance of lots of. We'll get to this a little bit later in the tutorials, But when we run in PMO test, what we're doing is just executing this test script, which is just a custom script that a lot of people use, you know, to deploy a set off accounts again. This what we're talking about? Four. These are the accounts that we spend up locally that we used to test our unit tests without contract. 17. Ganache & TestRPC Usage: Now, let's say, for example, you wanted to run that development test block train, but you wanted to visually see exactly what's going on within the op PC stream off your test chain. Now we can actually use ganache, which is a utility installed early on, can actually a lie in order to spin up a local instance off that RPC server or Ethereum Blockchain and our case for developing that we can actually physically see and interact with, You know, I'm gonna bring Finish Seelye, and then I'm gonna run in specifying in demonic Now, here eventually specified anymore, Nick, that we discussed in the previous video that it could be found in that dot in file. This just means that the series of private keys that were assigned when we run this chain will be exactly the same. We're gonna run that. What we should see is 10 accounts and 10 private keys. That will always be the same because your money we supplied them. Now, these 10 accounts are all pre loaded with 100 paper that we can use to while testing to make sure that certain parts vocal tract work Wait. We expect them to I want to see the bottom that we're listening low closed 85 full five. That just means port 85 45 is what we need to connect to in order to access and manipulate this instance off the chain. Let's drop back over into L workings by workspace for all contract and open up a new terminal. I'm just gonna use the terminal with envious cut. Now we need to compile the contracts, and we're gonna use that renews truffle for that. So if we do end him run, compile, it will use truffle, you know, took a pile of contracts and put him into a political build. This build has three Jason files, which is this the 80 i off the contract? It's just love a step higher machine code off what's actually put onto the block chain in the theory In contract, when we do migrate it now we need to migrate thes contracts onto our trade. To do that, we can go mpm run, migrate. Now, when you execute this and quickly flick back, it's the turmoil that I had open and we're gonna see those contracts actually be added to the chain as a serious events. And there you go. We see that the two contracts were actually added luxury, the first being the migration contract under the Lifestyle directory. On a second being the crypto eat out. So contract we can see the addresses that both these contracts were created that So if we in the future wanted into interact this contract, we just need to point to that contract dress will have access to that function that we made public in order crate doggies. In the next tutorial, we're gonna talk about how we can set up some basic unit tests in order to test out contract. 18. Web3 Unit Testing: in this section, we gonna quickly go through the process of creating some unit tests that make sure that the functions we have within our smart contracts will work when we deploy them to the block trade. So to start with just checking the package about Jason while that we do have the Penske web three included, This should give us all the AP eyes that we need to in order to access the Blockchain from some javascript that will run. Said that if we jump into our test folder, we're gonna hit a new folder cold, you tills and then in the base test folder, we're gonna create our first tests. So we're gonna go donkeys tests dot Js And within the details folder we're gonna create something similar gonna do crypto doggies. You tills hopes dot Js Now I like to format in this structure because you'll find later that as you start around a lot more, you notice you can't a lot more bloated and bogged down. And if you can separate out the specific utilities from the different unit test, you gotta run. You'll find yourself being able to comprehend exactly what you're testing. A lot better and you'll see that pretty soon. So now in the U tells director, we're gonna create our first util, which is gonna be the check that we can create a doggy. So start with will declare we're gonna be declaring all these functions as global. So we have to export, and we'll pass in the e critters doggies artifact. Well, contract it we're working with, and then we'll create a function in here Cold check donkey creation, and we're gonna pass it in the age, the name and the DNA. Which of the three variables that needed pause in in order to create? I don't. Next, we're gonna write some syntax for some some tester built. So in order to do this with it and we'll create a scenario that we want to print to the terminal whenever this function is executed So we'll go create. Ah doggie should create a doggy named and then, well, this print the name off the Dougie as well. So we know which don't you were working with and where we might have problems. They will say function done. And we will go to the next line. Now, at this line, we're going to take out contract the doggies and didn't deploy. This is next level. Would be They can't just fess deploy before we run this. Then we're gonna run it a sink function and then passed the instance off the contract that has been deployed. So when crippled abuses deployed in the past, the insert instance off that deployment to the next line. Now, this line gonna go await instance. Step will, basically, whatever functionally call from this will wait for the outcome to come back before we move on, because we're gonna be looking for an event to fire that says that the doctor has been created. So we're gonna go instant stock and then the function we want to cope with no contract. So create Dougie, and in positive, the age, the name and DNA. And now this is the actual contracts function that we declared back over here. It's this create doggy reminded the function needs to be public. In order for us to do this, no new line, you'll do another colon solitary and open apps brackets. Now, within these these brackets, we can define a set of sort of variables that are also extensions to the function there alongside so out between examples from is one of those and that basically allows us to define which dress we want this this transactional this function call to come from. And in this case, we wanted to come from the camps and the accounts injected zero. Now, the list of accounts, um, the list of accounts are the ones that would generate with that pneumonic. And I'm just gonna paste this in he FN else we know. So these are the addresses we have to deal with. The ifit index zero is always created as the owner of the contract, and that's because of the way that that migration script ran. So if you keep a list of these addresses, it makes a lot easier to sort of remember what you're up to. But we all you basically need to know is that we want to create this doggy using accounts here, which is the owner. Fantastic. So let's move on. Um, there are so options here as well. You can go value and actually pass in a value that you also want to send to this functions to some functions of require payment. And if you find a value within this field here. It will also send ether value to the function. But we'll talk about that a little bit later. For now Was happy accounts little closed off and then off. This is done. We want to go. Then function result. We want to test this. Make sure this result waas correct, are you? It will get the event back. So we're gonna go serves Don't include, so just check the output for some string value in affects will result Don't loans. We're gonna take the first log in the array when you are and take the event field if you want. Have a look at what these results have. Look out. You can counsel love them and view what's actually available for now. Just know that we want to get the first log. Wanna grab the event from that person we want to check to make sure that doggy created is the name of the event that was returned and then if not, we want to throw a message. The terminal that says Dougie created events was not triggered. Also close this up. We also want to make sure that around this entire function here we are catching any exceptions. So catch done. And that is that. Hold on. We also need to make sure that we return the module, that we just find out this function. We just find someone, go credit return. It will just take the name of this function and return it with the same name. Mr. Next, if we jump in, do the crypto donkeys test file. This is what we're gonna use to call these you tills. I'm gonna get reversed listed accounts in out. You don't need it. What will those will declare the the artifact for our contractors up with secretary drug users they took artifacts don't require. And here you have the soul. If you want to put it best to be consistent, then we'll go contract. This is where it gets interesting. Crypto doggies. So this is taking the artifact from Krypton noise, and then we're gonna take the list of accounts and use it for the following functions that we call now. This is a piece of help occurred that I used to load in those util functions. You'll see this across a lot of the smart contracts. That right and a lot of smart projects a lot of people, right to just I find it's a good practice to basically load in this list of you tills, um, Problematically doggy used sexual. This is equal to the name that off the Wallaby created before. Yeah, and faucets. The contract and the accounts as well, basically cycle through each of the help of functions and add them to the global scope. So we're at this out darkies helper function. So health food Sorry, I'm getting my sin textural, helpful functions. And then four var equals zero cycle through the list off the function number ducks linked and then global A to the map off help of functions in Monday make complete sense. And that's fine. Um, basically, just cos sin wherever we need it and in the future, if you need If you need a symbol, So destruction is company. Listen, go on. Now, basically below this, we can call any of those functions in this you tills file and have them execute with this Markle, Give it so we want to call our function check Tony creation. However, maybe we want to run it more than just once, so I'll give an example how we could do this so we could go for X is equal to zero. X is less than 100 next, plus plus. And then we can run. Check Toby Creation and we'll posit in the age lets you choose xsl age and we could give it a name so we'll go doggy and then we'll add XT. And here. So we basically print the doggy and then the number that were up to and then the hex or the DNA value. Um, let's just said it both hard coded, but also was, does Iraq's Iraq's Your exterior is your If I should say so. In theory, what we should end up with is 100 W's that increment in value number when these functions executed. Now, in order to run this if you bring up a command line, well, we need to do is to mpm run test and it will search through that test folder for a test file and then executed. And hopefully we did make an attempt. It looks like we have many mistakes, which is good. So this has gone through and created 100 doggies with the incriminating expel you as the age and the doggie's name and then the DNA, it will be said. Hopefully this is a good start for how to create test functions. While you're developing smart contracts, we will be extending listen in future tutorials. But for now, hopefully it gets us started for moving forward and trusting the contract that we written that doesn't fact work. 19. ERC721 Tokens: great Working on making this fall in the Fulton section, we're going to start implementing our U. S. C. 7 21 token into al crypto doggies. E O. C. 7 21 stands for theory and request for comment. Number 7 21 was basically a implementation that four tokens that was brought forward in issues 7 21 You can go look it up on their get help edge, but basically outlines the functions that should be included to make a known fungible asset . Or take it if we jump over to a medium post, which, actually it's a lot better about what fungible it. Actually, it's to be fungible, being something such as money or commodity, such that the nature of one part or quantity may be replaced by another part equal off equal quantity in repaying a debt was suddenly account. What we want actually do is create something that's non vulnerable. So when you think of the $5 note, if you see have some survival a note you can exchange that for another $5 notes and will be with exactly the same when you compare it to something like a baseball card with one baseball card is not equal to another type baseball card with what we want to do is generate unique tokens, that owner in value in their uniqueness. So in the example, off doggies, for example, Trump Makoto code. If you remember, we had this DNA field. This demand I field is what we're gonna use to make out doggies unique. This field is gonna create contain a set of values that define what the dog looks like and effectively makes them a collectible. Based on this day in a field, we're going to this little bit later. But you just need to understand the basic premise of what NIOC 7 21 total actually is and the fact that it is unique in the way that is implement. These are some of the functions that are defined as what is required to make something. In the sectorial token, you got fields such as name and simple, which dropped back over to a browser. And I'm going to eat the skin and we have a look. A token are exists. For example, crypto kittens, perfect kittens has the name cryptic kittens and with the token symbol off ck t and and there are Friday different types, each with different symbols in different names. What? You just need to know that those two fields relate to the name and then the symbol off each of these tokens jumping back a code you can see to. In order to be compliant with this TLC 7 21 particle, we need to have another neural field approved ownership transfer and a variety of other functions. He's only to be overridden when we and Interface, with this contract in the next section, will begin to implement this contract into our existing crypto doggies solidity contract. 20. Adding ERC721 Interface and Libraries: No. You have a basic understanding of what you'll see. Some 21 tokens are we're gonna start to implement this functionality into cryptic doggies. Unfortunately, because a lot of this code here is going to be slightly re implemented just to make things a lot of confusing, better move. It'll and some stop fresh with our interpretation. That's where it won't take too long to re implement it. So we're gonna go back to a basic contract. We're gonna have to implement three different interfaces or libraries that we're gonna be using. Now, I've actually linked these into description off this video. Splendid. Jump over to these three links. We're gonna download the content into our idea. So this is access control. I was gonna put him in the root contracts. Told it Now, access control deals with the address is that have we called an admin privileges of the contract Once it's deployed to hear Blockchain? It's a sort of standard that people have started to adopt as it it makes it really easy for you to set a CEO and a sort of co CEO addresses which have different sort of permissions, will say the important things we need to look for these modifies now. Modifiers when applied to functions will be run and check to see that their ballots before they believe I try to call a function as a CEO, I will be able to, because it requires that centers addresses people to CEO address. The same goes to CEO dresses as well. If someone else trusted coldness that isn't a CEO, however functional, fatal, so amazing access control for that. Now we can import it up. Top it by going import access control So fantastic till the next library we're gonna need It's called TLC said 21. And it's, as you'd expected to the basic kind of interfaces that we need to override in our contract . So let's jump back, Roberto Idea. We'll create a contract. Oops, sorry, great. How? Contract cold E. L C 7 21 so it will place this coded. We'll be into overriding quite a few of these functions. We'll go over that response in the final library we're gonna need is safe math These for a set off methods for dealing with large floating point numbers, ensuring that we always get exact position that we precision. We want. We don't lose any value. Two people. You use this to anything that uses payable a payoff function into sending value because a serious dissent in a sort of a current, equal way, you end up with, like 0000000001 being set. So you've got a lot of precision that you need to make sure you let loose. You'll see it in action in just a sec. So it's import this library safe dot soul on and what we'll do is back in our main contract will import those two again. So we've got e R. C 7 21 so and we've got imports safe now. Don't so fantastic. Next we're gonna do is we're going to extend El Grip adobes contract to use access, control the stars because we want to be able to set out contract to have an owner. And now here You might think we were gonna implement You'll see some toyland. But in fact we're gonna influence detailed. You'll see 7 21 and we're gonna override the functions that we are using than it. So just above it, gonna create a instance or a contract called detailed, you'll see 7 21 which is your C 7 21 I'm going to ride the function name, republic the returns and then a string today, and we have functioned symbol. The public view returns string testing. Now there are two other functions we can include here, which are token metadata and token of owners by index. But we're not going to for this particular contract and tested. So now we're at state, where we have imported all the libraries that we're going to potentially need for our contract. The only other thing we can do is at the top off crypto doggies. We can declare that we are using safe math for you went to 56. That just means that when we're using to $56 will always be using safe math to handle them . And that's it. In the next video, we're gonna go through the's starting to create the skeleton again off Al crypt. Italy's contract and declaring with a donkey years again, was making sure that you actually understood the initial teachings Fantastic 21. CryptoDoggies DNA Explained: the whole moving forward. I thought I'd give you good understanding exactly what we mean when we say DNA when we're referring to crypto doggies. For this, I'm gonna show you a library that I've been working on. Cold Dahlia. Tipaza. Gogi I deposit is actually based on a different project by a my pond aware with cats and said what it effectively does is it takes a five bites successful value and generates a random dog with different attributes and characteristics based on that value that is passed in. Now here's an example of Jump over here and refresh. You can see. Look at all these various types of dogs. These are all based off the 55 attribute people, Danny that we passed into them. We hit Refresh, You can see well, instead of being generated. I've just got a function within here that randomly generates values and kind of spits out different types of dogs. So what we're gonna be doing is we're going to create a C 7 21 token for each of these unique doggies, and it's going to store that Hexi decimal value that five white hex inside the theory and contract step when you own a dog, you own that unique dog. Based on that identifier circles went on whenever I mentioned the five. But DNA identifier, This is what I'm referring to. And in the end, what we're gonna have is a site that displays your dogs image and its name in the Web browser for the people of patches. 22. Adding Required ERC721 Variables and Data Structures: in this video, we're gonna go through declaring all the events mapping, struck's and multiplies that we're gonna need for out. You'll see 7 21 crypt adobes Contract something. We're gonna start with the events that we need and we're gonna need to events and, uh, toking created, which refers to the creation all our donkeys. But we're now calling them tokens to abide by the U. S. C. 7 21 standards. It's gonna take a you in 2 56 toking I d string name. That's five DNA. You went to 56 Price and the address of the owner. The second event is gonna be full when a token is sold. This is basically when someone else purchases the token, an event will be fired. That would be you in 2 56 indexed turkey 90. That's just a way for optimizing that we have a A map for the took a days the next status and string name, but its five DNA, we went to 56 selling price. Then we also want to send back the new price explain menu prices in this world sick. Just gonna put these onto your lines easier to read. There's a few more to go on. Then we want the address indexed old owner and the address indexed. You know, second tested and those. There are two events. Next we're gonna create on many things. We'll have a mapping for U N to 56 to address. We're gonna make a private We're gonna be calling it. Took an I. D to owner is basically takes a C 7 21 token or a crypto doggy, and the maps it back to the owner. Have another mapping full. You went 56 to a you went to 36 private. Then we're gonna call this token idea to Price. This is gonna be quick way for us to reference the price of the token looker dokey that we're doing next. We have a mapping for address to you in 2 56 and this is going to be the ownership toking count. It's just keeping track of how many tokens and owns. And finally we're going half of nothing. You're at 56 to address, and it's going to be took in i d to approved. This is basically allowing us to transfer tokens between different USC 7 21 token platforms . We can try it out token now, don't you talking for a kid. He took, for example, in another powerful. We need a way off storing whether or not the transaction is approved because the contracts can't interact each other unless someone flies off the event. Explicit. Declare the struck from Dokey similar to before will have its name and we'll have a butts 54 its DNA. Just leave it at that. We will create an array, the doggies, and next we're going to create a private variable. It indicates starting price of each doggy that is added to a platform. We can also use the term ether within the code. It this is just allowing us to define that we want to deal with this uncertainty. This insight into 56 is gonna be It's going to convert it to either value from way for us, sort of acne by solidity. And we'll also have a bullion called C 7 21 Enabled is a false Now, basically, we can. This will allow us to total between USC 20 and you'll see 7 21 Yes, it when he was an old stand that we aren't gonna be using. But in order to be compatible with some of the exchanges and platforms viewing the token, we do need to include methods for viewing it in an S. E. C. 20 said it. And we'll also add the motive fire for only you are see groups, you'll see 7 21 This basically means if a method is 21 we want to make sure that you see some 20 was enabled. So we're just gonna require you see 71 abled, and that is a modifier. And that's pretty much it for now, for AL events, methane Struck's and some of the storage we need, along with some of the variables that we're using the next video, we're going to start doing most the court implementation of the functions we're going to need or taken. We'll see that 23. ERC721 Token Creation and Access: Now that we've got the skeleton of a contract ready, we're going to start creating the functions we're gonna be using to interact and create al tokens. There's a couple functions we need gonna have create, took in function. Gonna take a string name, address. Oh, no. You went to 56 Price. This function allows us to specify a price when creating. I'll take it. So if we wanted a have, for example, or a pharaoh competition that we wanted to be able to specify a token and give it immediately to somebody else other than just putting it straight up auction. This lets us do that so it gives us a little bit control. It'll where a token goes when it is created. We need to require that the owner doesn't not Sorry, but the owner address is actually ballot. We can do that by going address here. We just want to make sure the owner dresses not zeroed out. We also want to require that the price we send it is greater or equal to the starting price . This just allows us to make sure that we're not creating a token has a value that's less than the study of breast. Now we're going to create a new day and I object, and we're gonna use a function called Generates random DNA And we haven't quite written this yet, but I'm just just get here so that we when we do specify it, it's just gonna ornament would be filled. And we're gonna also call a create where it's gonna create a new function that we're gonna call here, could create, took it. This takes the name DNA. Oh, no. In the price. And we're gonna accept a specified but these now. But before we do that, we're gonna create the other great took in function, and this one is only going to take a string night. This is going to be the one that we use most often asserts the one that allows us to discuss in the name Belle Doggy and it'll have the d A. It will have the owner set to nobody and have the price set to the starting price. We're gonna make it so only CEO only we can call it effectively. That's using the the access control library here. Now, within this particular function, we're gonna have something very similar bites. Five. Do you own a vehicle to generates random? Do you? And we'll call. That same function is above. It's so you can They're him on and possibly in the DNA that we make. We'll go and said the address is equal to us because by default we are in the tokens all the sort of the contractor into targets for reference. This it means the contract. And then we'll set the base price to the starting price. Cool. Next will create the create token function. This function create took in. This is going to take a string name? What size do you know? Address? Yeah, You went to 56 Press. It will be private because we want to be handled internally. And then you might have seen this before, but we're going to use Dougie, which we create in memory. Cold doggy, having equal to a new doggy. Instruct instance what we said. The name is equal to the name and the DNA is equal to DNA. And we you went to 56. New token. I d physical two doggies. The Iranian, in other words, don't push. And we add our doggie to that stack. Then we subtract once we get the correct into index we're working with next, we're going to create instance, we're going to apply the i d to the press. So we're gonna take Took in i d to price mapping with the new took in i. D. Is the index and said equal to the price of the specified We're going to fire the token created event and possibly took an i d the name DNA, price and the owner. And finally, we want to transfer the ownership off the tokens. We haven't written this function even, but we don't need to cold now transferring a ship takes an address which in this case said it zero and owner Well, a new owner and the took and I D and testing. Now the only thing we still need to write is the generator function, which we mean. Actually, we can probably that now what we'll do is we'll write the get token function so they get taken Function is what we use in order to get the details for our token and sent the u. Y. Since is the will eventually be a website. Basically Well, what do you wanna pass it You went to 56 give it a token i d It is going to get Public view , which returns a returns, a set of variables that we define, which will be a strength took in name slots, five DNA. You went to 56 Royce, you went 56. Next press, this should make sure and finally the address off the who scroll down and then we'll actually specify how we want to get this data. So for the token name, we can get this by accessing the doggies array by and feeding at the took and I D, which will get the correct stogie. And then we simply just want to get the name field, which is the name field to find with instruct, then to get DNA. We want access that same donkeys away, we would posit a took and I d again. Except this time we won't get the DNA cross. We can get that from the mapping For the token i d. To price mapping again passes the token i d. And then the next press. We can get that using a function that will write a little bit later called next Price all it will possibly a token i d This basically is just going to calculate the next price using some maths that we will specify soon. And then we will set the owner using the token I d to oh, you know, napping and getting it The took in i d and test it. And that's how we will get one token now. For example, if we wanted to get multiple tokens, we can also do that and, well, right country to do that as well. So we'll bear function, get all tokens will be a public You which returns? Find something a little interesting. It's gonna return three a raise Gonna return on the rails 2 56 Bit inside, it's just another array off 256 bit of managers and an array of addresses, so we'll get out total supply. To start with. This is gonna be a total supply off tokens in existence. We can do that by going on spending 2 56 total is equal to total supply. We are gonna have to override this particular function a little bit later as well. But for now, we will just testify on site in 2 56 array memory. We're gonna get a list of all the prices. But to do this we need to find a data structure off the crap size. So this will be And you you went 2 56 array of size total. This is basically to get in the total from the total supply to specify how large we want this array type to be because we need to be very careful when we specified size of race that we always we always know exactly how the elements were dealing with. That way we can effectively compute gas prices, which we'll talk about later as well. No, we're just gonna copy and paste this three times because we need it for three different things. However, in the last one we just need to address and this is going to represent the next process. And this is going toe address. The owners then we need to do is get it right. Either each like him this then the total I plus plus where crosses I is equal to the token i d to price the next prices by is equal to the next price off. Why then, owners? I musical to took in i d to owner. Hi. Oops. That should be a square bracket. Sorry. And then we've got We've populated the three arrays with each buried values that we need And then we can return. Place three raise by going presses next, prices Oops and notice. And that will allow us to get all the details. Old tokens with one function very easily in the next section. What we're gonna do is at a few more functions. Really well, tokens. And we're also gonna fill in the blanks and write some of the functions like the generate random DNA. 24. Generate Random DNA: in this video, we're gonna go through creating two new functions. We're going to create the generate random data or DNA function and also the tokens all function, which is going to return a list of tokens that are owned by a particular owner. So stop with we're going to create the generate random d. N A. Function. We're gonna actually do this back up here, underneath out, create token functions. Little guy function generates random d and I, and this is gonna be a private view that returns it by five. And what we're dealing with, random numbers in the Blockchain will be very careful because they're always to exploit and predict which, really, you're gonna get out of them. However, if its particular contract, it isn't to critical that we make sure that people are able to make it like this for two reasons. One, we're not dealing with any money with this random with around nature of this other than generating the i. D. S off the doggies. The second rate is that we are the only ones who can cold dysfunction as it is private and well, technically, we cockles at all. It's only cold by the functions pride to it, which which haven't only seal level. So we are the only one who contribute its function says never away that anyone can kind of influenced the way the outcome turns out cemented applying a lost block number. This is gonna get the look number off the block on our Blockchain. We're gonna use this to cede the random that we get that would be bites five. Well, might say to actually, and we're gonna get a hash value, which is equal to the fights. Me, too. And we're gonna do is we need to go block dot Look, yes, look, hash And in possible lust Look number. Gonna get the hash on this block number half being the 32 bite long hash off that book number Another really explain it very well. But, um, hashing function is one that takes a something that you can understand and turns it into A random series of characters Effectively encoding it. You can't reverse engineer that hash in any easy way Once you know the relationship between number and attack. Yes, you do know it's one way and you can't get back, but, um, yet basically, this book hash function just maps a value we posit to a hash Ellie. Cool. We're gonna use that Teoh generate of the Soviet era fights. Five is equal to Dina. We have that equal to looks like five DNA is equal to That's fine. You know, we're gonna cost the outcome of this. I'm gonna pass in Nashville and we're gonna end it with size off the bites. We want out of it. So 12345 But we only want war in this case 12 three full. Because the 1st 2 bites in our I d. We want to be able to set ourselves and explain it a little bit later for 2 16 Basically, what this means is we ended with this value here, and then we bit shift 216 places. So we'll just a five bite, um, for about DNA and then all we need to do with returns of DNA and that's gonna return basically effectively create a DNA randomizer full our contract. Cool. Let's jump back down and we're going to write the next function, which is gonna be the tokens off function which just returns a list off the tokens that A or nines we have acid in an address on owner Go is gonna return yet an array of insanity. Just 2 56 We'll get out token, Kim, which again is gonna be equal to he balanced Botvinov which will specify saying and we're gonna check to make sure the token count is equal to zero. And if it is, we just return it to you, right? We're gonna bother going the feather. Fantastic. No else we want to go into find. And on Sunday in 2 56 Caray sort memory. Good result. We have an equal to you inside in 56 and have it equal to the size off talking count. Then we'll find a total which is equal to the total supply. And was it fine and outside in 2 56 for the Result index, as we had right through the various results, we need a way of storing that. Next we'll go and create a full loop. And while we're less than the total number of supply, go increment I and then we'll check to see if token I d to owner with eyes. A perimeter is equal to the owner's address. Basically, we're gonna extract the owner token. When we find the owner, we're gonna set the results results, index. So the next free space and then we'll increment the result index by one. And finally we're 10. Their results. This will just return an array off the tokens that are invite only untested now, in the next session will start to go through implementing the other. You'll see 7 21 methods that we need, including the withdrawal methods and the purchase methods for buying and selling tokens and also taking the bounce out of the contract that is accrued over time. 25. Token Purchase and Balance Withdrawal: in this video, we're going to start in pointing to functions, one of them being the purchase function and the other being Withrow Parent balance function looks like for each of them do along the way to start with, we're gonna make the withdrawal balance function. The withdrawal of balance function takes an address that too uncertain in 56 small amount. Basically, our contract is going to stop accruing some value within it, and we need a method that allows us to extract this value in the form of ethereum to any address that we see fit. Now we're gonna make this public, and we're gonna be very careful that we divide. This is only CEO function because this one is pretty crucial, as it's going to start building up quite a bit of funds as people start to use it. So we're gonna require that the amount is less than an equal to this stop balance i e. The belts that it started from contract. We just wanna make sure the amount we're trying to extract is less than next. We're going to check to make sure that the amount if the amount of zero i e. The amount that, um, we specify, If we don't specify an amount, then we want to extract it all. So the amount is equal to this stuff God's. Then, if the to address is equal to, I'm basically no address, it'll So if no addresses specified, then we wanted, just by default, transfer all of the transfer only of funds to the CEOs. Address Sisters, the fullback. So if we don't specified address, either, it will just send all the funds of the CEO else. The to address transfer is called with the amount, and it's basically covers all the bases that would possibly run into with this particular function. Cool. The second months we're gonna write is purchase function, which is gonna take a token I D and is going to also take a payable value on. We'll talk about that one sec, so function just now. This isn't a sec. 21 5 token Sorry money, etc. 7 21 function. But it's one that's going to directly impact how al token is valued. So function purchase is 2 56 with the token idea, it's public, it's payable. Payable is an official modifier that is built into this living partner English. I know. What it means is that the function We will take a theater in value, so you consented value other than the gas costs. And we also just want to make sure that when not paused is applied because I want to make sure that people can't pay into this contract Bullet posed. This is quite a long function. So bear with me, we're gonna pay an old owner. We're seeking to the owner off and then talk about me and then isn't lce 7 21 function under oath were printed dress. You know that's gonna be equal to the message. Don't send her. Well, the person who initiates this transaction 2 56 selling process just gonna be equal to the price of the token. I d. It's just gonna get the current value of token that people to pay Now we're gonna require, but the old, you know, and that their dress is ballot. We're gonna require that the Yeah, yeah, it's dress. You felt we're going to require that the old China doesn't know people than you sound silly , but we just want to make sure we cover that base and we want to concern that this is getting a little bit more complicated, but it's one that we need to include because it is defined as a best practice for these kinds of contracts. We need to require that the owner, well, that the contracts owner is not equal to the new owner. It's the contract has an address. You just want to make sure that contract is not who the owner is because we want to prevent contracts in bay coming. An owner of a token basically contract should not earn tokens. They can get stock. If they do fantastic, then we'll have another require. Uh, cold selling press is greater than zero. Just wanna make sure that is valid. And we want it also require that the message dot value is greater or equal to be selling for us. And that pretty much covers all the main bases. That we want you to confirm that we're not gonna have problems when we blew this. Next, we're going to call the trends the function passing at the old owner, the new owner and the token i d. And we're going to send an event called Took In Sold, giving it and it's quite long. Need a token? I d getting it. Tony's looking I d stop name and giving it doggies. Took an I d dealing the selling price. The price off the token I d the old I know. And then, you know, I'm pretty sure it's great. Then we're going to calculate the excess. So this is the extra either that should be returned back. The buyer if they happen to transfer more than the selling price, all the talking This will be you in to 36 excess, which is equal to message. Don't value. Subtract now sub is actually function within thes safe maths, uh, contract. And we're gonna subtract the selling price. We must get also access, and then we're gonna get the contract cuts of the contract count is the amount, you know, because going to 6% off how much we're gonna take po transaction and put into the contract , which we can actually withdraw, even withdraw balance motion. It's a contract cut is equal to the selling process. Times we're multiplied by six divided by 100 which is what is gonna put his account 6% Cut . Go now. No need to transfer if if this is the initial sale. So basically, if this the initial sale of the token, we don't transfer it so old, you know, not hopes is not equal to address this. You just contract address, and we're gonna transfer the pain. It the payment minus t contracts got to the old owner i e. To the person who already owned the token and is now getting the value out of it because someone else bought it. Since selling price subtract, contract comes and then finally, we're going to return the extra ether to Well, sir, returned the extra either to the to the new owner. Hold tight show. It's great. It's your right. You own a dog transfer in excess. Miss basically takes you the excess. Um, if they're from the transaction entrances back to the owner or the new era Aida Percipient Estancia hated this transaction. Go on. That's about all for this particular Tora. The next part we're going to deal with calculating the price of the tokens and how we want Teoh to manage the steps off the process of each took it on. And I'll speak to you about that next 26. Token Pricing Steps: in this section, we're going to discuss two different functions. We're gonna do the price off function, which is going to turn the price of a token. Um, and we're also going to stop Tiu, define the limits and how much we want token prices to increase after each purchase. So we're gonna stop me writing the function for price off, which we've referenced a bit above. It would be good to finally define it. The price of just takes an unsigned interested. And it's successful over a public view returns and on site and 2 56 and in return of the price. So I took in i d to press using the token i d for the man. No single took a anyway, next, we're going to define the increased steps. For now, the value of all took it. So basically what we're gonna have it is we'll have a starting price help the doggy on, then after each purchase, we want the doggies value to increase by a certain amount, which incentivizes people to buy it after somebody else returning the original owner a portion of profit on, then also giving someone else an opportunity to make profit off the doggy in the future. So we're going to the final steps Has four different inside in churches. Increase limit one which is equal to what next? Start with your part to either we're gonna do some int. They were gonna copy this because we have to do a full times. We're gonna have 23 and four. Now, the second step is going to be 0.5 a Tha The third step is going to be to either, And the fourth step is gonna be five so massive. But when we get to that stage, good big players in. Yeah, I just noticed we had any shop here with the token ideas. Well, on the price which will result that problem. Sorry. She dresses properly. Something to the purchase function. There is. There was a mistake with the toga body being referenced in the price of it should be token . I d cool now below here, we're going to create the next process function. It's going to take the unsigned integer to 56 off a token idea. And it's been a compute than its precedent. So be a public view turns and it will turn that express. So to start with, we get the press off. The turkey currently will be an ensign in 236 Press is equal to press. Oops. Lights off token, I d. And then we're just gonna you check to see if we should, um if we're above the limit, basically. So we're gonna go and do. And if price is less than the increase limit one, there were 10. The new price, which is gonna be multiplied by 200%. Well, I doubling and then we'll divide it by 95. Go. And then the else If price use less than increase limits to same sort of deal, we're going to return the price dot Well supplied by 130 fun. It's the steps going to slowly get, um, is gonna become less less. It will occur unless unless Paulson, but we more, more drastic is 96. Well, safe price. Darts, mo. I'm sorry. Should say price is less than the increase limit. Three. Then return christ dot multi. Um 1 25 Divide by 97. Less than increase. Limit four. Return price dot Low 17 Yeah. Do you only 7%. Um and then finally will have a lost L statement. Oops. Clearly I've spoke that room Have a final statement. Which else will turn price dark mole multiplied by one or Dane divided by 98 Be the final. So it will continue to grace, but no, not following any of these standards. So that is the pricing calculations and getting the price of tokens. In the next part, we're going to start to the final that you'll see 7 21 behaviors. There are about six or seven that we're dealing with, but they are quite short. So we should go to special in quick. I'll see you then. 27. ERC721 Token Function Overrides: Okay, we're nearly there. Now. We're gonna stop to define the overriding behaviors for the S E 7 21 took and functions, so start with function. Enable e R c 7 21 It's gonna be a public that only the CEO can call, and it's going to basically to strange the e r. C 7 21 enabled to equal. True, they will do function total supply. And this is going to be a public view that returns signed in 2 56 total supply. And this is going to return in total. Basically, just said the value of total supply to the hoo doggies don't length cool. Next, we'll do for set the function. So this is overrated variables that are stored within the C 7 21 contract. So if you have a look at the contract, um, we are setting these balance values and eventually were returning them in this country. So these are just function that we need to declare. So this is balance off dress, you know, public U turns side in 56 balance, and it's going to set the value of balance to ownership ownership. Token count. I think that's what we called it school. She took it. Can be pretty sure that's what we call it. Scrolling the very top. You have a look Ownership talking count getting the total of the tokens. Cool. Next, we're gonna have function owner off, which is going to take an unsigned int 2 56 and took an I d gonna be a public view that returns a address. Well, owner. And so there was gonna be Oh, no, it's legal to token i d to let me know which is the token i d composite. Basically, we just mapping the structure, values taking, sir, we're taking the values from the map things, and we're returning them as this value here balance. Next, we need to declare the approve motion which takes an address to unsigned it to 56 token i d . It's public can only be run when the contract is not closed and only you see 7 21 Kohl's commune made to it. It requires that we own owns his eyes, is a wrongful, right in the second well message dot sender and took in i d just checks to see that I send owns a token basically and then we'll set the token i d to approved mapping. Based on the token, I d equal to the to address. And finally you're gonna call the approval function or event. You know, this event is specified within the AOC 7 21 contract. Tell the out of here Preval asking for the transfer mint. I'm so we're just calling this event basically. But we're using their implementation off the event to the approval takes a message to send a to address and the token Heidi next ocean trance for From we're gonna taken address, which is the from address you're taking address, which is the to address. We're thinking on Sign Into 56 which is the token 80. This is a public function. This is again, when not pause, being very careful that we don't exiting. Run this where the contract is not or the police station and only your season 21 we're going to require that the to address is a developed dress. Were you going to wolves? Indentations hunky. We're going to require that the urns function again that the from account does. In fact, um, I want to talk in that we want and we're gonna require that the approval for this function to offer this, sir, that the approval of this token transfer is actually also acknowledged using the message sender address and he took in Ivy. And then we will perform the transfer from the from address to the address on the took an I D. Posted. Cool. Next function is going to be the transfer function. Gonna be a function transfer. It's the public implementation of it. Gonna taken address to it's gonna taken on site in 2 56 So can I. D and the public is gonna be when fullest again. And it's also in early lce 7 21 function. It's going to require that the to address is in fact not and not invalidation. It's going to require that the bones well, that the sender, in fact, I want to take in. It's gonna reassign the ownership and also clear, clear any pending printing approvals. So that's using the transfer method again. Using the message send a to and the token I d. Fantastic. It is only a couple functions, so we're gonna smash thirties as well. We're going to define the implements e o c. 7 21 which is a public the when not posed. Uh, it's gonna return A but we in value just letting us know if the contract is, in fact, has a 7 21 compliant. It's going to require that the what sorry require is going to return the Boolean value off the RC 7 21 neighbors who three more functions, three short functions gonna function. Take ownership, which is gonna take you in. Took an i. D. It's public. It's when No post and it's obviously only you see 7 21 compliant. It requires that we are approved and at the dignity he has proved. Yep. And we gonna transfer If that's the case. I took an I D to owner and then took in i d The message. Don't send a and that's a good idea. Wilson. The last two functions relate to the name of the token and a symbol of taken. So we got the function nice, which is a public view turns This is a string on and it's just gonna basically return the name of how token which in this guy's gonna be crypto doggies. Well, whatever you wanna call it this is the value that will appear on, like either scan and what not when someone views the data for your token, so make sure you get it rides before you deploy. We'll also declare the symbol on this string on. We will make else and illegal too. Critter, Dougie. Crypto doggies. Don't be talking many. Yeah, CVT go. And that is basically the implant. All the implications we needed for the U. S. C. 7 21 compliance. The rest off the function of the right are private on. We will do that next year. 28. ERC721 Private Function Overrides: already. We're on the home stretch for our It's not contract. Were riding the lost full functions, which are the owns function, the approved function, that transfer function and the is contract function. So let's get started. We'll do function. It's to start with. This is just basically take a address which will call a claimant and a token idea and basically just confirmed that the token owner or that a token isn't back to signed to the owner that we are specifying, um, since gonna take it address, which we will call a claimant just because that standard Bigley's and that is gonna take it took an i d. Be a private view that returns a 1,000,000. The will return the value of the token i d to owner mapping, taking token day, just confirming that it's equal to the claimant. Easy. Okay, Dokey Next will be riding the approved function that she's gonna taken address to and announcing into six for the turkey. That's a private function. That's gonna the view is going to return a bull. Private function means we're gonna only be handling these internally our contracts. You know what's gonna be calling these? That's why we're not doing any requires in this particular case, we weren't down there requires and previous functions about took in i d to free thinking. Told it you can I d equals equals the to address Just confirming that a token is in fact approved for the new token assigning. And we have a motion called transfer. This is important. Was this transfer the ownership of took into another address it's gonna taken address from and address to unsigned in 2 56 Ah, for the took 90 it's gonna be a private, and we will do owner ship token. I can't change the count for the to address it's lists or in cricket committing. They're talking out. We're going to insurance. Uh, the tokens ownership. So it took an i D to owner. Using the Tokai D is equal to the to address women, creating the token. If it's from the no address and then we can't account that address, basically, so we're best is going to remove the previous ownership. Wrong address doesn't know there's no equal. So, basically, if if if the address is correct on Ben, we will. Ownership token counts from address and decorated by one name. We will delete you token I d to approved. So remove it from the Nothing just remove the approval goes. It's no longer needed to be addressed. And then we'll finally Wilmot the the transfer that which is the event that's been Air Sea 7 21 Contract the fishing. This is gonna take a from address to address a token I d. Awesome. We have one more function around. This one hasn't assembly in it. Fun. Um, so it's going to check to see if an address is a contract about There is some current online that everyone basically follows for this particular function. I'll show you got sick. It's a private. You returns a Boolean. Basically, what does we define? A tour? 56 bite size. They're evil. Then we run some assembly, which, um, ways a great idea for this particular function. It's the only way to do it. And then we will do that function on the address and just confirmed the size and its size is greater than zero. Then it is a contract. Cool. I don't know too much about that. That's just standing that people use, and that is pretty much all the code that you need for grip it or in the next section we're gonna do is we're read sort of factor out. Our unit tests confirm that this all still works. And if it does, we're gonna start testing on remix, so I'll see, you know. 29. Refactoring Unit Tests and Crushing Bugs!: of what we get into unit testing. I just wanted to go over a couple mistakes. We've been in the previous video to start with online 243. We should have put returns. We have a couple of instances this following on 260 and on to 64. We also have a mistake with how we've defies token idea here. We put token if it so we had to change it back to Tokyo. Cool. When already to progress board into the next section. We'll close down the grip in Tokyo, Seoul and let's get started back in the Crypt Adobes util function, which would reflect a too bitter making more equipped, fully new contract to start with, won't gonna do a such remove his entire function. It might have made much sense, but because we're making a couple fundamental changes, we might as well write this just second time that way actually understand going on. Okay, let's start with creating a function. It checks to make sure the total supply is in fact equals the expected value. So when I say totals black mean the total number of tokens that exists inside the contract so we'll create a function called Chick Total supply were positive and X elected value, and the older was again. We'll declare the it and say that total supply thistles. The message that comes up in a prompt should be equal to and then expected, will you? Then we'll declare a function indigenous. We're going to take how instance of crypto keys, the contract. We're going to check to make sure it's deployed. Then we will. We're at a function notice this time. We're not using a sick because we don't need to, because the value we're getting in return is instant. We don't need to wait for the doctor and update. We're just getting the value that is set inside the smart contract when it is created. So we have the function we pass about instance on and then we take, for instance, don't total supply, which is the name of that function. Then we call the coal that which is says we want you, Cole and get the hell you up. Then we're gonna call another function, possibly total supply. And within this, we're going to just assert that Sorry. Set the who, sir, The equals. Basically just checking to make sure that something is equal to another thing. So it will take a total supply and we'll give it the expected value. This is actually going to check the total supply tokens in circulation was no contract and compared to the expected value if it is incorrect, then l method will throw an exception in return. The straighten toe supply is not equal two and then expected value. Fantastic. Then we do need to make sure that we are handling the Dunn case and the catch of any exceptions just was the full news and take the check total supply and exported as a function. Now let's Riyadh That function for creating all doggies could be slightly different bottles a slightly side. So good function check. Don't be creation. We're gonna positive just to name this time. It's the prodigal. The variables really need to provide a name now because now I d is is generated when the dog is created, how DNA is generated randomly and we also don't need to provide an agent. Books were no longer handling it very well. So it and then it should create took in great token should create a a random, don't you know, named and then Plus today that same sort of deal Do function, doctor, we'll take crippled donkeys will confirmed it's deployed. Then if it is, we'll run and a sink function because we want to wait for the event to fire mangle. Possibly instance, and using this instance will use the A white function or white on the instance. Don't create token. This is the nature of our country. Now, when I love using, create the reason create took name and that's what we need to provide. But we also want to provide the from here, and then you can't win said it so in this case will send it from accounts ERA, which is out on her account. Finally, we then need to handle then statement so that we could then and we will come function with the result and using the results we're gonna do sit taught, include we're going to check the result talked lugs the first look in the array. We're gonna take the event string. We're gonna compare it with token created token created matches, the event that we have within our crypto doggy smoke contract. It's the event that fires when the U. S C. 7 21 Hercules created, and then the message we want to spit out. If that's not the case is token created. Event was not triggered sweet, and I think we'll go to closed up of us. However, we do need Teoh handle done event here on the catch of the any exceptions and same sort Do take the check, Toby creation and plant it right There is what to cool and back into scripted on tests. We just need to adjust the functions. McCauley No. So to start with, well critical to the Czech total supply function in positive values Europe. So because we haven't created and you don't visit, So then in this with you here for four ignorance, ex Eagle Syrah X is less than 100 x plus. Plus, we're gonna go check Dougie Creation. But now we only need to pass Indeed, Doggie's name, possibly else. Fantastic. And now, in theory, this should should test successful. It's let's give it a crack. So go in PN run. A test already is we have a problem. Um, it looks like we've made another syntax error. That's fine. That's back onto line 1 94 in the contract. So if you jump back into the contract uh, Dr 11 94. Yes, indeed. I have done deaf instead of beef. Cool. Um, let's run it again and see what we get. Looks like another mistake. This is that online? 237. Um, we have address, but we need to be checking to see if dress used notes. We should between zero into the brackets there Go and let's run to skim. Good to go through this with you because it means that we're picking out the mistakes that we night and the mistakes that your contract probably has. It is looking like it is working now. She's good. Fantastic. Now it's Rebecca. Make sure first and fired was told us. Blush speaking. Zero. And then we have all operate tokens. And then what we can do use Now that we have 100 tokens created, we could add a another. No, the test after this to check total supply, and I haven't equals 400 because that's how many doggies we should have. Let's form this test again, and we'll 100 tokens have been created. Confirms that our contract is in fact working and is generating jobs as expected in the next two Toro. We're going to stop dealing with cravings is simply why blow to go through the how we can use Meta mosque to make transactions and we're gonna load this contract into remix and stopped to play around with it and see what kind of data was story. 30. Introduction to Remix, MetaMask and Ropsten Testnet: Now that we have a contract completed, we need an easy way to test and deploy it onto the Blockchain. So for that gonna use readings having to use remix. You also need a browser extension for five bucks a crime called Many mask. Let's go jump onto the Adam store and find this. Some use the Firefox version. Basically jump onto Adams. Don't motility ogg and search from in a mosque and its five folks. And when you're done, it should appear in the top right up here. Now, if you click, that will give you a notice about so things you should probably raid the home of the tens of use, which again you should definitely read. Um, this is still bad software. I would not recommend putting a lot of money into it. So now we're using. It was developed to, um trusted as far as you would like. You would trust yourself. I should say, um, there's no warranty. So when you get stuck, you have to define a new password. This is very important. You don't want to forget this possible. This is basically managing your private keys for you. So whenever you make a transaction on a Blockchain. I wanna interact with your with your wallet address or your contract that you earn. You need you'll possum to your private key and your private, So make sure you keep this positive. Very secure. So I've created my password. No. It's gonna give me a random set of keys for my That's my name on it. Basically, um, I need to keep track of this and keep it somewhere safe. So I'm gonna Kobe somewhere safe. Um, and once that's complete somewhere safe. Obviously. Um, not gonna be using this little if anything off this because I've just revealed it to you guys, but keep it safe because it's very important that gets access to it. Even though they don't have your password, they can still create your public product. Keep with this. So just be very careful. I've copied someone safe and like that, they've actually created me a wallet. So now, swole it is visible on a scan. So if we jump up to eat the skin, you can see that it has their funds because there's a new address. That's your address. That is your wallet. What? You can store your funds And in our case, it's the one place where we're gonna be story now. Development funds up top. Here, you can see a main network field. What we're gonna do is to drop down to Robson Robson is a test network. We can get three free Ethereum that we can use for developing on the Blockchain to get free to some of this free. Either you can go Teoh wraps, tin faucet sightings Feel that right? Russian faucet. The official euro is plus it. Robson, don't be a Port 3001 and we're just gonna wait for this load. Oh, well, wait, let alone if you click the three dots here, we're gonna copy the address to Klippel. Now, this address here is your wallet dress. It's the same one. You can see anything. Skin here. So if we go over copy at that jumps, faucet paste. Oh, address into their and basically asked to be said one. Either the address would be added to the cute. You can feel the transaction hash for this. He saw you thought that being said on in a few seconds. But we should say is this value here update that is very great Tiny. We're waiting for that. If we jump back over into remix, what we need to do now is actually load in those contract files that we have just made to go browse. And if we then jump into you know me folder into the contracts folder, we want employed access control. We want to act upload crypto doggies. We want to upload. You'll see 7 21 And when a bloated state math, once we have this full contracts loaded, we'll click. Uncle Tobys, What's he going to go over the Anil analysis and disable the symbol of arable names? Check box because you find you get a lot of problems that come up because especially within the access control we have a couple of arable inside, A very similar and the compile it trust to be smart and to its credit, is actually very useful. But for what we're doing, we don't really need to do that right now. See this contract? You should see it start to compile it Here, there once about 15 things and we are basically set. Now if you jump back into a bullet we wanted this is just waiting for that value to come through. We can have a look at that fall said address again. Interesting. It can take a little bit of time for process. Don't expect to happen instantly. Uh, can take you can take some time for now Will continue to work What we need to do at the top here. What we want to do is to change the in very environment to injected Web three now injected with three is going Teoh mean we're gonna be connecting. Teoh insisted. Animals, um has crashed my brush. I might have to reload page because I have since installed in a mosque. So let's do that and close that off. Reignite remix will inject. We'll get the word three libraries on load and it looks like it It didn't load in time to grab those lives. So luckily, what we just did is still loaded. Rerun. Kabyle, stop this over to Krypton. And as you can see, we are injected 13 on Robertson Network and we also have the account that we created listed there. It's like we are still waiting for anything to come through. Unfortunately, it doesn't like we're going to get it in a reasonable amount of time. We'll give it a couple seconds. But while we're waiting for that, what we can do is change it back to job script PM on drums. Creepy and basically, uh, it will run an instance off the death Blockchain on he drive a script so we aren't relying on, well, let address here for anything. We are purely relying on the A M and the wallet said, It's it's oppressed. So these are the five addresses and it has set for us. So we're gonna slip to count zero. We are going to switch to critical these and if we create, we should see a transaction appeared on the bottom. Here we get details. We can see that all of this import but could that is the but good for all contract we just wrote. We will also be supplied a contract address. So that was the address that this code could be excess Xs from within this job Script bm We can also see all the functions that we have written and the functions were able to run. So, for example, one of the functions we will be using a lot use The great took in function. Let's create a in this case of a doggy named Steve, make sure you put the brackets or the courts around it. As this is history. We will hit great tokens and we can see that transaction is indeed pending. We have the details. We'll see it. A string named Steve because that off on and we just want to look for when the event comes back, I'm pretty sure we might need to select Listen on network that's not come up. That's actually a good example of where we can go. Try to find the toy committees created. So if we go to one of our other functions, what function could be used, we could try taking will total supply, and it returns one So Al Token has been created. Reno tokens. Why is one and we know we index from zero. So we're looking for the first token. So if we look for a function where we get a token, for example, get to again and popping zero, then he'd get talking. You'll notice that it returns the information related to that particular target in this case to Steve, we have the round of DNA generate for us. We have the price and the next price in way. And we have the owner of the token, which in this case should be the address that we sent a transaction from. We can also see that the amount of the throttle well, it has decreased. And we know of that one cat, Holzer. That one. Dougie on local box. Let's go back to the injected. Went through photo and CFO eat has come for yet. We also wanted to say Listen, okay, Network. Otherwise, we're gonna see old of various transaction on the ropes. And then what? It does look like there's no white come through, um can take a while, But like I said, you're you're more than welcome to use the job scorpion while you wait in the next year, what we're gonna do is start to build the web. You Why that we're gonna use to visualize all this data, and we're also going to deploy our contract for riel onto Robson net. But once it's deployed, will be able to access from Web browser and interact that through the website 31. Getting Started With Frontend Development: Hey and welcome to the next section which is on building the U Y for our small contract that will enable people to be the interact with the contract we've written using the Meta Mosque browser extension both chrome and Firefox. Now, to start with you and download the resources from this video and within the website resources, you're gonna have a photo called source. Import this into the current project workspace. Once you've done that expand folder initiative force of items usually CSS image Js Then in days, the CS contains older CSS files that will be using for our project. It defines the design and the general field and the way it looks effectively. Now, if your company index toe html, you know, break right through. I've stripped out most off the cool content and just left what you need as thes guilty of the website. As I know this causes and a website and were designed course so you can have a look under the jazz folder. We've got the doctor stuck jazz file. We have a basic structure that will be using including a document not ready, which will basically be called when the website loads we have a generator doggy image function which basically is gonna be used to load in those dougie images we saw form before given a doggy idea or an OutKast DNA, and it has the absolute So basically, all of the contract related in directions will be added into this APP item. We also have a Libs directory which contains a couple of libraries that we need in order to run the smoke contract client on the Web browser and on images. We have a silicon and a background image now, in order to run the website and two dead for I just want to in the root directory run and can run. Dev, your Web browser should automatically open and you'll be presented with the basic layout that be working with the rest of this section. If you right click and inspect, it will bring up the source menu, which is useful for being able to debug as we go. Right now, you can see we don't have any errors just confirmed here in the same sort of state. In the next section, we're gonna discuss how we can start to add cods that display the various attributes that al doggies hold and eventually will be working towards being up to purchase those doggies through this website 32. Creating the Doggy Cards: before we start writing too much of the JavaScript that interacts with front, and we first want to write some of the front end components. All right here you can see the card that were kind of aiming to make a look like this example of the doggy image loaded based on DNA. It's going to have a books that has the current value and the next process you. When depression clicks the buy button, we want to trigger an event to purchase this car. There's also an owner address. If we click that, we won't like it to go to the ether trader or either scan website and look up the owner's address to see what transactions they made recently. Let's get started first and just riding the cod I've put eat like I said, but the example of rights we can follow along as we go now, I've already placed in a bit off the base config for the card here. You can basically see what you need for the outline of this, so let's get started on may be adding the doggie's name, So what we'll do is what should I get comment to start with so we're up to. Well, this is called doggy night. It's going to be a hazel. It's going to contain the glass card title because God title refers to this box up here. It's also gonna have doggy name as it's close workings this later in the JavaScript, we're gonna have a custom style. It's in line, it's gonna be display, and we're gonna have it in line block. Then we'll close that off, and we'll also have the word name in here. It's just a pre Phil that's gonna be replaced with a dog's name when it gets at it. Next, we're gonna have the doggy image right down. Theodore. Key images after gonna be a canvas and canvases works slightly different images did. And when you're making them problematical, so we're gonna need a with a Kloss text need to Just using this direct everything up doesn't really matter too much what you've got here. We're gonna have a canvas dive inside with the class card image, top and doggy canvas, and that's what we're gonna reference later to apply this camps object onto the card. We're also gonna have a custom I d cold. I d. I'm gonna have it. Doggy canvas I d. And this is so that our canvas function can reference the correct canvas on the screen. Finally gonna have a style by item in one with a wits. 100% it was. Make sure we close Cool. Let's jump down to the next line. And now we're gonna stop our cod block. So this is where all the information below images stored. So what kind of grouping? Things together. And within this, we're gonna have a dip for active class, which is going to be God. Look, open up the doof and create another comment code. Doggy DNA. Just so we know that we're dealing with this particular dean a component. Yeah. No, we're gonna store as a div class doggy DNA. Oh, actually, no. My mistake. We're gonna have a doggie text because should wrap this in a square bracket to don't text. And within this, we're going to have a small element and just gonna ride DNA. Now, we've got some custom CSS that handles changing this small element to make it look like it's bold and ground. We're also gonna have a class is equal to doggy. Next hopes are dog eat DNA, and this is the actual value. So this top one is just a text, and then the actual value stored inside it. And we can leave that in defeat. Make sure that it's close stuff. Let's move on. Next. We're gonna have this doggy text field, Um, another, don't you? Text field, I should say we're actually gonna make a copy of the previous one. I say, let's talk it out twice. Within this, we're going toe next for us, WTI and maybe w next cross and we can move on to the next field. Now we put this line here, we want a match, so we're gonna add a horizontal line. Hey, Joe, Next we'll add a no comment and just mentioned where to Doggy purchase. This is just defining that we're in this box here is gonna deal with Input Field and the Bible within doggy purchase. We're going to have a full That was according to put a form here, because in the past, all the data in the form to the JavaScript win the button is pushed Swiger doggy purchase as the form identify, then within it will have a div class. We'll make a form group and we'll have an input. Great. We'll make another comment. Mugar. Tookie by value, this is just going to be defined. This value here, that's the value that we were going to pay for the dog, which is the But this could be a text Kloss form troll. This just allows us to use, um unique bootstrap feeding were, like regarding around keeping these circular and next to each other. It's just more for you. I appeal. We got form control, Dougie Price, and that they identify we're gonna look for when we want to change this this box, we're gonna specify type being number, and we're gonna specify an I d field that we're gonna look for when we're using jobs. We'll close it off and close off the text next line, you know? No, no, the comment. Doggy by button. Next line. We're going to specify a button object pretty close, but button primary, but in by. And that's again mostly just for visuals on button primary and button by. We have override in the CSS to change the color brown, and what type is equal to submit that simple? Because when we're looking for events occurring in job script. We're gonna be looking for a type submit event works in a story data I d feel, which is custom field that we're gonna replace with the i d of the dougie when we add a card. That way we can look for particular Dokey instead of cards by looking for this field and finally will have another idea Field called doggy. But by but which is what we're gonna look for when we are specifying when an event comes through, we're gonna be looking for the doggy by button event and we'll close it off. Close off the hook, the button field and move on. Now Davis closed. So the only thing we want to do next is just to make sure we don't get confused, will add another comment here. Just say it's a form group will blow this. Just mention that it was a form and below this one will just medicine that it was a cut book. Hey, it's what? How did you get lost? And with off the front car block? What we want to do is at a card foot. So to do that we go did close is equal to cod Footer Now I can't. Footing visually will mean that we get this nice little gray box area where we can put the field. It's within the card photo. We're going to create another coming. You specify doggy on a address, and then we're gonna great a small field. I'm gonna And then the next line we're gonna have a close is equal to and then text muted again. No, the visual thing and doggy Oh, no. I will be the field we look for. We will update it. Also gonna add a hatred which we will be for our link to either scare. Let's go when we want Teoh check for an owner's transaction history and we're gonna have tired is equal to its called black. And what that will do is will mean that a new tableware opened instead off redirecting the page when they click it now off the stiff final comment and just say that we're finished our card footer Fantastic! And that is pretty much all the U Y. Elements we should need to do. We might come back here later if we have problems. But for now I'll see the next set 33. Write the loadDoggy Function to visualise the Cards: No, it's right. The function that we need in order to create new cards and load new dog information. But this we're gonna jump into doggies that Js And then just after the generate image for the doggy, we're gonna create only function. Well, quite a quick comment just to mention what we're doing. My dog is based on input data and then well defined function load dokey. Now, this is gonna take a variety of different variables. We're gonna take the doggies, i d, which is the idea that we've assigned to within this macho attract before that doggy when it's generated. If you remember the array minus one, that's the I d. We got Toki name, which is the name that we specify when we create new doggy good doggie d and A. And that's the DNA field that's randomly generated for us within the contract. Democrat Doggy press. That's the current price. The doggy. So if someone was to buy it, that's the price. Still get it up. Then we got doggy next price. And that's the computer next price, according to the ladder system that we've got to generate the new prices for the dogs. Then we've got owner address. That's the address of the owner off the cart. The doc you. And then we put Luke Kelly All right, which would make more sense later, but basically just just specifies whether or not we own this dog. And if we do, we'll use it to disable the buy button brackets and write the function. Start with. We're gonna get a reference to the cod roe. And they called template example is if you jump back into the index. Basically, what we would do is we want to grab a reference to the card wrote where we're gonna place this new doggy card item. Sweet, good, the cadre. And we're gonna get a reference to the template as well, which we're gonna a pen with the information that we've got. So we're gonna go card right is equal to dolla sign than the name of the element, which is card, right? And well, in the same thing with the car template. Fantastic. Now we're gonna check to see if this card is locally. Angela so OK, luckily kind. And then if it is, we'll go card template don't find, and we're gonna find the buy button element within the cod template sets button dash by Don't That's you. And we're gonna set the attribute to off Disabled equal. True, that's just going to disable the button. If we own this card Els cart 10 point Don't find Button Dash by does actually. And then we're gonna Sorry. Got a bit ahead of myself. We want to remove the attributes disabled if it does exist. We don't technically need to do this because we're gonna pretty sure the disabled actually sort their. It's always good to be. It's always good to be specific, just in case it doesn't up there. We want to remove it. Who? Now? We've got a bunch of references to cop templates, and this is gonna be updating all the information within the card based on the input information we could contemplate dot find. And we're gonna be festive. Aided all his name said dot donkey name dot text because this is text field with a pass it doggy name. I'm gonna make a copy of this because when you use it a few times now, next we're gonna get do the dougie canvas, which is find dot dougie canvas, and then I'm gonna get the attributes I D and then add and you attribute to override that called Doggy can this and then we're gonna penned a doggy i d. So we're gonna end up with an I D field called doggy canvas to canvas zero depending on the ideas, this will make more sense in a sec. It's to do with the way that we generate the canvas items. This is to do with the difference. Being canvas and images on this we need to do is because it's a canvas. Cool. Next line, we'll go card template don't find and then dot dougie DNA Next deal. This simply just a text update on donkey DNA. Cool. That's actually it. Same with the next God. We're replacing the owner address, and we are just gonna be looking for a doggy. Erna. Cool. Have you got something similar With the next field, we want to update the hatred we have been ethos can address link. So what we're gonna be doing is just removing Mr Candy going attributes. We're gonna look for the h ref, actually it and then we're gonna replace it with a euro hate U P s. It was last four slash ether scan dot io forward slash address for it. Slash And then the owner address. Things will basically just return a link to the owner's address on the skin. Cool. Now we're gonna have another car, simply so find now we're gonna Duthie Bye bye. So, okay, but button already done this before, but et en cash by and we're going to the attribute data I d. Okay, data ideas that custom build we added ourselves, and we're gonna store the doggies I d within that custom attributes. This is gonna be important, because when we click the buy button, we're gonna be accessing this data. I d Field in order to buy the button within this field by the donkey within this field can't template dot Find nearly there. Don't, Dougie. Plus, this is simply text optic. However, because we're dealing with floating point numbers, we need to be careful. We're gonna preempt a problem we have, but we're gonna go past float my prime bracket, doggy press close dot to fixed and a rocket and then four decimal places. This is basically just to limit how many different places we display on the front end and then the same deal with the next price for their next dash price Doc text house float, Dougie Next press to fix full cool. And finally we're gonna go caught right dot a pin and then we're going to upend the templates, made a cob template and then get the hate email within it and add it to that road. This is basically just having a card to that picture Malraux for each time he called dysfunction. Finally, we now call the generate donkey image positive the doggy DNA, Pass it in the size which I've worked out to be three is the best one best for from my experience. You can trade it around if you like, but basically gonna scale the way the images render on the canvas. And then we define the canvas that we want to apply degenerate image to, and that's this field here. So basically what? It's gonna take this again and we're going to place in here. And what that should do is slowed a doggy under the you I whenever we call this function and we could actually test this, I have created a string to do this, pop it into the J Coury document. Ready? This is basically gonna load the doggy gonna pass index zero Steve. Possible arbitrate DNA came up with a base price. Next price and owner address and locally owned is equally false. So then if we run outside in PM run death, we should see how don't you, Steve, show up and there's obviously some glitches with the way the U I looks. We'll need to scale the cards out a little bit, but for now, that's perfectly fine. And I'll see you in the next year where we will look at collecting toe a contract. 34. Contract Load from JSON ABI: Hey, in this video, we're gonna flesh out writing some of the base functions that now for intended application needs in order to connect to a contract. This simple was creating a couple Foshan coat, innit? Web three, innit? Contract and flushing out the basin it motion. So we get stuck. So right now we've got this innit function that isn't doing anything. If we jump into this, what we're gonna eventually want to do is return, huh? Which is referencing this outside object dot in it with three. Yeah, we don't obviously have seen it with three functions. Let's add that Civil Day unit, Web three, and then what we're gonna wanna do inside this is just to check to see if the Web through provider is available. The Web through provided will be passed through as Jeff's job script library and met a mosque ties into it and provides information about the account that's currently connected through it to the browser. So we're gonna do is check to see if it's on the fine. Start with if type off Web three, there's no equal undefined. Well, if it still undefined and we're just gonna set the global name off. What? Three eagle toe? A new instance off the current provider. Fantastic. No. In the event that we cannot find be provided through minimum ask what we'll do is we'll set the provider equal to HDP provider and connected to port 8545 This is about the Copa look like Went three is equal to new Web three and then me Web three dot providers don't hate she P provider. And then in brackets we go hitch p four slash local host 85 45. This just makes him for running an instance, Um, from the command line, the Web browser will look for that and connected. And then finally, in this function, we're gonna return another app dot inet con tract. We're going to write this function as well before we do that. However, if we jump to the top of this, we need to write some aesthetic global fields that we want to be able to use within this object. One of those is a list of contracts that this particular object is managing. We're probably gonna ever have wanted yet, but I just do it just for the sake of completeness and then We'll at also create a very vocal crypto doggies address, which is still the address off the crypto doggies. A smart contract we don't actually have an address for as of yet. So for now, we are just gonna leave it blank. So then, if we jump down below the network three, we now need to write thean it contract function. This is where we're gonna load the Jason 80 i for a contract into the web browser, and we'll explain all that in one sec. So we gotta go. All signs don't get Jason. So he used Jason, and we're gonna load the data and posits, too this function Cool. And then afterwards, we're also going to pretend ap dot find events which we will implement the second. Well, now we didn't get Jason. Basically, this data here refers to in this build folder on the left. This crypt Adobe start, Jason. It contains kind of like a map of all the functions and data types and things that we can interact with for the contract. Likely. So when we go do go to deploy this, we need to make sure that we have a copier that cripple. He start, Jason in the directory. All the root directory off the Web website. It's now within. Get Jason. We're gonna get making const called crypto. Don't. He's artifact, which is equal to the data that we've load from Jason. I mean, they were gonna have at dot contracts, which is referencing this right here dot crypto doggies. And we're gonna set that equal to truffle contract. And then the artifact was basically truffle contract will load in the artifact day and then spit out a nice structure for us to deal with for the contract. And we're gonna store in the crypto doggies map. Next, we're going to sit the provider. We're at dot contracts dot critter doggies dot set from fighter. We're gonna set it even for web three dot current provided. Finally, we're going to return that don't mood doggies, which is the next function. We will be rotting. Final thing I'd also like to add is a bind events. So you just let it here, But we need to put it somewhere. We're gonna place it just in the next field. And this is where we're going to handle the various events. For example, women click the submit button. We're gonna be passing the form data. So we need to define where we're going to. We're gonna do that form data when we get it. So we gotta go to declare from the document dot on submit. We're going to check to see if the thing that submitted was formed dot doggy purchase. Yeah, and if it was, we're gonna pass the data to app dot handle purchase. And that's about where we need to be out right now. In the next video, we're going to write the handle purchase function and will also start to write the loading off the doggy information into a nice structure to then passed to the create. Sorry to pass to the load doggies function. I'll see you in the video. 35. Handle Doggy Purchase: before we move on to loading the doggies from the contract. Let's finish off the handle purchase event that we just previously wrote. Now, we just caught the event, but we haven't dealt with it yet. Don't do that. We're going to create a new function called handle perches. We're gonna posit an event. This is the event that's passed from this document on submit. So I'm gonna go if in doubt, prevent default. And they were gonna get the full input field for the doggy I d. I'm gonna go far, doggy. I d is equal to Parr's and than the event dot target dot elements dot closest. This is basically just find the closest button within the event dot button dashed by. We're gonna get the data field I d. And that should give us the doggy I date there. Next, let's Web three dot dot get accounts, which will get a list of accounts. We're going to pass the error and list of accounts, and then within this function, we're going to check to see if we got an era. And if we do, we're gonna do a constant lug with the earth else we're gonna set far account is equal to accounts zero, which is the default main account for the person who's using the website. Now we're gonna go let contract instance, is equal to at dot contracts dot crypto doggies dot at that just means we wanted to find the contracts address. We're going to find that as hap dot crypto doggies address, which is the one that we defined at the top here, which we haven't quite flood yet. But when we deployed, that's what we put into this field. Next, we're gonna go contract instance dot price off, and we're gonna check the price of a dog I d Then we're gonna go. Then there were passed the price to the next function which will return contract instance dot purchase passing in the doggie Heidi and then the next line, we're gonna possibly from count address as the account that we just saved you. So this is the account that we want to send the purchase from, and we're gonna send the value as process. And this is the price that we just got from the price off. Dougie, I d And finally we're gonna handle Then the result in the past the result to act dot load doggies. And then we're going to catch any error gets and we're gonna pass it out. Console dot Log era message. Oops. Yeah, just consuming. I've got all these lined up fantastic. So effectively, we're just gonna do is going to get event. We're gonna get the doggy i d. From the button that we clicked. Gonna get the first account in the person's met a mask. We're going to get the contract. Instance We're gonna at the price of the doggie with click. Don't just to confirm that the price and why isn't correct Because we don't wanna trust local job script. We want to make sure that the of the actual price the dough from the seven from the contract is the one that we're using Its a minute. And then what we're doing is we are paying on purchasing without, which will trigger the minimalist purchase they need to come up, and then we're going to reload the doggies when we have made that purchase. That just now, in the next video, what we're gonna do is we're gonna write this lewd doggies function which will basically reload the dogs in the U. S. So I'll see you there 36. Load Doggies from Contract Function: All right, We're in the homestretch. We have two more functions we need to run, which are the Lord doggies function and the get doggy detail function. So we're just gonna write stuffs for those now is we Don't forget, we got load doggies. And when you function stub full, get doggy details which will take a doggie i d And a local address which I'll explain include sick Let's do the load doggies function first when this we're gonna need to do the web three heath dot Get accounts again. So much more use before blow. Let me get function her and the accounts. And as we did before, we're gonna try to see if the error he has No no Then we console, don't log. Actually, little comfortable error An error kun's that we will print the era and then we'll check to see else if kill stop length is equal to zero i e. They don't have any accounts up in mid a mosque. Then we'll do console. Don't look user is not logged into not a mosque. And finally, this is handling the case that we have indeed got the accounts. Then we'll actually removal the cards in a row and explain why we do this later. It's best we just cleaning up. If someone happens to have a new doggy come through before the pages refreshed, all the cards will actually stack up and you'll get doubles. So we got carved up room Children, stop! Remove Already. Next, we are going to off the excitement. And after this get accounts We're gonna get running the next pizza logic, which is getting the address off the default account. And then again, you're going to to find the contract. Instance she's going toe app taught contracts dot crypto doggies dot at and then we specify the contracts address. So we go to dot crypt Adonis address. We're going to return the total supply, which is equal to the contract instance dot total supply. Then we handle supply and will do so in the following function. We're gonna get four, but I is equal to zero. I is less than supply, and I lost plus in right over the total supply with each doggy. I d gonna app dot get doggy details on a party and I which is the doggy I did. And he address off the default account, then look it. We still need to handle any exceptions. Yes, We're gonna catch era. Think will past the era to a consul. Don't log air dot Message close with these brackets closed with that and that function is now done. Let's jump down to get doggy details. Now, this is going to be the details that we're returning If you drop by Grodas contractor, look under crypto doggies When the took in created event decide we'll start another one. Um, we are going to get token. So when they get token function is cold. We are going to be getting the took a name, DNA price next process owner. So it's Trump over here. And let's handle getting that information so they let contract instance equal to app dot contracts dot crypto doggies taught Pat. I can gonna find the address. They will return contract instance dot Get token calling that function. We're gonna pass the doggy I d then, doggy, we'll handle it. We're gonna go ahead and put in her. So we did this. Let's credit new J's on object. Okay, Dougie. Jason is equal to way to go, Doggy, i d the vessel Space way to go, doggy, I d Because that's what we want to set this value too. And we'll go doggy name. Give us a lift to space. So good doggy name. And we're gonna set this to the first value that we get back. Go get this order. We're going to get the took in name as the first item back. Some very doggy index zero because, technically, this is an array of elements. So what were you doing next? We're gonna get the DNA. DNA is a black five. It's looking good, doggy, Do you know? And they will go Dokey one for the next element next week. Don't depress Toby Price. And now we can't just load that know me directly because we're actually dealing with the way value now into co convert from way to either. And to do that, we can go with three dot from way then positive doggie. You next syrah index to, I should say, and then we'll convert it to number. Cool. And we'll do the same thing with the doggy next press, which is gonna be equal to Web three dot from White Dokey in days. Three duck to number and slightly. We are getting the owner's address so you can go. Oh, yeah, Dress doggy. And the X element is four. And that is our Jason Decca structure. So now let's pass this Jason Kato over into the create doggy function to credit card. So first, we're gonna check to see if the local owner address is equal to out dress. Because we want to make sure that we flag that button to disable. If we own the dog that we look so going, Ducky, Jason, don't on your dress. We'll make sure that's not equal to the local address. And if it isn't, then we get load, little doggie, and we have awesome the variety variables. Get your doggy, Jason dot Tookie my i d doggy Jason dot Tookie name talking. Who's Jason dots? Don't you d and I, Toby? Sure. I saw. I thought Doki price on Dougie. Jason Dots, Cokie. And next. Oops. Express Ducky Jason adults owner address. And finally, we're going to set the local address. Or in if you go down to a function, have looked locally owned, we're gonna set to false because the owner address does not equal a local address. Who Now we're gonna have an else statement for this if and stable Selves a love typing. We are just gonna copy this. What? Dougie into the else statement and basically has changed this to true. I know it's a bit Bobo's, but at least you know exactly what's going on. It's very easy to explain. Cool. So then, finally, we do need to handle mm money to handle a get. I feel like we're one set of brackets off, so believe we're supposed to have a catch. Yep. We're gonna catch the error, and then we will come. Soul doctor Logue. Their adult message wasn't and that should be pretty much all the jobs we should need to ride. So the next video, we'll also clean up this old options that we no longer need. We might also need to just confirming, but I'm pretty sure that's everything we need. So you only always should need to do now is deploy out, contract on to Boston, test it and then we're gonna add the crypto doggies address into this field, and we should be good to go. So the next video we'll do that 37. Deploy CryptoDoggies to Ropsten Testnet: we're now ready to deploy a contract onto the Ethereum Blockchain. We're gonna be using Ripston Test that However, I was able to find a small actually quite a large bug in our contract code that made it so that when you purchased a doggy, the price wouldn't be updated. Uh, now, to fix this problem, if you go into the kryptonians dot soul contract, go to line 1 59 Need to add the following in order to update the price off token or the doggy after a purchase is put through. So I need to go token I d to Price and then took in I t is equal to next price. Well, and they will positive the token I d That's pretty much all you need to do. What that will do is little update the token price after a purchase goes through. So now that we've completed, the contract we're gonna do is we're going to compile it. So we're gonna do truffle compile. What this will do is we'll generate the build directory within this field directory. Gonna take a copy of the scripted doggies. Don't Jason, and we're gonna put it into the root folder off our website, which in this guys is the source director. Delete any existing crypto doggies that sold files that's in that based in the new one. Next time, with a small change, I wanted to make you I to make it display better on small screens. And to do this you can open up index to hate email and change line 68 to be Cole Excel three four. And since this year, hopefully making scale better. There's one other small change online nightfall where we don't have any context on the buy button. So we want to add the word by do this by just adding the word by eating the button field. Next, what we're gonna do, you gonna deploy this contract onto the Blockchain? I'm gonna use remix again. So if you bring up remix the ethereum, the Vogue what? We're gonna do it with a paste in that contract code and update the crypt interviews that soul with the new updated contract code It's a copy were arrested in. Make sure that this information on make sure about the four different contracts loaded in and available within the browser closed down Some of these next step is going to pay to grab some ethereum from the rough Broxton faucet. You can do this if you haven't already done. This is we? We went over before, but we'll do it one more time. You gotta Robson or faucet Robson be we call 3001. You can actually take your account's address. Pasted it is field and then click. Send me one test. Either That can take some time. Clearly output. Now that we're looked in with their account, we can see how well is available. We're gonna change his gas limit to this value here. So by default, it should have bean three million. But we're gonna change the full 30.7. She's gonna make the transaction great Thrill Foster. Oops for Chemical. Next, we're gonna select the crypt adobes as the contract we'd like to deploy. We're gonna hit, create. So tell us it'll cost us about $4 in 92. That's fine. We got it for free and we hit Deploy. We need to wait for this to go through. We can click it. Viewed status. I need to wait for this transaction to complete. We're waiting for this. We can actually check our Web servers ready to go. So jump back over into your idea and eventually you'll be putting your address into that. Now we don't have one. Find NPM Wrong Dev. This should have happened. Browser. We'll drag browser across and look out the inspector menu now, as it's already warning us. Invalid dress. That's fine. We haven't with the addressing. That's perfect. We're ready to go. Let's jump back over and to remix to see how it's going. Looks like our transaction will successful. Now, if you click, this unit will take us to where our contractors we can take Copy off the address back into V s code. I want the address into the crypt, a doggies dress field refresh and bring up a Web browser you can see when only getting there is. That's untested. Next, we're gonna jump back into remix and we're gonna generate alphas. Dougie, You know, just to do that, we're gonna take out contract address and put it into this load contract from address field hit load missile actually lawyered all the functions relating to our contract. We can now interact with it straight out of remains. So what? I'm gonna do is we're gonna create it. Took it on a credit token or a dhobi in this case with a name. Kate. Wait. Great Tucker. It will bring up a confirmation on whether or not we want to do this. It will cost us some fees, you know, to gas the transaction. Let's admit and that transaction should be added. You can see it's pending down the bottom. Here. We can also have not met a mask. We can view the states here clicking on the transaction. Time for this complete can vary a little bit, but eventually we should see it go through. You can see that the great took and function was called with the name. Then you can see the various fields that were included. So obviously this field here would have bean if that would have been the name field goaded . And this for President de in the press. Take a little bit. We got it. Looks like transaction has completed. We could have in the details field in remains. Scroll down. We should see it yet. So Katie was created An index zero with that DNA at that base cost. And with that owner so we can jump back over and refresh. This transaction probably will come up cool. So the talking is be transferred from address from zero to l address. Let's jump back to a website. Wait fresh and when I look well, dodgy has bean loaded. You know, it's indirect with this a little bit. Let's try buying out. Let's hit by. No, I actually loved into a different county. The owner. So what do you purchase that and you can see for your transaction should review some stats . More importantly, we should be out of you that I sent a value of 0.1 e tha to this transaction. I have specified under the purchase function that I'd like to buy Token zero. This field represents the dignity fresh this for seven. Well, waiting to go through. We don't back over to remix. It's actually check some of the other functions we have available. For example, let's go get old targets. No, you can see here. We've actually returned a list of the tokens. We actually go and return just one token there. So if we punch in zero, we could get the information for token zero. You get Katie tonight the price and the next press along with the owner. It's jump back over the front end and refresh the page. And what we should say is we now have the new price that's been added. We have the next press, and all by button has been disabled because we already owned this. Now, if we actually swap over to, for example, another account that I own and they were first page, you should see that the new press and kitty at the Doggie is available for purchase in the owner has also been filled into this field. If we click the field, we'll take us to the owners page, and that's about it. Graduations and finishing first death, Where you can take from here, is if you can get this step that uploaded onto a service similar, then you're able to interact with it and send it up, thrust the world. The other option is that you deploy the contract on two main net, and I'm gonna go ever doing that in the next video 38. [Optional] Deploying to Mainnet: Welcome to the final video. You know, crypto keys. Smart contract tutorial. In this video, we're gonna deploy a smart contract onto the main net for the Ethereum Blockchain start with. We're gonna remove all the imports from our crypto doggies start soul contract. We're gonna replace them with the actual code from the other contract files. So we're going to access control stuff with and copy all of this. Good. Yeah, except for the pregnant talk. Because we already got that to find in spell. Then we'll do the same with e L c 7 21 Took it. More places just below access control. Well, finally will take the safe mats library because this is a library does not need to go before the other code. Sweet, because right at the end of the file and testing close up that fun. No, I will do it will bring over remix as we'll be using this to put contract or paste in the code that we've got. We'll make sure we've only got one file within the browser. Then we'll make sure that I'll inject environment is 13 Make sure that it's out. Count that selected Leave the gas limit at its default. Also, make sure that you are logged in two men. Net. It's been a mosque. You'll also need some ethereum and over to guess this transaction. The process may very, but I've noticed that it costs roughly between 10 to 20 U. S. Dollars to deploy a contract. So this might be one you just follow along with me on. Then we click, create and bring up a box just wanting us that we're about to write this data. It's the theory and book. Great to talk. We should get a gas price estimate right now. It's it. It's gassing us at about 9.5 away. Scroll down to the bottom for happy with that. Will he confirm this will bring about transaction window warning us that we're about to spend roughly 22.6 years still this onto planes contract and will it submit? If we are happy, we can click their transaction books to bring up the details. Don't take a sec first, pop up. What? We're waiting for that we'll go back over the V s code. We're jumping tussles, hoping about Dobi said Js and prepare to replace his contract dress in the previous video, when I demonstrated us clicking on the ethos Get address. The reason why it wasn't going to be correct account because under here well, we define either skin because it was a Rob Stone address and we didn't prefix with Roxton. We were just going to a random address with No, don't be in it because it is going to be a net. We no longer need that Boston reference. But if you were trying to get your version working before and having problems, it was because of that. Let's check back in this transaction jelly. It's estimated it'll take about four minutes. We can see the input data. It's about two brought fantastic . It looks like our contracts being deployed Head back over to the skin. Just confirm we can't confirm that our contract has been deployed to this address. Let's make a copy of the address. You're that guy with the doggies, Js and replacements address here also, what we hear jumping back over into remix, we're gonna take a copy of all the code that was in this browser. Scripted argues that soul and then underneath the skin into contract code we're gonna click , verify and publish. I'm gonna put in the name of our contract. In this case, it's crypto doggies. Minutes left, open Pilot. You know, Casey, it was 14 point zero point full 18. Both We used Don't 19 within the Slippy compiler four remix and they will turn up religion off. We'll pay, single contract could scroll down, They're fine published and hopefully this works. This time, though, I have had problems in the past. Fantastic. That was successful. All this means is that we can view the rule source file and also read smart contract and interact with it through either scan that if we jump back in to eat this, get into remix, what we'll do is we'll generate Hey, took him simple. Go to me. Great took and field Put in the name off. Our doggie in this case will make our dog's name just great. Okay, it's warning us. The gas prices about 20 that does seem a little high, wants it at the 15 and hope that it goes through waiting for him warning us little costs about a dollar 88 To upload this new doggy hits event will be the transaction. If that doesn't load, just jump back over to your contract. Click transactions. Refresh the page. Doesn't think the network's slightly slower to know. We will wait for the transaction in ratings. Fantastic ness looked like it looks like that transaction has gone through. It did take a little while for it to go through there. We can expand the details view that this transaction did in fact encode the data just and in the logs. We can see that Index era. Just decide this DNA, this base cost and that is the address off the owner. So if you never get to the crypto doggy still stole your old, you'll view the working small contract on men. Just think of them. We are Fact on made net and this is the dress told that you just created, so could the ethos can address and should take us to this model contract. You can see that the you'll see 20 because currently the scantily sports UFC 20 but we can still recognize the name Oh, out token is being crypto doggies, CDT. As we specified, we can see token ballots as well are one CDT broken, which is blows to the contract. Basically, if we purchase that doggy will on that contract, Thanks again for joining me on this course. It's been a lot of fun. I find a few exit things along the way. Just teaching it. If you have any questions, don't hesitate to read you. If you have any problems. The course let me know. I love to hear about the projects are working on to feel free to hit me up on Twitter at Nathan Glover, a US, and also check out the repository crypto doggies. So the completed project is up when I get help. Um, get to me basically some examples with the finished code, if you having any problems and, like I said, contracting any problems cash around.