Creating ERC20 Token using Truffle

Ethereum Blockchain Ethereum totorials
28 minutes
Share the link to this page
Copied
  Completed
Creating ERC20 Token using Truffle

Transcript

Hello, I'm going to show you how to create an ERC 20 compliant token using truffle. Then I assume that you know, you know NPM no GS and truffle, know how to use them. You have done something with them. So first of all, I'm going to go to my workplace and create a new folder, which is going to be obviously empty. It is let's create a C 20. folder. That's either and less empty truffle.

Great. What do we have here? We have everything we need. Okay, so let's check what it has created for me. Ah, a placeholder labels, contracts, migrations and tests, everything I might eat. Now I'm going to create a simple command 20 token.

So, I'm using just Jessica, double check. Ah, nope. Is that just an artifact of the fact that I'm using command emulator. So I need to use the open for 450 and I'm going to use it Okay, so It is now Ah DRC 20 means that it is standard which is created by the children so that the tearoom developers so there is an agreement on what everyone should use So, I'm gonna go ahead and create a new window and can I first of all, first of all show you some simple though gets it is it is that say the first one. Let's take the first one It is, it is. This is a token, which implements all the standard functions which you need to implement and adds obviously additional functionality which is unique to each token by white as claim.

Token time lock that's unique. That's a two distinct token. Okay, so let's start. I'm going to use an open Zeppelin. As it has everything I need to create a ERC. 20 compliant token.

It's over here in token and it startup, right. I'm gonna use one file one file to To make it simpler, okay so as you may see this on a token requires ERC 20 and basic token. So what I'm gonna do is I'm going to be copying just just that. It will go to ERC. 20 it uses ERC 20 basic Okay, well let's go to ERC basic token. c 20.

Basic, this one okay. Does it use it? No, it does not. So I'm going to go ahead and just copy to my code. Okay, good. Now as you can see it has total supply, this is the variable which will hold maximum.

If it's not an interval, the total amount of supply of tokens. This function obviously going to check and return the amount of tokens Someone has this transfer function will allow you to send tokens from a from the sender meaning for example you to someone else and obviously each provide the value know how many tokens you want to set the event is something which will be fired to track down the the amount of traffic and addresses from and to. So let's get going. So what else we do all the stuff we need ERC 20 and basic token basic token Ah, it is basic token. I'm going to remove all the comments to make more clearer. Okay, what else?

Does your safe math Okay, safe math is safe math. It is, which is where it is. This is safe math. It's okay, just great. Now I need some basic token. Do I have a safe math by basic token?

Okay. Now what else needs to start? I need your 20 do I have it? Yes, I know I do not have Okay, let's find it. It should be right Right You see, do you see 20? Yes Yes that's it I've seen the startup is ERC 20 and basically you have basically Yes, yes.

Yes. Okay now coffee tea ah I'm gonna go ahead move all the comments. Now as we see now just under token implements, ah functions which is have been declared in ERC 20 years basic token. So basically even though it's it's named contract, but it is interface for for the students To use them to describe them. Okay, so as you may see bad on it, there's a limitation of balance and limitation transfer. Okay, so do we have everything we need to create a start token?

Yeah, I think it is, I think it is. So now we can create our, our took. Yeah, that was our collagen code simple c 20. token is a token. Right. I'm going to implementing this one. I'm going to use ng m every function this one has and this 100 and this one in my token in order for it to be ERC 20 compliant now what do I need to do when I what what proper this token has okay so so token has obviously token has some name so we're going to declare our name I'm sorry public name which would be to change your marriage to 20 standard token okay let's let's let's change name or ah something I like zero.

So, yeah. Now we need to short symbol which would be that say Thunder. Yeah, let's go with it. Now we might describe this and let's let it be to. Now we're going to describe an initial supply. Public constant.

Initial shelf supply. Let's say it's gonna be 10 millions. So that would be 10 raised by six plus decimals. It is it is. Okay. We have to go Everything now we need brought provide the construction.

So we provide an assign total supply, initial supply to total supply. So name of constructor should be the name of the contract. Ah, let's go Oh, obviously wouldn't check us out the owner. Do we have an older that's fine. That's the owner. Okay, so we did not have, we're not gonna have an owner but if we were to have an owner, obviously, this token would need To implement OAuth.

So I think I'm going to do it because this is the center of practice right now. So yeah, I forgot the owner contract. And I'm going to add it just right here. So basically what it does is assigns an owner to our to this contract and the contract may inherit many races. So I'm gonna inherit ownable. So it will have the owner variable.

I'm gonna send a sigh new owner to the one who's gonna deploy the deployed contract. I'm gonna assign total supply which was described Sticking right here, and initial supply it is. That's all. That's all there is to it rc 20 token. Now, in the following video I will show you how to deploy this contract. But before that, before deploying it to Robson, the test net for Fortier, I'm gonna deploy it and check it out on test.

