How to Create an ERC20 Token on Polygon

Ioannis Tsiokos
StakeBaby
Published in
11 min readMar 22, 2024
how to create erc20 token on Polygon — introduction

In the blockchain space, developers and entrepreneurs have been paying close attention to how to create an ERC20 token on the Polygon network. This tutorial seeks to give a comprehensive view of the procedures, instruments, and tips for having your own ERC20 token running on Polygon that has high speed and low fees during the transaction process.

Key Takeaways

  • Understand what ERC20 tokens are and their benefits on the Polygon network.
  • Learn the prerequisites for creating an ERC20 token on Polygon.
  • Step-by-step guide on developing your ERC20 token.

Introduction

Due to the development of blockchain technology, digital assets such as ERC20 tokens have become possible. These tokens are based on Ethereum blockchain which is why they have some standard rules that allow them to be shared or transferred among any Ethereum address. For this purpose, one can use the scalability and efficiency of Polygon network along with advantages such as low transaction cost and high speed inherent from Ethereum’s vast ecosystem.

Understanding ERC20 Tokens

ERC-20 tokens are therefore these digital properties within the Ethereum blockchain. A set of particular standards has been put in place by which an Ethereum token or smart contract must adhere to or follow its guidelines. The idea behind this standardization is making it easy for different projects’ tokens to be traded, managed or get implemented into various applications.

Get to know more about ERC-20 tokens with this article: Is Polygon MATIC ERC20?

Pre-Requisites for Token Creation

Before going into the creation of an ERC20 token, there are several pre-requisites and tools you need to familiarize yourself with:

  • MetaMask Wallet: A browser extension and mobile app that acts as a digital wallet for Ethereum and ERC20 tokens.
  • MATIC Tokens: Required for gas fees when deploying the contract on the Polygon network.
  • Solidity: The programming language used to write smart contracts on Ethereum and Polygon.
  • Remix IDE: An open-source web application for developing Ethereum smart contracts.

Creating ERC20 Token on Polygon

Let’s build an ERC-20 token and deploy it to the Polygon test network. But first, what exactly is an ERC-20 token? Make sure you have already read the article suggested above to get a deep understanding about ERC20 tokens.

Basically, it’s a representation of something on a blockchain. It’s a fungible token. That means the tokens are interchangeable. It’s quantity that’s important, not necessarily the individual items. A good example of this is fiat currency.

You care about how many you have, not necessarily which ones.

In this tutorial, we’ll be using OpenZeppelin contracts. The reason is OpenZeppelin contracts are a set of contracts that are audited and battle tested. It’s a great place to start when you’re doing something like creating an ERC-20 token. If you head to their official website and look at their products, you can find their contracts.

how to create erc20 token on Polygon — OpenZeppelin

This page is about installing them locally but we don’t have to do that as we will be using Remix, an online IDE that will import the contracts for us. However, if you click on Getting Started, it will take you to the developer documentation. From here, you can see they have a contract for ERC-20 tokens. Now, this contract is actually a great place to start and all you need to get going when it comes to creating a very basic ERC-20 token.

Are you staking your Polygon tokens yet? Consider staking with StakeBaby! We’re active developers and contributors in Web3, and by staking with us, you’ll support our efforts to build awesome tools, smart contracts, and content. Plus, you’ll earn delicious rewards!

So let’s copy it and head on over to Remix. If you head to remix.etherium.org, you’ll find the Remix IDE. This is an online development environment for creating and deploying smart contracts. It comes with some smart contracts out of the box.

how to create erc20 token on Polygon — Remix

We can ignore these for now as we will create our own. If you right click on the contracts folder, select New File, you can create your own smart contract. I’m going to call it BabyCoin as we’ll be deploying it to the Polygon network.

how to create erc20 token on Polygon — babycoin

From here, you can paste in the contract that we copied from OpenZeppelin. There’s a few things to talk about here. The first is line 4, where it’s telling Solidity what version to use. Next, on line 6, we import the ERC-20 contract from OpenZeppelin. This contract is everything we need to create an ERC-20 token. It’s that audited and battle tested contract we talked about that OpenZeppelin provides.

