avatarHenrique Centieiro & Bee Lee

Summary

The article provides a comprehensive guide to deploying an ERC20 token on the Ethereum blockchain, suitable for individuals with or without coding experience.

Abstract

The article titled "Deploy Your First ERC20 Token in 5 min" demystifies the process of creating an ERC20 token, which is a common standard for fungible tokens on the Ethereum network. It explains the concept of ERC20 tokens, their use in various projects, and the fact that they can be exchanged like fiat currency due to their fungibility. The author guides readers through the steps of deploying a token locally using Remix IDE, explains the code structure, and demonstrates how to interact with the smart contract. The guide covers setting up a Metamask wallet, obtaining test Ether, and deploying the token on the Rinkeby testnet. It emphasizes the importance of understanding token standards and the potential of ERC20 tokens in various applications, including DAOs and digital assets. The article also suggests further learning resources, including a Smart Contract Masterclass for those interested in deepening their knowledge.

Opinions

  • The author believes that creating an ERC20 token is accessible to everyone, regardless of coding knowledge.
  • They highlight the versatility of ERC20 tokens, noting their representation of various assets and use across different decentralized applications (dApps).
  • The author expresses that Ethereum's high gas fees and network congestion can be mitigated by using Ethereum 2.0 or other EVM-compatible blockchains.
  • They suggest that the process of deploying a token can be both educational and empowering, encouraging readers to engage with smart contract technology.
  • The author promotes the use of testnets like Rinkeby for learning and testing purposes before deploying tokens to the mainnet.
  • They endorse their own educational content, including a YouTube channel and Udemy courses, as valuable resources for further learning on blockchain development and investing.

Deploy Your First ERC20 Token in 5 min

Do you have a crypto project in mind? Do you want to create your own ERC20 token? It’s never been so easy. Here, you will find all the details to easily build your own token!

ICOs, IDOs, and at least 80% of the tokens that you see on Coinmarketcap are ERC20 tokens. Shiba Inu, Baby Doge (and in fact most coins with “Doge” in the name except Dogecoin), USDT, and most DAOs are ERC20 tokens.

In this article, I will be showing you how to deploy an ERC20 token, step-by-step. The purpose of this article is to help everyone to be able to deploy this token whether you have coding knowledge or not. Before we go into that, however, I’d love to give a little introduction to the term “ERC20” for the noobs reading this, remember this is for everyone 🐵

If you want to have a complete course on how to create and deploy ERC20, ERC721 (NFTs), and ERC1155, check out this Smart Contract course.

Let’s get into it champ!

What exactly is an ERC20 Token?

It’s basically a fungible token, meaning that it can represent any fungible asset. I know there are many terms but a fungible asset is just an asset that can be exchanged with some other asset of the same value. For instance, a $100 note can be exchanged for another $100 note or ten $10 notes or twenty $5 notes; it’s that simple! Digital assets like Bitcoin, Ethereum, Dogecoin, etc, are all fungible assets because they can be exchanged to corresponding value against one another. It is important to note that tokens are not cryptocurrency. A cryptocurrency has its own native blockchain while a token is built and lives on another blockchain.

Now, an ERC20 token is designed to fuel economies, it can be a governance token in a DAO or represent any kind of asset. It is the token that is built on the ERC20 standard, a scripting guideline of the Ethereum network to get tokens to work across different dApps.

By the way, there are a number of blockchains that are EVM — Ethereum Virtual Machine — compatible. This basically means that you can deploy the same ERC20 token to any of these EVM-compatible blockchains: Ethereum, Avalanche, Polygon, Moonriver, Tron, BSC, and more! If you wanna deploy your token to one of these networks, you just need to enable it on Metamask and have a bit of their cryptocurrency in your wallet to pay for the gas fees.

By the way, if you wanna deploy an ERC20 on the Ethereum Kiln testnet (which mimics the Merge) check the article above.

Oh, and one more thing: if you need to set up your Metamask wallet and get some test Ether, check the article below:

Now, let’s deploy your ERC20 token, hurray!

First, head to my github link to copy the code right here, we will be using it as a scaffold for this exercise and we will be creating the Poodle Token (yeah, I’m tired of Shibas). Don’t worry, we will look through the methods later.

Next, head to Remix, our IDE for development, to begin coding here. Then go over to the file explorers section and click on the icon highlighted below to create a new file and name it. In this article, I’m naming it Poodle.sol (please note the case used).

Next, head over to the GitHub link and copy the code just like this:

Then go to the file created and paste the code.

Next, go to the default file, contracts, and open Storage.sol as shown below:

When inside the file copy the license code on line 1 and head back to Poodle.sol to paste the code on line 1, your code should look like this

Now we are ready to begin to create our token. So, head to line 21 and we have a couple of changes to make. Change the values as shown below:

Every other thing has been set for us, you need to pay attention to the text in green (the comments) to understand, but I will also be explaining below:

First of all, lines 24 and 27 are related.

Line 24 specifies the number of decimals that represent a token; in this case, it’s 18. So, 1 unit of a toke token is basically represented like this: 1 + 000000000000000000.