So I'm going to run through, see you go oops, here we go. What do I do now? Obviously I need to compile Sure, go ahead and do that. I'll remind you that CMD is just because I'm using this CMD or command is basically an emulator for command prompt. And the reason I'm using it, it's it has, I don't know, it's highly customizable. And there's another thing is which you can do.

You can do this. You can do you can do this, which is very, very cool. I guess. That's close that. Okay, so, right now I need to compile that's compile. Okay, here it is.

It did compile. Okay. That's great. Now, you Come file right here. Contracts migrations. Binary Second.

Okay. So this is and let's print out migration for that. Okay, so migrations is gonna be a C 20 token there. And we go, boy, okay, so we now we need to obviously buy Okay, use your board deploy and it has not quite there because I used it correctly. Check it out again. Okay, so contrast simple etc.

Is try some reason doesn't create pull it up for it. I wonder why? To get back to it again. I think it's because I didn't say it. I said yes, I see now check it again. Compile Okay, it's much better Okay, so I made a mistake this function let's go ahead and file that file it compiled that shape file.

So, as Go ahead, as you may imagine the wishes simple usage token, this one this one will have everything bound to it, meaning it will have safe math vulnerable, is it basic and so on. So what we might do it right now is try to deploy this contract. Yeah, that's good to hear with it. Okay, great. It did deploy to this address this deck groups so what I'm gonna do now is I'm gonna test desktop. So first of all i to connect to the disk desk.

Desktop. So good. issued the RPC commands. Now I'm gonna fly to a metal but what is with this dick? Yeah, I'm gonna go ahead. I cannot remember.

What should I write? Up help? Okay. It is this style publish, sir. Oh, no. Console.

Yeah, it is. It is. Okay, so now I'm going to describe This as an ad was my contract this one it is now I need ABI of this contract which I'm gonna get wrong. I'm gonna get wrong what it is but yeah. So this is Abi. At the end of it is, right?

Yes, it is. Check it. I think this this Yep, go ahead. Oh yeah, it does. Yeah. Yeah.

Id Park Probably dose doesn't work. Okay, that case I'm gonna do what I always do, I'm just gonna use the way I always get my API this simple c 20 tokens. It is their face. It is face. So check out API expected, then. Okay, so that's again, I just need to copy.

There were too many parenthesis. Yeah. So ABI works fine. Now, how do I connect to my contract? I do all three contracts contract to contract. out I provide API at address, which is what I think.

Yeah. Right. Let's check to see what it has. What I'm interested is volt supply. That's, that's checked those supply as is correct. Yes, it is correct.

It has $1 and less two decimals. How many zeros do we have? This 123? Like 2323. Okay, so we have too many zeros, because I'm multiplying 10. Yeah.

So I get 10 billions, not one. And I suppose that was my first place. So it's 10 billions. Not one. Sorry, I forgot. Now.

What do we need to check? Okay, let's check. Who am I? And so I was sent Okay, so what? We need two addresses for that. Find one.

So I'm going to check the balance of myself and the owner or business His first count was three counts. Zero Yeah, this is this is me This is the owner let's double check if the contract owner matches owner Cole. It is so now I'm sure that I'm gonna have initial supply that will I let's check balance off owner balance opponent is zero. Why is that? Because I did not assign initial supply to him. I don't want to create If not assign any supply to anyone.

Now we need to fix that obviously. So balances off owner which is me and it's crate initial supply and that's that Okay, so we need to redeploy obviously recompile loida squid and squid file right now. Boy so no update because I do not change anything so checks two checks API and same so there's nothing to date. Think that how it works so what I'm going to do is I'm going to start to test around See? It is now started and I'm gonna redeploy it redeploy. Now, ratios on a simple see edit it to the address.

So I go ahead and connect this up See? Ah, now what do I do? Yeah. This is the address on contract. Do I have a be safe? No, I do not have safe API.

Okay. coping again. Best. Basically it is we do have our cc tree. contract. Yeah.

At address which is right. I'm gonna sign on the account. CEO. Okay, so let's check the balance. sec. balance off coal.

Oh, okay. It is now I do have tokens. Now I want to send some tokens to other accounts. So accounts is going to be the second to call. Sorry. First one in the array.

Okay. Now let's double check that it has no balance unless it is zero to get let's send now let's transfer Can you remind? Yeah, do like she check so To and then develop Okay, great. So to develop the last 1000 Okay, it is at Bell address because I say from whom I said let's go back to Okay, it is 1000 so now I need to check whether I have but it's extracted from previous from my about it. Yes it did. So that's it.

So now, whereas an honor tester proceed the following videos, I will show you how it works on the Robson test network and how the ether scan checks your token. If it's yours compliant, it can you know, help you out to send a check the balance and so on. Okay. Good. Thank you that sit please post questions, you know and the comments, suggestions and so everything gets welcome. See you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.