Simple ERC-20 Token Code Example in Solidity (2026 Updated)
Creating an ERC-20 token on the Ethereum blockchain is one of the most popular ways to launch a fungible cryptocurrency token. In 2026, the landscape has matured significantly, with stricter regulations and better tools, but the core process remains accessible to developers and enthusiasts alike. The safest and most widely recommended approach is using the OpenZeppelin library – a collection of audited, battle-tested smart contracts used by thousands of projects worldwide, including major DeFi protocols.
Start Using AI →
This comprehensive guide provides a minimal, fully functional ERC-20 token code example, detailed line-by-line explanation, deployment instructions, and important warnings. It is designed for educational purposes only. Whether you're learning blockchain development or exploring side projects, understanding ERC-20 is essential.
The Complete ERC-20 Token Code Example
Here is the minimal, production-ready ERC-20 token code using OpenZeppelin Contracts v5 (latest in 2026):
This code is only 15 lines but creates a fully compliant ERC-20 token with all standard functions (transfer, approve, transferFrom, allowance, balanceOf, totalSupply).
Line-by-Line Code Explanation
- // SPDX-License-Identifier: MIT – Declares the license (standard practice for open-source contracts).
- pragma solidity ^0.8.20; – Specifies the Solidity compiler version. ^0.8.20 means any version from 0.8.20 upward (current stable in 2026).
- import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; – Imports the audited ERC20 base contract from OpenZeppelin. This single line gives you all the secure ERC-20 functionality.
- contract MyToken is ERC20 – Defines your token contract and inherits all ERC-20 features from OpenZeppelin's implementation.
- constructor(uint256 initialSupply) ERC20("MyToken", "MTK") – The constructor runs once when the contract is deployed:
- Calls the parent ERC20 constructor to set name ("MyToken") and symbol ("MTK")
- You can change these to anything (e.g., "RichCoin", "RICH")
- _mint(msg.sender, initialSupply * 10 ** decimals()); – Creates (mints) all tokens and sends them to the deployer (msg.sender). Multiplies by 10**decimals() because ERC-20 uses 18 decimals by default (like Ether).
How to Test and Deploy This Token (Step-by-Step)
- Use Remix IDE – Go to remix.ethereum.org (free, browser-based).
- Create a new file named
MyToken.sol. - Paste the full code above.
- Compile using Solidity version 0.8.20 or higher.
- In the "Deploy & Run Transactions" tab:
- Environment: Injected Provider (MetaMask)
- Connect your wallet
- Enter initialSupply (e.g., 1000000 for 1 million tokens)
- First test on Sepolia or Holesky testnet (free fake ETH from faucets).
- Once verified, deploy on Ethereum mainnet (costs gas – around $50–$200 in 2026 depending on network congestion).
No-Code Alternatives in 2026
If coding isn't your thing, several platforms allow ERC-20 creation without writing a single line:
- Smithii Tools – Form-based creator, costs ~0.01 ETH
- CoinFactory – Advanced features like tax, burn, anti-bot
- TokenTool – Simple interface with metadata upload
These tools still use OpenZeppelin under the hood and are suitable for quick testing.
Advanced Features You Can Add (Optional)
Once comfortable with the basic version, extend your token using OpenZeppelin extensions:
- Burnable – Allow token holders to burn (destroy) tokens
- Pausable – Emergency stop for transfers
- Snapshot – For governance voting
- Taxes/Fees – Automatic fees on transfers (popular in meme tokens)
All available in OpenZeppelin Contracts library – just import and inherit.
Final Thoughts and Recommendations for 2026
Technical creation of an ERC-20 token is now easier than ever, but success depends on utility, community, marketing, and compliance. In 2026, regulators are watching closely – transparency and legal compliance are more important than ever.
Whether you're learning blockchain development or exploring ideas, start on testnet, understand every line of code, and prioritize security. The blockchain space rewards those who build responsibly.
Have questions about this code or deployment? Drop them in the comments below!
