This video tutorial demonstrates how to create a custom ERC20 token on the Ethereum blockchain using Remix IDE and MetaMask. The ERC20 standard, established in 2015, defines essential functions including totalSupply, balanceOf, transfer, transferFrom, approve, and allowance, along with transfer and approval events for transparency. The tutorial walks through implementing these functions in Solidity, deploying the contract on the Ropsten test network, and verifying the token in MetaMask and MyEtherWallet. Key concepts include using require statements for transaction validation, mappings for tracking balances and allowances, and understanding that while creating tokens is straightforward, real-world implementations require additional security measures to prevent vulnerabilities like overflow attacks.
How to Create ERC20 Tokens on Ethereum: A Tutorial
Added:[Music] in case you didn't know you're actually able to create your own cryptocurrency or custom token on top of the ethereum blockchain through the use of smart contracts you might have also heard about the hype and the craziness surrounding these so-called icos or initial coin offerings and all initial coin offering is is a crowd sale put on by various companies usually tech companies uh to exchange their custom tokens for ether as a way of raising Capital now some of these things have gotten quite out of hand um because they're actually quite popular usually and they end up sometimes crashing the entire ethereum network in this video I'm actually going to show you how to create your own custom token uh and then in a following video I will show you how to create your own um Ico contract so you could raise funding for um any of your own projects in the future so to get started let's take a look at what is called the erc20 token standard and all the erc20 standard is is a draft specification created uh in 2015 that defines um what a token contract should look like and all or virtually all of the modern Uh custom tokens that have been put out in the last few months all follow this standard so every token should have a total Supply function and all that does is return the total amount of token in circulation it should have a balance of function and given an address it Returns the balance that address holds of your token a transfer function does exactly what you would expect it to do it would transfer the value um to another address from your own address transfer from uh is a special type of transfer and basically uh as I will talk about down below you can give uh permission to another address to spend tokens on your behalf so this is what this transfer from function is from or for uh and then this approved function basically gives lets you give permission to another address to spend on your behalf and then the allowance is just a function that returns how much uh how many tokens you've given permission to that other address to spend and then the final two pieces are these events a transfer event and approval event and they're just a way to log um what's going on so if a transfer happened you log to um you're transferring from to and the value and then approval um basically you're logging that you've given permission for an address to spend on your behalf now before we dive into any code um in order to work with the the contract that we're about to create you're going to need to install a Chrome extension called metamask and all metamask is is a ethereum wallet that runs within the Chrome browser and allows you to actually interact with um ethereum decentralized applications um by injecting uh a JavaScript library called Web 3 into the browser and by doing that any ethereum connected uh web application will use that library in order to talk to the ethereum network um and then do its thing you're also able to um connect to a local ethereum network that's running on your own computer as well as several ethereum test networks so once you have that installed you're going to have it's going to ask you for a password and it's going to generate a wallet for you and and then you're going to see something like this so you'll see your account and then how much ether you have and then any transactions and also up here you're able to select the network so you can run on the main ethereum Network or any of these test networks or if you have a a client uh an ethereum client running on your local machine you can actually connect to that in this case we're going to run on the robsten test Network which is a live Network um that actually has to be mined in order for transactions to run through um so it's as close to running on the main ethereum Network as we can get without actually having to spend a bunch of money so go ahead and get that installed before you continue on to the next part so coming into our remix uh IDE I've basically copied all of those methods from The Proposal and created an interface called ic20 and then I've created a contract that Imports that file and then implements that interface so we actually have to implement these functions because this this uh token contract doesn't do anything so we've got this funk token and basically the first thing we're going to do is implement this total Supply function so we're going to need to return a total number of funk tokens in circulation so we can do that first by creating a variable making it public and constant and then calling it we'll just call it total Supply and we're just going to say how about 1 million so 1 million Funk tokens and then we're also going to send this initial balance to ourselves so we're going to say we're also we're going to need this uh a place to actually store these balances so let's create a mapping and it's going to be a mapping from address to an unsigned integer of 256 we're going to call that balances and the first balance we're going to initialize is our own so we've set the total Supply to our balance and we're also going to return the total Supply uh in that function so that function is taken care of the next thing we want to do is return the balance of an address and that's easy so all we have to do is return balances and then given an address which in this case is underscore owner return that so that takes care of that function the next is transfer so this is a little tricky in that we need to do some checks before we actually are able to transfer anything so to run the check we're going to use a require statement and a requir statement is basically an if statement uh and shorthand that will throw an exception if any of the U conditions inside it fail so we're going to do multiple conditions the first condition we're going to check to make sure that whatever we're trying to transfer out actually exists in our balances so the balance of message. sender needs to be greater than or equal to the value we're trying to send and then the next thing we're going to check for is to make sure that value is greater than zero we're not going to try and waste time um sending zero to somebody so if those two pass we can go ahead and transfer and the way we do that is we decrement the balance of the sender and then we add to the balance of whoever we're transferring it to and then the next thing we're going to do is log that this happened using the transfer event and just looking down below the transfer event we'll take a from so would be from message.
sender to and then the value because this needs to return a Boolean will return true because it succeeded so that takes care of the transfer function next is the transfer from this is also going to require some checks and one other thing we're going to need to create is some way to track who's been given permission by who um to transfer on their behalf so to do that we're going to create another mapping and this is a mapping of an address so this first address is who is giving permission and then we're going to map it to another mapping and inside that mapping there's going to be an address and this address is who is being given permission to spend these funds and then that's going to be mapped to how much they're actually allowed to spend and we're just going to call that allowed so back down here in this transfer from first thing we're going to check is that whoever is trying to spend this that they're actually allowed to do that so we're going to check that allowed um from so they're trying to spend this person's um tokens and then we're going to check to make sure that they themselves so message.
sender are able to spend this much so greater than or equal to that value we're also going to check just like um in the previous function that the balances the balance of whoever we're trying to spend from is greater than or equal to the value also we don't want to spend any zero balances or send zero tokens so we're going to check that value is greater than zero so if all those pass we'll go ahead and do the same thing that we did above we'll transfer so from we'll take away the value and then we'll add to the recipient which is two and then one last thing we need to do because uh in this next function we're going to allow someone to spend a certain amount we're going to have to decrement from that amount so if they spent uh 50 of like a 100 tokens we want only 50 to be left in the allowed mapping for them to spend later on so allowed from message.
sender and we decrement that value and then we do we log another transfer event so from to value and return true because it succeeded so next we have this approved function and this is pretty simple all we do is add um update the value in the approved mapping up above so approved message.
sender for the spender and they're able to spend this much of our tokens Undeclared oh allowed so they're allowed to spend that many and then we return true oh one also one thing we also need to do is log that we've given an approval so we can track that later so message.
Sender Spender and then value and then this last function is just going to return the value from that allowed mapping so and that's basically it for a contract we've implemented everything in that interface but there are few more things that need to be added in order to make it a more userfriendly experience when people are actually working with your tokens so there are a few more variables that uh most of these tokens actually Define so the first one is going to be a string and that is called symbol so if your token actually ends up on an exchange like palonia or bitrex it's going to be trading under a specific symbol so you're going to want to try and pick a unique symbol in this case we're just going to use Funk and uh that's going to be our symbol the next variable is going to be called the uh the name and that's just a special name so fun F token and then finally this one is called decimals and all decimals is is a way to show how your tokens can be broken up or denominated so in this case we're going to use three decimal places and because we have let's say 1 million Funk tokens this is actually how it's going to show up within your wallet so essentially one Funk token is Z1 and one one whole um whole number would be called something else so just like an ethereum um one ether is actually many times uh one way one way is one quintilian of an ether so this would probably be called a super Funk or a mega Funk or whatever you want to call it so that's how that's going to look when we actually open it up in one of our wallets so everything is looking okay H let's go ahead and try to deploy this so when you're deploying on a live Network even a test Network it's going to run through your wallet so your metamask wallet is actually going to ask you to accept the transaction because it actually costs ether to deploy contracts so we're going to click accept because this is not real money and then we're going to wait for this to be mined actually through the magic of the internet we're going to fast forward so you don't have to sit here and wait for this okay so our contract has been deployed let's go ahead and copy this address and let's head over to wallet. ethereum.org and this if you're familiar with the misted ethereum browser this is the same interface so you're able to run this through any browser uh as long as you have something injecting the web 3 JavaScript library into it in order for it to talk to the ethereum network so that's what we're using metamask for so when you get to this uh main dashboard we're going to click on contracts and then go down to watch token then we're going to paste our address and for some reason this is being finicky so we're going to refresh this go back to contracts try and paste again all right it worked so you paste this address and it found our token it knows the name it knows the symbol and it knows the number of decimal places so let's go ahead and hit okay and now we're watching this if we go back to wallets and click on our wallet you can actually see that we have 1 million Funk tokens in our balance um we can also add this to metamask this is an old contract that I was playing around with so let's do the same add that and now you can see it's in metamask so both of these wallets know how to work with erc20 tokens um and so we can actually test sending tokens to another address I think I have a few addresses in metamask So yeah so account One account two we're going to copy the address for account two and then we're going to send we're going to send to there and then we're going to send 100 now let's send 1,000 no let's send we let's send 10 10 Funk tokens so that's what it's going to look like send 10 Funk tokens to that address hit okay accept and then through the magic of the internet we'll fast forward and I'll show you the balance of my other address all right now that the transactions have been mined we've gone to this other address and you can see we have essentially 10 I guess super funks Mega funks or 10,000 Funk tokens sent to this new address and that's basically how easy it is to create your own custom token in the next video um I'm basically going to show you some improvements on our existing contract because in its current current form um it's actually not very robust um there are some vulnerabilities that people have found um with math um it's actually susceptible to what's called an overflow uh attack so we'll go ahead and address that and then we'll also describe how you would actually go about um launching your own own Ico or initial coin offering in order to raise funding for whatever project you desire so if you like this video please hit like um if you like what I'm doing please hit subscribe so you can be uh notified of my new videos um and if you'd like to donate uh I'd appreciate it uh I've given all of my crypto addresses down in the comments below I look forward to seeing you in the next video
Up Next

AutoFarm Yield Aggregator on Binance Smart Chain: APY Explained
@AltcoinBuzz
21K views•2021-03-03

Hybrid Key Establishment in Production: Post-Quantum Cryptography
@durumcrustulum
14.7K views•2025-08-27

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto











































