In this tutorial, we'll explore how to create and deploy an ERC20 token on the Sepolia testnet using Solidity and Remix IDE. Designed for blockchain beginners, this guide requires only MetaMask and SepoliaETH to get started.
What Is an ERC20 Token?
ERC20 is a technical standard for fungible tokens on the Ethereum blockchain. These tokens are interchangeable, meaning each token holds the same value as another (unlike NFTs). Popular examples include Tether (USDT), Uniswap (UNI), and Aave (AAVE).
Key features:
- Standardized interoperability (works across wallets/DApps).
- Fungibility (1 token = 1 token).
- Customizable supply (fixed, capped, or uncapped).
Step 1: Designing the Smart Contract
We’ll use Remix IDE and OpenZeppelin’s ERC20 library for a secure, gas-efficient token.
1.1 Setting Up Remix
- Open Remix IDE.
- Create a new file (
token.sol) under File Explorer.
1.2 Writing the Contract
Paste this base code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("TokenName", "TKN") {
_mint(msg.sender, 10000 * 10 ** 18); // Mints 10,000 tokens
}
}Key Components:
pragma solidity: Compiler version.import: Pulls OpenZeppelin’s ERC20 template._mint(): Issues tokens tomsg.sender(your wallet).
👉 Learn more about OpenZeppelin contracts
1.3 Token Supply Models
Option A: Fixed Supply
Tokens are minted once (e.g., 10,000 TKN).
_mint(msg.sender, 10000 * 10 ** 18); // Fixed at deploymentOption B: Uncapped Lazy Supply
Tokens can be minted indefinitely.
function issueTokens(address receiver, uint256 amount) public {
_mint(receiver, amount);
}Option C: Capped Supply
Sets a hard cap (e.g., 1M TKN).
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
contract MyToken is ERC20Capped {
constructor(uint256 cap) ERC20("TokenName", "TKN") ERC20Capped(cap) {}
}1.4 Access Control
Restrict functions to the owner (you) using Ownable:
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor(address initialOwner) ERC20("TokenName", "TKN") Ownable(initialOwner) {}
function issueTokens() public onlyOwner { // Only deployer can mint
_mint(msg.sender, 10000 * 10 ** 18);
}
}Step 2: Deploying the Contract
- Compile: Click Solidity Compiler → Compile token.sol.
Deploy:
- Select Injected Provider (MetaMask).
- Connect your wallet (ensure SepoliaETH is available).
- Click Deploy and confirm in MetaMask.
Verify Deployment:
- Copy the contract address.
- In MetaMask: Import Token → Paste address.
FAQ
Q1: What’s the cost to deploy an ERC20 token?
A: On Sepolia, it’s free (testnet ETH). Mainnet costs depend on gas fees.
Q2: How do I add decimals to my token?
A: ERC20 defaults to 18 decimals (e.g., 100 * 10 ** 18 = 100.000000000000000000 TKN).
Q3: Can I update the token supply later?
A: No—fixed/capped supply is immutable. Use mintable contracts for flexibility.
Conclusion
You’ve now created and deployed an ERC20 token on Sepolia! For mainnet deployment, consider tools like Hardhat or Truffle.
👉 Explore advanced tokenomics designs
Need help? Drop questions below! 🚀