Simple ERC-20 Token Code Example in Solidity (2026 Updated)
Creating an ERC-20 token on Ethereum is one of the most common ways to launch a crypto token. In 2026, the safest and most recommended method is using OpenZeppelin – an audited, battle-tested library used by thousands of projects.
⚡ Want to test a free AI tool right now?
Start Using AI →
Start Using AI →
This is a minimal, working example. It is for educational purposes only. Always test on testnet first and consider a professional audit before mainnet deployment.
Warning: Deploying tokens involves real money (gas fees) and legal responsibility. Many jurisdictions treat token sales as securities in 2026. Consult a lawyer and only use funds you can afford to lose.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
_mint(msg.sender, initialSupply * 10 ** decimals());
}
}
Code Explanation – Step by Step
- pragma solidity ^0.8.20; – Uses the latest stable Solidity version (2026 standard).
- import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; – Imports the secure ERC-20 implementation from OpenZeppelin.
- contract MyToken is ERC20 – Your token inherits all standard ERC-20 functions (transfer, approve, balanceOf, etc.).
- constructor – Runs once when deployed:
- Sets name to "MyToken" and symbol to "MTK"
- Mints the full initialSupply to the deployer (msg.sender)
- Multiplies by 10 ** decimals() (usually 18) for proper decimal handling
Why OpenZeppelin? It prevents common vulnerabilities (reentrancy, overflow) that have cost millions in the past. Never write ERC-20 from scratch.
How to Deploy This Example (Quick Overview)
- Go to remix.ethereum.org
- Create new file: MyToken.sol
- Paste the code above
- Compile with Solidity 0.8.20+
- In "Deploy" tab, enter initialSupply (e.g., 1000000 for 1 million tokens)
- Connect MetaMask and deploy on testnet first (Sepolia, Goerli)
- Once tested, deploy on mainnet (costs gas)
No-code alternatives: Tools like Smithii.io, CoinFactory, or TokenTool let you create ERC-20 tokens by filling forms – no coding required (cost ~0.01–0.05 ETH).
This example gives you full control but requires understanding. For real projects, add features like tax, burn, or pause – always using OpenZeppelin extensions.
Remember: Easy to create, hard to succeed. Focus on utility, community, and compliance in 2026.
Questions about the code? Ask in comments!
