Learn Ethereum Programming in 1 Hour: Solidity, ERC-20 & Uniswap

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so welcome back everybody today i've got a brand new coding tutorial video for you i'm going to give you an introduction to blockchain development with ethereum and the solidity programming language these are some of the most in-demand skills in tech right now and i'm going to show you why in this video step by step because i'm going to show you how to launch a live project out there into the wild on a blockchain in a matter of minutes all from your web browser so whether you're just checking out blockchain for the first time as a brand new coder with no experience or you've got some experience in software development or blockchain already then this video is for you because we're going to use the latest versions of all the tools and technologies and you're going to pick up some brand new tricks along the way so before we get into that you know if you're around here hey i'm gregory and on this channel i turn you into a blockchain master so if that's something you're interested in then smash that like button down below if youtube algorithm and subscribe to this channel and if you want to become a blockchain master step by step start finish and head on over to the dap university.com for slash bootcamp to get started today all right so let's go ahead and jump into this what are we gonna actually create today well what i'm gonna show you to do is actually launch your own cryptocurrency live on top of the ethereum blockchain how to hold it inside your ethereum wallet like this but then we're actually going to take the next step and we're going to put it on a cryptocurrency exchange so in particular we're going to use the decentralized cryptocurrency exchange uni swap this is one of the most powerful applications on top of the ethereum platform today it's one of the most used decentralized applications and one of the cool things about uni swap is you can list your token permissionlessly okay you don't need anybody's you don't have to ask anybody if you can list it as long as you are able to access the blockchain directly you can add your token uni swap and start trading it so you can see lots of different cryptocurrency lots of cryptocurrencies on top of ethereum you can see lots of different cryptocurrencies on a website like coingecko.com uh that that work like this basically just go any of these coins and look at you know the d5 coins for example a lot of these are uh ethereum-based cryptocurrencies or erc 20 tokens that run on top of the blockchain because that's one of the beautiful things about ethereum is it lets you create your own cryptocurrency without creating your own blockchain with smart contracts that's exactly what we're gonna do today and we're gonna show you how to create it and how to put it on an exchange like uni swap and another big benefit of doing this way with solidity smart contracts is once you've created it you can put it in multiple different places so you can do it on ethereum you can do it on uh you can do it on binance smart chain if you want to trade on pancake swap you can do it on polygon matic you can put on optimism layer two you can list it on sushi swap balancer you know whatever alright so who is this video for well the short answer it's for everybody so anybody who you know already has programming experience and wants to see how this specific skill works from blockchain this is going to be a crash course and how to actually you know launch something quickly on the blockchain with relatively little knowledge okay that's the whole goal is so that you can see how to do something pretty amazing on top of ethereum it's incredibly powerful that's you know potentially worth a lot of money and you know to get you started down that process okay so if you have coding experience you definitely can follow this video very fast if you're brand new and you have zero uh coding experience that's okay too because we're gonna learn this by doing okay some people ask me all the time like hey if i want to learn block change and i go like learn web development first well my answer is always no you should start with the exact same that you want to learn and this video we're going to be very potent we'll be very focused we're going to work on the solidity programming language only we're going to do everything in our browser so you have to go through all these steps of setting things up in your computer you're going to get a primer that shows you how the blockchain works you get an introduction to the celebrity programming language you'll learn everything as you go and even if you know blockchain already you're still probably going gonna get something out of this video because we're gonna use the latest version of solidity programming language and you'll also pick up some pretty cool tips and tricks along the way okay so here are three main objectives that we're gonna accomplish in this tutorial we're gonna create a cryptocurrency like i said we're gonna store in a wallet and then we're gonna list it on exchange so we're gonna go through these one by one and you're gonna get an introduction to everything you need to know to do this okay all the concepts and all the skills so let's first start off with creating the cryptocurrency itself so let's just kind of reason through this what do you need in order to create a cryptocurrency on top of ethereum like i said one of the most beautiful things about ethereum is you can launch your own cryptocurrency without creating your own blockchain with smart contracts so we're gonna create a smart contract to do that so you're gonna ask yourself okay so what do you need to create a smart contract well you need a programming language and we just need one programming language in this case which is really nice thing about this tutorial like i said you can just do everything in your browser but we're going to use the solidity programming language so this is the primary programming language used for creating smart contracts this is like the most in demand programming language maybe on the face of the planet right now because block change is a hot skill and you know solidity is the most potent skill if you're trying to you know become a blockchain developer the the most critical thing to master okay so the good news is solidity is a pretty um i would say honestly in the grand scheme it's pretty beginner friendly language it reads a lot like uh python you know in javascript and while there's gonna be a lot of effort required to become a true solidity master you can still pick up the basics of the programming image pretty quickly as you'll see in this tutorial but if we're going to create an ethereum token we have to understand like how it's going to work so we need a basic set of guidelines and instructions for how this cryptocurrency should work in the first place okay so the good news is we don't have to reinvent the wheel ethereum actually has a standard for doing this it's called the erc20 token standard and if you go look on a cryptocurrency website like this for checking prices like coingecko and you look at all these defy coins like most of these are erc20 tokens so some really famous cryptocurrencies like uni swap the uni token is an erc20 token chain link is an erc20 token these are just smart contract-based cryptocurrencies that are on top of ethereum that all adhere to this standard so what is the standard well basically it just describes like how the token should work so it determines what functions the smart contract actually has to be compliant with the erc20 standard so it has to have some critical functions like a name every token must have a name like so you see you know this right here that's the uni swap is the token name the uni is the symbol it must have a symbol okay it must have these other functions that uh facilitate the behavior of the token like the transfer function okay this basically lets you send cryptocurrency from you know one account to another um it must implement a transfer from function so this tells you like how the cryptocurrency can be traded on a decentralized exchange without your action on your part i guess is what i'm trying to say and then it also must implement very specific behavior inside these and the last major thing is it must have very specific events okay so events are basically a way to log a certain action on top of the blockchain so like a transfer event is logged anytime a token is sent so basically whatever this function is called it emits this transfer event you're going to see all that as we go along but the really important thing to understand here is this is a a standard that we can adhere to and we don't have to reinvent the wheel so because we don't have to reinvent the wheel uh we can use a library often times to launch your own cryptocurrency really fast that is secure and audited and that's what the open zeppelin library is for okay so they have lots of different um you know contract patterns inside here like if you want to launch uh a cryptocurrency with erc20 tokens you can do it quickly with open zeppelin if you want to create your own non-fungible token or nft maybe crypto collectible you could do it click with open zeppelin but today we're actually going to use a much simpler code that i've prepared ahead of time so that you don't have to reinvent the wheel and you can just create your own erc20 token now you of course could just copy and paste this and you know get up up and running right away but i'm going to show you how to you know walk through some of it step by step we're going to use this complete code solution um you can you can see it's just you know quite a bit of comments in it so probably it's only like you know 30 lines of code in total we can build this out pretty quickly and i'm going to show you how to do it in your browser and you're getting a pretty good primer on how the uh solidity programming language works now you won't be a solidity master after watching this tutorial but that's not what it's for the whole idea is to show you you know how to create something really quickly and get you excited about what you're learning and have plenty of other step-by-step much longer tutorials on this channel that show you how to build full stack applications on top of ethereum but this shows you how you can launch a crypto pretty fast you know put it in your wallet and get it you know it trading on a decentralized cryptocurrency exchange in you know less than an hour all right so now let's go ahead and get started coding so head on over to remix.etherium.org so this is a website where you can create smart contracts with the solidity programming language for ethereum all inside your browser okay so we don't have to set anything up on our computer today all you need uh is to to do everything on this website here okay and you also need an ethereum wallet installed so you need meta mask um so if you don't have this installed just uh look up on google the metamask ethereum wallet okay so this is basically turns your web browser into a blockchain browser and it also lets you hold cryptocurrency inside your wallet like ether for example and you can also add ethereum based tokens which we're going to do later in this tutorial we're going to take the token that we created and actually add to our metamask wallet and you're also going to need this wallet so that you can pay gas fees on top of ethereum because that's how it works anytime you create transactions you deploy a smart contract to the network or anytime you know you trade a token on your new swap or add your you know cryptocurrency token uh that you created to uni swap you have to pay a gas fee to do that and you'll need to sign these transactions with metamask but you'll see all that as we go all right so let's go ahead and get started so inside of remix look over here on the side and you can see that you've got some folders okay so this is just what's called the directory in software development it's just a list of folders uh that has a structure and so you can click on the contracts folder into this directory and this is where we'll actually create the smart contract for the token itself all right so inside of here uh you can just click on this new file button all right this will create a new file and you can just call it uh you know token the capital t token sol that's how it works pretty pretty easy so we're going to create a contract inside if you're called token so that's the convention whenever you're uh writing a smart contract as you do the file name the same name as the contract itself and the convention here is to use a capital t for token as the file name because the contract name is capitalized and then sol is the file extension for solidity smart contracts anytime you see sol that you know that there's a solidity smart contract file inside of there okay so it's pretty easy to get started the first thing we want to do is actually declare the version of the solidity programming language that we're using uh you need to do that at the top of every single file basically this just tells the solidity compiler how to compile it so basically it needs to know what version the programming language you're using because inside of here we're going to create human readable code with solidity but that has to get turned into machine readable code when it gets compiled until you have to tell it the compiler version so we'll see that here in a minute we do like this so progma solidity and then we're going to say um version 0.8.6 i'll actually bump this up so you can see it better so that's how you do it pragma solidity version 0 8.6 and you use a semicolon after every line like this all right and the next thing we do is we just declare the contract so we do that with a contract keyword inside solidity so we say contract and then we do capital t token all right and then we do curly braces and then inside these curly braces is where all the code for the actual smart contract will live okay so this is like a shell that you can think about you know this this is where all the code for the contract goes and then anything on these new lines inside these curly braces is where the the smart contract code will go so every token for ethereum has to have a name okay just like we've seen here these tokens all have names like the uni swap token all right they have symbols etc etc and so what we can do with the first step is actually just create the name for our token so how do we do that well inside the smart contract we can just store it in a variable okay pretty easy just like this so we say string public name and we're just going to call it my token so let me break this down a little more so this is a variable inside the smart contract but is a special kind of variable called a state variable all right so there are different types of variables inside solidity we'll see that more here in a minute but basically this um variable it just stores dynamic information in this case it's going to be static because we're just assigning it here once but basically this is where the name of the token goes uh it's a string type which basically means uh this data type right here so a string is anything that's contained inside these quotation marks so that's different from like uh you know an integer which might be one one's an integer but you know the the phrase my token inside quotation marks is a you know a string so there are different data types that solidity a string is an example an unsigned integer you know uint is an example there's struct there's all kinds of stuff but this is a string which is important to understand and the last thing is it's public which basically means that we can read this variable outside the smart contract so when you put this token inside your cryptocurrency wallet it needs to be able to read the variable called name and we declare it public so that your cryptocurrency wallet can do that okay and also other exchanges etc etc right so let's go ahead and go through the next step which is actually just compiling the contract and testing it out so you can see how this name variable works this is gonna be a test to make sure that everything's set up properly is working we'll continue to iterate on this smart contract uh here in a minute but uh you can just go in your in your browser here over to this button right here this is deploying my transactions okay so if you don't see this you might have to go down to the plugins tab and search for deploy and run transactions okay so if i'm ever doing a step over here and you don't see the link on the sidebar just click the plugins uh button here and you can search for whatever the plugin name that i'm looking that i'm using is okay so here it's deployment run transactions you can see the plugin name at the top so if you don't see it you just search for it there so anyway so what we're going to do is go ahead and compile the smart contract down and put it on a a test blockchain so like i said a second ago whenever you deploy a smart contract you have to compile it so what does that mean well here we have human readable code this basically means that you or i can read this it reads somewhat like english right there's actually english words in here but a computer doesn't understand this code so whenever we want a computer understand it we compile it we take it down and convert it from this human readable code into machine readable code called bytecode that's actually going to get run on the blockchain and it gets run on top of the ethereum virtual machine that computer process that interprets smart contract code and actually runs like on an ethereum node so anytime you're interacting blockchain of course it's a peer-to-peer network of nodes that all talk to one another and each one of those nodes that's executing smart contracts transactions is using the ethereum virtual machine so we have to take this code and compile it down into a way that the evm that's a short for a theme virtual machine understands we can actually before we deploy run transactions we go this compilation step here so you can see this this is little t icon with the refresh wheel we can choose a compiler type so basically we want to go up to 0.8.6 all right that's the latest version that's the version we have here in our file and we click compile and it works so we have a warning here it says spdx license identifier not provided in source file so you're supposed to supposed to provide the license at the top so you can do that like this all right that's actually contained in the source code that i'll put a link to the description below i've got the final code solution like you could just copy and paste this whole thing and skip this step if you wanted to but i'm just going to give you a quick introduction to how this works if you're brand new to coding and just and want to see this okay we do that click compile it works no more warnings and now we can actually uh deploy it so for this step we're not really going to use metamask okay we're just going to do everything inside of remix so remix has a test blockchain built into it and you know some test accounts you see the environment right we're just going to use this javascript virtual machine so it's a javascript version of ethereum that's just running in your browser okay it's not a real blockchain um you're not using metamask you can see that you have all these accounts here with a hundred fake ether you can act as any one of these accounts but yeah i'm sure i did this quickly so that you can you know see how the token development life cycle works so let's just click the token as the contract we're going to deploy click deploy and then boom there you go you can see it listed in your sidebar here you can see the address for the token right here so the address is the location of the token on the blockchain now it's in memory it's what it's saying here basically it just lives in your browser it's not actually on a blockchain yet but now you can see the the functions that the token has okay so you can see the name function right here and you can click on this and you can see it's returns a string and it's my token all right so that's the that's the variable that we set here right so you could change this you could call it my great token and change it and watch it watch your changes happen real time so if you're going to change the code then you have to go over here and you know recompile it all right and then deploy it again all right and then you'll see a new copy of your token uh listed here and you can read it and you can see the variable image change so that's one important thing to understand about ethereum smart contracts is in and of themselves they can't really change so if you make a code change then you have to redeploy a copy of your smart contract to the network get to go through the compilation step again you have to deploy it again because they're immutable they can't change you're supposed to be able to just trust that it stays the same now there are smart contracts that can change live on the network but that's that's a little bit of a different story for different day but from your perspective as a beginner just going through this uh the actual contracts that you'll write these less sophisticated ones don't don't really change so anytime you make changes you have to go through that process all right so next i'm just going to go ahead and paste in a few more settings for the token they're going to show you how it works so basically we're going to add some more variables we're going to add a variable for the symbol okay so this is uh the symbol that you'll see on a cryptocurrency exchange like you know the uni swap token the symbol is uni uh so we're just going to call it uh you know mtk will be our symbol um the next thing is you you need to set the decimal places for the token so what does this mean you think it does decimals like this way so think about us dollar currency so dollars are represented like this if you if you have um you know one dollar you only have a hundred pennies that make up a dollar you can't really subdivide a dollar any further than that at the actual currency level okay so basically a dollar has two decimal places after it because 100 pennies make up a dollar and there's nothing smaller than a penny so with with tokens basically you you want to determine how many zeros are after the decimal place that's the decimal's variable is so basically uh with tokens the convention is to do 18 decimal places because that's how ether works so ether is the native cryptocurrency the ethereum blockchain it works different from tokens but ether is divisible by 18 decimal places and so that's the convention for tokens so basically your token's gonna have one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seven eighteen zeroes after the decimal place okay that's what 18 is and then lastly we want to do a total supply of 1 million all right so how we do that is basically i say 1 million so 1 1 2 3 4 5 6 but then you have to do 18 decimal places after it to actually represent the total amount of tokens because it has it has 18 zeros after the decimal place one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifty sixteen seven eighteen of course this is not dollars uh so we put that here all right so the reason we do that is because your token solidity does not support decimals all right every time you store numbers on the blockchain you have to do it uh with integers okay so that's what this data type here is uh a uint so a unit stands for unsigned integer so it's an integer that does not have a sign it's unsigned so a sign would be negative so it can't be negative so a signed integer might be negative you know 1 million but an unsigned energy would just be like a million with no no sign and of course these variables are also public all right so now um that's how we would do all the configuration for the tokens we can just go through the you know uh compile and deploy all right you can see it here decimals name symbol total supply and total supplies is just the actual amount of cryptocurrency that's you know available in the entire uh for for the entire cryptocurrency game all right so next i'm going to show you how to actually uh make these settings dynamic so what do i know that like how you can customize them however you want to so that it's not just you know hard coded into the contract so i'm going to introduce you something called the constructor function for solidity so this is a function so if you're new to programming basically a function is just uh like a command that you can run inside the smart contract that actually does something and then you can put a bunch of information or steps inside the function that get executed whenever it's called so you call a function that you know writes some information and you do steps inside of it so we can use a special function called the constructor function inside solidity and what this does is actually execute some code whenever the smart contract is created or put on the blockchain itself and we can pass some arguments in this function these special variables right here like this we can just tell it what the name is going to be what the symbol is going to be what the decimals and what the total supply are going to be whenever we do that we can take these local variables that we pass in all right these name you know symbol decimals and we can assign them to the state variables uh that are declared here inside our smart contract so instead of uh you know writing the name here we can just you know pass it into the constructor function where we cut the contract same thing for symbol we can just you know write that way you can take out the decimals and total supply and we can set all this stuff whenever the contract is created so that's what the constructor function does and that's how we can do right now so i'll just show you how to do it uh go to compile all right then go to deploy and then now you can see this deploy has um let me just kill these first this deploy has a drop down menu click the carrot and you see the name is you know my token symbol mtk decimal is 18 and then one million one and then one two three four five six and then one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seven eighteen all right and then click transact and there you go boom token decimals name symbol and total supply perfect so now i want to show you how uh tokens actually track people's balances so what do i mean by that well the smart contract one of the most important things that it does keeps track of who owns how many tokens so if you were to look at like uh you know this uni swap token for example you click on it you can look at the actual contract itself let's just look at an ether scan so the etherscan is a website where you can inspect all the contracts and transactions on top of ethereum and if you look at the actual swap token itself uh let's just find it you can look at the holders and you can see like you know some of the top addresses hold like 86 million uni tokens all right these are these are uh contracts but this one's not a contract so 24 million tokens about so how does the cryptocurrency know that this particular account holds 24 million tokens well it does it with something special inside the code we have something called a mapping okay so what is a mapping basically it's um it's a mapping that shows you it keeps track of it lets you store information based on key values what i mean by that basically it takes a key uh which is sort of like an id for a database in this case the key is an address it says mapping address right here all right you pass in an address and it returns a value so you can put in an address for a token holder in this case and it returns an unsigned integer in this uint 256 that corresponds to the number of tokens that that person holds and now it's important to understand these uh keys or these addresses are unique so only one address will ever you know it's deterministic if i pass in an address it's always going to return the same value so in this case basically if i put this person's address in that we saw right here it's going to return the same value every time so key value you know key value all right so we can see that inside here so we can we can give this mapping a name we can call it balance of and we can call it public all right so we can access it outside of the smart contract and solidity is actually going to give us a special function for free just like we did with these variables over here that will actually let us query the balance of a particular account whenever we apply this public label this mapping will basically be a variable would be public and it'll have this mapping structure associated with it okay and that's how we keep track of who owns how many tokens now what we're gonna do is actually assign all the tokens created uh whenever we deploy the smart contract to the person who created it or the deployer in this case it's gonna be our ethereum account that we're deploying to the blockchain with this one right here okay so we can do that like this basically whenever the smart contract gets put on the blockchain we can just say balance of message sender equals total supply so what does that mean well basically you take the balance of mapping here and this step in the function actually adds a new value based on this key so we could just say you know balance of we could hard code our address in here but instead we're going to use a special variable inside solidity called message sender so msg.sender this is a global variable and it has a special sender value that corresponds to the person who's calling the function all right in this case the constructor function is being called by the person deploying the smart contract so what we're saying here is the balance of the person who's deploying the smart contract basically assign all the tokens to their account so we pass in the total supply here we say take the total supply and assign it to this person the person who's deploying the contract so whenever we create the tokens we will basically own all of them but whenever we do that we can you know of course supply liquidity on uni swap and let other people start buying them just like you know an initial dex offering okay that's that's how that works so we can we can see this in real time we go to compile and then we can uh click deploy well first of all we need to kill this we add some settings here name know my token symbol mtk decimals 18 total supply one one two three four five six and then eighteen one two three four five six seven eight nine ten eleven thirty four two seven eighteen click transact and now we can paste in the balance of the account up here basically just copy it paste it inside of here all right and then click call and there you go you can see all the tokens have been assigned to us all right so now what i want to do is actually show you how to code the transfer function so what does that mean well basically this mapping is the balance of this tells us how many tokens each person has but now it's actually code out the behavior that lets people send tokens from one account to another okay so that's what this transfer function is called so we can just say function all right transfer and basically we can implement all the code inside of here that will perform each step that takes tokens out of somebody's account and puts it in somebody else's account okay so if we're gonna do this we need two pieces of information we need to address who it's going to so we say address two so that's the variable and argument that we pass into the function we need to know how much cryptocurrency that they're sending so we can say a value and that's the data type of uint256 all right and then we also want this uh variable to be external and we want to return a boolean value because it's part of the erc20 spec so we just say external returns a boolean type of success variable name okay so inside of here all we really have to do um is essentially move tokens from one account to another so we can just do it like this we can just query the balance of the account that we're debiting tokens from we say balance of all right and then we say uh you know from so basically from will be the account who's sending it basically in this case it's going to be message sender like we saw a second ago all right and then we'll say equals balance of all right from and then we'll take away the value all right so basically this value that's being passed in we're going to debit it from this account and then we're going to credit it to the other account to all right boom it's really that easy like that's the core of the transfer function is we say take tokens out of my account the person who's calling this function and then that's how you do it take them out and then add them to the other person's account who were passing in here this you know two right here okay so that's really all you need for the core functionality the transfer function now it becomes a little more sophisticated than that because the erc20 standard requires us to actually log events every time this is created or every time a transfer event happens so we're going to create something called an event called a transfer event like this so below this mapping we're going to paste this in uh this is how you declare a transfer event so you say event transfer uh pass in the address index you know here's the here's the from account it's coming from and then here's the address it's going to and here's the value that's how you define an event with the event keyword and you give it the name and then you pass in the arguments for the event okay and then finally you can just emit the event inside of here and just say say emit transfer and then say you know from to and then value okay and so the last thing we want to do is actually add some conditions to this function to make sure that it works like we intended to and actually has some safeguards around it so basically what we want to do is make sure that the person transferring tokens actually has tokens in their account for they can before they can do that because you don't want people just sending tokens that they don't have right so uh solidity has something called the require function and anything we pass inside of here if it evaluates a true the function can continue execution but if it evaluates to false then it'll just stop it'll just revert and we won't actually be able to do this stuff so inside this require function we want to make sure that the person has enough tokens in their account to do this so basically we just say require balance of message sender is greater than or equal to the value that's getting passed in so basically we just want to say like hey do you have enough tokens in your account before you try to do this right so that's how it works all right the last thing we want to do is actually return true here because per the er20 c20 spec we need to return a boolean variable of success and if this function works then we need to just return true all right so now we can do is actually see this in real time we can just kill this we can go to the compiler click compile all right actually we have a little problem here let me just fix this basically we need to change this from um sorry to um msu.sender and then also this from here to that's message.center we'll change it back to from here in a minute you'll see how it works cloud now works and you can go here and you can click uh contract token click deploy put in the information my token you know assemble them decay decimals 18 2 3 4 5 6 then 18 one two three four five six seven and nine until electro thirty percent seven eighteen click transact and now we can actually uh execute the transfer function by going up to the top and clicking on the accounts find the second account and clicking copying click copy all right and then switch back to the first account but then you want to take the second account and paste it here in this transfer function click to click the drop down and then paste in the to account paste it in here and then put in some amount of tokens i just put in 100 tokens so 100 followed by 18 decimal places click transact and then there you go so now we can query the balance of that same account we sent the tokens to and now you should see the account balance here then you can also look at the balance from the first account in the list and then add it to the balance of let me just do this real quick on you know paste it in here query it and click call and you can see that it's gone down so we successfully implemented the transfer uh logic so that's a lot of the major functionality for the erc20 token really what i want to show you here is how to work with variables how to work with mappings how to work with events how to work with constructor how to work with functions the next two things i'm going to do here is i'm going to finish off this smart contract with some faster kind of copy and paste coding here because i don't want to spend all day just building out this token there's only a little bit left to tell you the truth but i wanted to show you how to you know use each part of this token so what we're going to do is actually just go ahead and paste in the final code solution for the token and explain how the other parts work okay so i'm just literally going to go to the github here and then copy it and then put in the rest here if you want a full tutorial on how to code a ersc20 token step by step uh we've got some other tutorials on this channel of course do that also in the blockchain bootcamp with um you know an entire truffle project with tests and everything but now what we can see is we have the entire token with code comments and everything we have the variables up top uh we have an address for the balance okay we have the transfer function that we saw here we have the constructor like we saw here here's the transfer function but it's actually been broken out into a new function so you can see it here so why is that well the next function is for is called transfer from so what does that do well for erc20 tokens you know whenever we're calling the transfer function basically we're spending tokens ourselves so if you're in your wallet and you send a token around yourself you're calling the transfer function but if you list a token on an exchange you know your tokens get sold for you by the actual exchange itself then it uses the transfer from function so basically this is saying who's the account it's coming from and who's it going to and you can see it works basically just like the transfer function because we can see that it's actually using the internals of the transfer function right here so i've taken it out and put in its own function up here and you can see it's reused right with transfer and it's also used inside this transfer from function so the last thing is um whenever you do transfer from an app needs permission to do that and so that's that's what this approve function does so approve basically says i'm going to let a certain account spin my cryptocurrency for me so you can specify what account that is that's that's the spender address here and then there's the value which is the amount of cryptocurrency that you're letting them spend so if you go swap a token on uni swap you know for example you'll go up here you'll say i want to swap you know some token let's say the ave token for eth you're going to have two steps you're going to approve the token so that uniswap can swap it for you and then you're going to have to the actual swap because whenever you do this swap unity swap takes the tokens out of your wallet and does the exchange for you and so it uses this transfer from function here in that process but the first step in the process is you approving the tokens for them to do that so that's why you put in the spender in this case with the uni swap address and the value be the amount of tokens that they want to swap for you so what this function does um is it adds a uni swap to your list of approvals or your allowance so you can see this allowance mapping inside of here this basically keeps track of your account and then all of the addresses that are allowed to spend tokens on your behalf and then the amount and then whenever you approve tokens uh it has to emit an approval event just like the uh transfer event that's the complete token code so we can just you know check that all this works again the final code solutions in that github repo then i'll link to down below you can click compile compile token still works you can deploy it to a test blockchain you can you know do the settings you can call whatever you want to my token mtk 18 decimals then we can do a million tokens one two three four five six then one two three four five six seven eight nine ten eleven twelve thirteen forty fifteen sixty seven eighteen click transact and it all still works all right so now we create the cryptocurrency let's actually launch it let's put it on a real blockchain and list it on a decentralized exchange so that other people can buy it um we're going to design a test network okay so there's lots of reasons so basically ethereum supports multiple environments it supports the main ethereum network that you might know and use today if you're actually using uni swap for real and the steps i'm about to show you will work on the ethereum main net for sure uh but we're gonna use a test network so this is a different environment uh where basically you can you know test your applications out you don't have to risk any real money uh so we're gonna use ether on the test network but it's just fake ether it's not actually worth anything in the real world and then also if you're worried about like you know launching a cryptocurrency out in the world and then like you know doing something illegal then i don't think you have anything to worry about by doing it on a test network because you're not you're not doing anything with real money okay so that's the whole point here we're gonna use test network for those reasons so we're gonna use something called the kovan test network so inside metamask click your network selector at the top and click on kovan all right covant test network and now in order to do this we need some ether in our wallet to pay for gas fees to list the token on our uni swap and all that type of stuff so we can get some ether for free by going to link faucet here see this in your uh documentation in the instructions here so you can copy your address you can paste it in here you know click you're not a robot and then send send me test eth all right so whenever you do this you should see it pop up in your metamask here so boom there we go got point one eth and so now we can actually put the cryptocurrency live on the blockchain so we'll go back to uh remix here we've already you know compiled the contract uh we can go to deployment step all right and uh here's where we're going to actually select the cobon test network so instead of doing this javascript virtual machine we're going to select uh injected web3 which is going to be our metamask account here all right you can see it you might have to connect your meta mask here it might ask you to connect but i've already done it and then so we can see our account so what we're going to do is deploy the token to the network and we have to pay gas fees in order to do this so you're going to see a meta mask confirmation pop up because whenever you put a smart contract in the blockchain you have to pay a gas fee that's denominated in ether okay so basically uh you're creating a transaction you're changing the blockchain state and anytime you put new information the blockchain you're essentially writing new information to it and you have to pay to do that so that that prevents spam on the network and so you have to pay let's click uh i'll see your deploy kovan fill out your sim your information my token mtk 18 decimals total supply click transact and then he'll see your see your confirmation pop up you'll sign it click confirm you'll see the creation tokens pending and there you go it worked you can see the contract address here click click this and you can also uh click on debug and you can see i can't remember ceremix doesn't actually put a link here but you can go to your browser here you go to kovan.etherskin.io all right i'll do it off screen and you can see the blockchain explorer for the actual cobon test network this is kovan.etherscanio you can paste in your uh contract address here and then boom there we go there's the contract that we created you can see the transaction hash it was created a few few seconds ago you actually click on the contract you can do verify and publish you can click compiler type select a single file uh 0.8.6 you can just do no license if you want to or any lessons you want to you can hit the contract code go from remix copy it go to kovan uh enter the contract source code and then on that robot click verify and publish and let's see here if it works this might take a second and then boom there we go so now you can actually see the contract was verified so this is pretty standard practice on ether scan is if you're launching your own project is to verify your smart contracts so that people can see how they work and now you can see the contract name token you can see all the source codes saved in it on ether scan you can see the smart contract api the contract creation code all that type of stuff all right and then also one big benefit is it gives you these this interface to read from your smart contract and write to it so you can see you know how much how many tokens do i have you can go to your meta mask here copy your address paste it into the balance of and then click query and you can see you have all the tokens all right now i'm going to show you how to actually add this token to your ethereum wallet in metamask so you can see how many tokens you actually have i just copy the contract address all right go to metamask and just click on assets and then add token and then paste in the contract address and it'll auto populate the symbol and the decimals click next and there you go all right and now you can send these around to however you want to you could take some arbitrary address right like you just find some other address and meta mask you can just go to you know some address here uh you could just i don't know just click on this minor and we can send them some of our tokens just copy it and then go to metamask and now you can send your tokens around you can just click send and then uh actually paste an address here let's just see copy it all right and then just say like send the tokens and swap from ether to tokens and say we just want to send them one token so now inside metamask you don't have to do the you know crazy stuff you can actually do decimal places but we want to send them one token we can just do that click next and then boom there we go you'll see it populate whenever it's finished all right so uh we've completed several of the objectives so far so we can just see on our whiteboard here we've completed the first objective of creating the crypto now we have actually put it on a blockchain and we have stored it in our wallet okay so now we wanted this last step of actually listing on an exchange so we're going to do this with uniswap all right so in order to list it on uni swap we're going to use something called a liquidity pool so what does that mean well basically a uni swap uses something called an automated market maker so whenever you go to uni swap you just tell it like which token you have and like which token you want to swap it for and it just does the magic behind the scenes there's no like order book there's no candlestick chargers nothing like that that you would see in a traditional exchange that would have you know traditional market makers this has something called an automated market maker on the back end so how that works is basically you provide liquidity to uni swap so you are the modern market maker and other people who hold this token can also be market makers but you're the first one you have to provide funds to this liquidity pool in order that other people can buy it so how it works is you create a pair a trading pair so in this case we're going to take the two cryptocurrencies that we have in our wallet our token you know my token mtk and then also ether which we hold in our wallet and we're going to take equal weightings of my token and ether uh that will actually set the initial price for the token whenever we deploy it to or we put in a liquidity pool so i'll show you how to do that basically um you go to uni swap all right so you gotta you swap here make sure that you select your account um and make sure you select the kovan test network okay and you'll see that you're created here so uh you can look at the steps inside your github repository basically you click on the pool tab which is here all right so you're on the swap tab i'm gonna go over to pool and then you go to uh you know create new pool new new position here all right so for the pair we want to leave east selected okay and then you want to actually uh you know select the token so what you want to do here is uh take your token that you deployed to etherscan actually let's just find it or you can go back to remix and find it here uh let's go to remix find your token address copy it go back to uni swap and then paste it in all right and then you import my token okay and uh based on the same page you want to click add liquidity and then uh do like this so it doesn't appear the active second list make sure you want to list a token you want to trade yeah that's okay you want to import it and so we want to set a fee so this is probably the best for most pairs so we're gonna collect zero point three percent okay so for initializing pool we wanna set the starting price for the token basically the price is gonna be reflected in eth so about the time record this video is about twenty five hundred dollars so basically you could just say that twenty five hundred dollars worth of eath buys you know like i don't know a thousand tokens one two three if you give that one each it'll give you a thousand tokens okay minimum price of how many tokens per each let's just say you know 500 and then max 2000 all right and so now we can say uh how much each we want to deposit well we don't have very much ether in our wallet so we can just do a minimal liquidity if you want to make have a lot more liquidity you need a lot more eth in your wallet so for this demo purposes you won't be able to buy many tokens on the grand scheme of things but uh if you have a lot more ether you can increase this but i'm sure it's like point zero one eth and that means we're gonna deposit an equal share of only nine tokens so now we'll click approve all right click confirm this is the approval step we talked about i click preview and then you can see all the settings here it's in range click add all right confirm and then there we go i'll give you an explorer and so now we have uh complete this last step of actually listing the token on the exchange so let's demo it let's actually see um i'll see we'll see it work in real time so the transaction's been submitted you can go back to uni swap and now anybody can you know buy your token a good test of this will be actually using a different account sending an ether and all that type of stuff but for now we should use the same account we're going to click on the token that we have which is eth we got ethernet wallet here we want to buy my token so we'll just paste in the contract address for my token here all right and then uh we'll click mtk let's just paste in the right one i deployed this before so let's just copy it uh my tv swap make sure i got the right one pasting the address all right click on that one all right so enter in let's say point zero one ether let's say zero zero zero one either actually let's just saw one sorry this one all right and that that will give us a new token click swap confirm swap confirm and you can see it has a nice special link to add the token to your wall if it's not already and then you can see the transaction wait for it to finish sometimes it takes a second on the test network all right boom there we go so we've transferred uh tokens from our wallet like this perfect so now you've accomplished every single one of these steps you know you created for smart contract you've created a cryptocurrency you put it out there live on the blockchain uh you've got introduction the coding on this you have you know uh listed it on an exchange you can actually trade it live right now so that's your introduction to ethereum programming with a smart contract this is how you can implement something really powerful in under an hour like you can launch a cryptocurrency put it on the network uh get people live trading it really fast so um we've covered a lot today in a short amount of time um if you want to get your hands dirty and continue on beyond this we have lots of tutorials on my youtube homepage you can go to like full-on udemy courses but they're totally free so taking your view to the next step which is basically building a full stack blockchain application maybe you want to build a you know simple token exchange you can do that you want to build a d5 project you can do that you've got the you know front ends with javascript you've got the back ends with solid smart contracts and truffle you'll figure out how to write you know tests for them and if you like those courses you went to the next step then i should become a blockchain master like a real professional level blockchain developer over at dap university.com forward slash bootcamp alright you have to be an expert to get started today i've helped people with zero coding experience become real world blockchain developers in a matter of months so that's all i've got until next time thanks for watching dap university
Info
Channel: Dapp University
Views: 43,942
Rating: undefined out of 5
Keywords: ethereum developer, ethereum solidity, dapp ethereum, ethereum app, ethereum development, ethereum dapps, ethereum application, ethereum tutorial, ethereum mist, decentralized applications, ethereum web3, dapp, ethereum contracts, solidity, programming ethereum, ethereum programming language, ethereum coding, ethereum contract, ethereum code, ethereum virtual machine, ico
Id: XyoFT4QkoL4
Channel Id: undefined
Length: 48min 30sec (2910 seconds)
Published: Fri Aug 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.