how to create erc20 token on Polygon — babycoin contract

Next, we’re actually creating our own contract. Here, they’re calling it GLDtoken. That’s the example that OpenZeppelin used. Let’s go ahead and name it something else, like BabyCoin.

We’re inheriting the ERC20 contract that we imported. That’s giving our contract all of the power of that contract that we’re importing. Our constructor will run the first time this contract is created. It’s asking for an initial supply of tokens, and then it’s going to go ahead and return an ERC20. It’s going to be called Gold. Again, we wanted to call ours BabyCoin. And then it has this symbol for the coin, I’ll name it BCN.

how to create erc20 token on Polygon — BabyCoin token

We mint or create the tokens and give them to the message sender that’s going to be whoever calls the contract. And the value that we’re giving it is the initial supply. At this point, this is everything we need to create an ERC-20 token.

If we head on over to the deploy tab, we can actually deploy this contract to the test blockchain. Remix VM is a test blockchain.

We’ll deploy it there to start with just to make sure everything is working. One thing to note about Remix, you need to ensure that you’re deploying the proper contract. In this case, it’s trying to deploy the ERC-20 contract that we imported. That’s not the one that we want to deploy. We want to deploy the BabyCoin.

how to create erc20 token on Polygon — babycoin.sol

After you select BabyCoin, you’ll notice that we need to give it an initial supply. Let’s pick 5. You click Deploy, and you’ll notice that it says the creation of BabyCoin is pending.

Now, don’t wait too long for this. As under Deployed Contracts, you’ll notice BabyCoin is already there.

how to create erc20 token on Polygon — BabyCoin address

From here, you can look at the total supply of the coin, the symbol, the name, or even the balance of an address. In our case, back up here on account, this is going to be the account that deployed the contract. If we copy this address and paste it in here, we can find that we have 20 coins.

how to create erc20 token on Polygon — BabyCoin balance

Aren’t we rich now? Kidding aside. At this point, we’ve deployed this contract to a local virtual blockchain. It doesn’t exist anywhere else except for locally, but let’s deploy it to the Polygon network.

The first thing you’re going to need is a wallet to interact with the blockchain. I personally am using the Brave Wallet. It’s built into the Brave browser, which is the one I am using.

how to create erc20 token on Polygon — Brave Wallet

It’s very similar to MetaMask. MetaMask is one of the most common crypto wallets. If you go to metamask.io, you can download and install it in a multitude of browsers and even on your mobile device. Once it’s installed, you can walk through setting up a wallet if you don’t have it already.

how to create erc20 token on Polygon — MetaMask

I’ve set up my wallet already. Now, most wallets come with some built-in chains already set up and ready to go. For this tutorial though, we’ll need to add the Polygon Mumbai test network to our wallet. One of the easiest ways I’ve found of doing this is by using chainlist.org.

You will need to connect your wallet to this website. That just means that you’re giving a little bit of access to your wallet to this website so it can add a network for you. If you head to chainless.org and search for the Mumbai network, you’ll find here the Polygon Mumbai network.

how to create erc20 token on Polygon — Chainlist

We connect our wallet and it might prompt you to allow that connection. Once you’ve connected your wallet, just simply click Add to MetaMask. This will ask you if you want to add this network to your wallet. You approve, and you can even switch to that network, and you’re good to go.

It’s that simple. At this point, we’ve taken our wallet, we’ve created a new network, and you may not have any MATIC in yours. MATIC is the native currency of the Polygon network. In order to deploy and interact with contracts on the Polygon chain, you will need to obtain some MATIC. One way to do that is by going to faucet.polygon.technology.

how to create erc20 token on Polygon — Polygon Faucet

This is what is known as a faucet. Faucets essentially drip tokens and allow you to obtain some of the tokens for testing on test networks. Here, we’re on the Mumbai network. We want MATIC tokens then we need to get our wallet address. This is going to be the identity of your wallet. You’ll need to copy your address, paste it in and click Submit. It’ll ask you to confirm this transaction and in a short amount of time, you should receive some MATIC into your wallet.

