ERC-20 tokens are a fundamental component of transactions on EVM-compatible blockchains and Layer 2 networks. In this tutorial, you'll learn how to create an ERC-20 token on Polygon, a cost-effective Layer 2 EVM blockchain compared to Ethereum's mainnet.
What Is an ERC-20 Token?
ERC-20 tokens represent "something" on a blockchain. They are fungible—meaning interchangeable. Unlike non-fungible tokens (NFTs), which are unique and non-interchangeable, ERC-20 tokens focus on quantity rather than individuality.
Developing on Polygon
As networks like Ethereum grow busier, gas prices rise, and transaction confirmation times lengthen. Scaling solutions like the Polygon PoS network offer developers a way to avoid these issues. Let’s explore Polygon, its advantages, and how to get started.
What Is Polygon?
Polygon refers to more than just the PoS chain—it’s a protocol and framework for building and connecting Ethereum-compatible blockchains. For example, Polygon Hermez is a ZK rollup for payments.
Originally named Matic, Polygon’s legacy lives on through its native token: MATIC.
Is Polygon PoS a Layer 2?
While Polygon PoS provides Layer 2 benefits, it’s technically a sidechain with checkpointing capabilities on Ethereum’s mainnet. Unlike rollups, Polygon PoS operates as an independent chain with its own security.
Advantages of Polygon PoS
- EVM-compatible: Deploy the same contracts as Ethereum.
- Speed: Processes up to 65,000 transactions per second.
- Low fees: Significantly cheaper than Ethereum.
Bridging Between Chains
Use the Polygon Bridge to move assets from Ethereum to Polygon. This process wraps your assets (e.g., ETH becomes POS-WETH) for use on Polygon.
👉 Learn more about bridging assets
Step-by-Step Tutorial
Prerequisites
Tools:
- Remix IDE
- Brave Wallet (or MetaMask)
- OpenZeppelin
Testnet:
Connect to Polygon Mumbai
Wallet Setup:
- Network Name:
Polygon Mumbai Testnet - RPC URL:
https://rpc-mumbai.maticvigil.com - Chain ID:
80001 - Currency Symbol:
MATIC - Block Explorer:
https://mumbai.polygonscan.com
- Network Name:
Get Test MATIC:
- Use the Polygon Faucet to request MATIC.
Build the ERC-20 Contract
Open Remix:
- Create a new file:
PolyCoin.sol.
- Create a new file:
Code:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract PolyCoin is ERC20 { constructor() ERC20("PolyCoin", "PLYCN") { _mint(msg.sender, 1000 * 10 ** decimals()); } }Key Details:
decimals()defaults to 18 (for divisibility).- Tokens minted:
1000 * 10^18.
Deploy to Mumbai
- Environment: Switch to
Injected Web3(ensure your wallet is connected). - Deploy: Select
PolyCoinand confirm the transaction. - Verify: Check the contract address on PolygonScan.
👉 Explore advanced ERC-20 features
Next Steps
- Deploy to Polygon Mainnet.
- Add functionalities: minting, burning, or governance (via OpenZeppelin).
- Integrate Chainlink Price Feeds for DeFi compatibility.
FAQs
1. What’s the cost difference between Polygon and Ethereum?
Polygon’s fees are a fraction of Ethereum’s—often less than $0.01 per transaction.
2. Can I use MetaMask with Polygon?
Yes! Add the Polygon network via Chainlist or manually.
3. How do I get real MATIC for mainnet?
Buy MATIC on exchanges like OKX and transfer it to your wallet.
4. What’s the transaction speed on Polygon?
Transactions typically confirm in 2–5 seconds.
5. Are ERC-20 tokens cross-chain?
Not natively, but bridges (like Polygon’s) enable cross-chain transfers.
6. Can I customize token supply later?
Yes—modify the constructor to allow dynamic minting/burning.