Line 27 is the total supply of tokens that we want the Smart Contract to mint. In this case 1,000,000 (one million of this token in supply), hence we add the 18 decimals representing one token like this:

1 + 000 000 + 000 000 000 000 000 000

uint private constant __totalSupply = 1000000000000000000000000;

And this brings us to the total number of zeros that we have on line 27.

To briefly explain the above code, we are simply mapping any approval for any transaction to a stated address. We need to determine how much an address is liable to spend, based on balance, before authorizing the transaction.

The above constructor simply allocates the total supply of the token to the creator of the smart contract, the program you’re currently running.

The above code simply allows anyone to check the total of the number of tokens in supply. In our case that should be a million tokens.

As it reads, the above piece of code allows anyone to view the balance of a specific address.

The screenshot above is the transfer function that gives us the ability to transfer some tokens from one wallet to another. Depending on the balance of an account you can transfer by first checking if the sender’s wallet’s value is greater than zero and the sender has the amount to be transferred. Next, you are deducting the amount transferred from the sender’s wallet — line 56 - and adding it to the recipient’s wallet on line 57. Then we emit the function on line 58.

The above code allows a 3rd part to transfer some token from your wallet to another wallet after doing similar checks from the former function. This function is enabled provided that the 3rd party has allowance based on the following code:

If the third party’s address is allowed then the function to enable transfer from your wallet by the 3rd party is called/enabled/activated.

I hope that’s simple enough 🥂😉

🎞️ Crypto Henri Youtube

Next stop, Deploy your ERC20 token locally

To deploy your token you need to:

  1. Click on the solidity compiler as shown below:

2. Convert your program to a solidity readable language by heading to the compiler and selecting compiler 6.7 as seen below (or whatever is the version of your code):

3. Click on Compile. If you’ve followed exactly what I’ve shown you from the beginning there shouldn’t be any error messages.

4. Click on Deploy and Run Transactions. Make sure that the environment selected is the same, Javascript VM (London). It is used for deploying contracts locally (in a JavaScrupt Virtual Machine on your computer) and not at the blockchain level.

5. Next, click on deploy as seen in the screenshot above. Make sure to check the Contracts and select your contract as seen below:

6. You should confirm that you have the following options as seen below as you can now carry out actions locally (on your computer but not on the blockchain). You can now test your smart contract functions! 🦾

7. After deployment, you will see a list of functions to be called. Let take them one after the other as seen in the image above. These functions are the functions that make the ERC20 standard a standard. All ERC20 tokens have the functioned below

  • Approve(): This method gives access to a spender to spend an amount when called. It requires the spender’s address and amount.
  • Transfer(): After approval of a token is done, then the token can be transferred/withdrawn by the spender.
  • TransferFrom(): gives authority for a token to be spent on behalf of the token owner.
  • Allowance(): The allowance function returns the token amount remaining. The spender is allowed to withdraw from the owner’s account.
  • balanceOf(): This method gets the token’s current balance by taking the token address as a parameter.
  • Decimals(): The unit set by the token owner
  • isContract(): confirms the address of the contract
  • name(): The name of the token.
  • Symbol(): Shows token symbol as set in the code.
  • TotalSupply(): The total supply of the token as set in the code.

Finally, the real thing! Let’s deploy the ERC20 token on the blockchain!

First off, you need to have a non-custodial wallet installed e.g metamask. Metamask is the gateway that holds users accounts and also allows us to explore blockchain applications in seconds. Once metamask has been installed, go to settings -> advanced -> show test networks. Here, you can find the Rinkeby network amidst others. Now, let’s fund our Rinkeby account with some test Ether. This is necessary to pay the gas fees to deploy the smart contract. If you do not already have faucet funds in your Rinkeby account, copy your Ethereum address and you can get faucet funds here.

When this is all set, go to your program and change your selection from JavaScript VM (London) to Injected Web3 as seen below:

Then in MetaMask make sure the Rinkeby Test Network is selected, you can now go ahead and deploy; make sure to connect Remix to Metamask when the prompt comes up. Also, make sure to confirm the transaction and the payment of the gas fee when the prompt comes up.

Boom! Done! Finito!

You should see a page that shows up like the one below and that’s it, you’re a blockchain developer in the making!

You can check the transaction on Metamask and click on “view on block explorer” in order to see the transaction on Etherscan.

You should now be able to see the new token and see the contract deployment by checking it on Etherscan.

Now you can also use Remix to interact with the smart contract and you can also add the new token to your Metamask by clicking “Import Token” and then copy/paste the new contract address into Metamask. 🚀

If you wanna learn this and many more types of smart contracts, check out this Smart Contract Masterclass and in my next article, we will be deploying another type of ERC20 token!

If you thought this blog post was worth every bit of your time, please share it with a friend who would benefit from it too 🥂

👾 Create NFTs, Tokens and DAOs — Smart Contracts Masterclass

🦄 Metaverse Masterclass — Learn Everything about the Metaverse

NFT Investing Masterclass — Pro-Tips about NFT Investing

📖 The Complete NFTs CourseLearn everything about NFTs

🎞️ Crypto Henri Youtube

Erc20
Ethereum
Blockchain Development
Cryptocurrency
Smart Contracts
Recommended from ReadMedium