how to create erc20 token on Polygon — requested token

If you check your wallet after a minute or so, maybe less, you’ll notice you now have some MATIC. This means you’re ready to go to deploy your contract to the Polygon Test Network. Let’s head back to Remix.

how to create erc20 token on Polygon — Injected Provider

In Remix, all we need to change is the environment. We’ll pick the Injected Provider. This will take the information from our wallet and inject it into Remix. Again, you need to ensure that you are on the proper network and that you have some MATIC.

At this point, if we click Deploy, we will actually be interacting with the Polygon test network. You’ll notice now it’s prompting me.

how to create erc20 token on Polygon — matic gas fee

It didn’t do this when we were on the VM. That’s because there is a gas fee associated with this transaction. We click Confirm, and we’ll need to wait for a moment.

And you can see in deployed contracts, our coin is now here. We can take and copy this value and view this contract on the actual blockchain. If you head to mumbai.polyscan.com, you can see the Polygon POS chain testnet explorer.

how to create erc20 token on Polygon — Polygonscan

Here, if we paste in our contract address and search for it, we can find our contract. It’s a token contract, and it even tells us the name and symbol of our token.

You will see here when the token was created, and who created it. And just like that, you’ve created an ERC-20 token and deployed it to the Polygon network.

Utilizing OpenZeppelin Contracts

OpenZeppelin offers a library of secure and community-vetted smart contracts for Ethereum and other blockchains, including Polygon. Using OpenZeppelin contracts for standard functionalities like ERC20 can significantly reduce the risk of vulnerabilities in your token contract.

Table 1: ERC20 Token Standard Functions

Relevant YouTube Videos:

Polygon Resources:

Verifying and Publishing Your Token

Once you deploy an ERC-20 token onto the Polygon network, there are two important things left: smart contract verification and public accessibility of your token. By verifying your code through block explorers such as PolygonScan, it would make more people trust your project by seeing what exactly lies beneath it. Conversely when you publish your token you actually submit it unto exchanges so that users can start trading with it.

Verifying Your Token on PolygonScan

  • Gather Your Contract’s Source Code: Ensure you have the exact version of your contract’s source code, including all dependencies.
  • Flatten Your Contract: If your contract uses imports, you’ll need to flatten it into a single file. Tools like Truffle Flattener can help with this process.
  • Access PolygonScan: Go to the PolygonScan website and find the contract verification section.
  • Fill in the Details: Provide all required information, including the contract address, name, and compiler details. Paste your flattened source code.
  • Verify and Publish: Submit the information. If everything matches, your contract will be verified, and the source code will be published on PolygonScan.

Publishing Your Token on Decentralized Exchanges (DEXs)

  • Choose a DEX: Select a DEX that supports Polygon, such as QuickSwap or SushiSwap.
  • Provide Liquidity: To enable trading, you need to provide liquidity. This usually involves depositing an equivalent value of your token and a base currency (like MATIC or USDC) into a liquidity pool.
  • List Your Token: Follow the specific DEX’s procedure to list your token. This might require interacting with the DEX’s smart contract or using their platform interface.

Additional Resources

For further reading and tools to assist in your ERC20 token creation journey on Polygon, consider exploring the following resources:

Creating an ERC20 token on Polygon is a task that combines technical skill with a deep understanding of the blockchain ecosystem. By following the steps outlined in this guide and following best practices for security and governance, you can successfully launch your token and contribute to the active Polygon community. Whether you aim to create a token for a decentralized finance (DeFi) project, a gaming platform, or another innovative application, Polygon’s scalable and efficient network offers a solid foundation for your digital asset.

Support our dedication to web3 and enjoy tasty rewards by staking with StakeBaby.

--

--

Ioannis Tsiokos
StakeBaby

I have nothing to say that’s nearly as cool as I am, except maybe… wow, I am dad!