Simple ERC-20 Token Code Example in Solidity (2026 Updated)

RH Editor
4 Min Read
Simple ERC-20 Token Code Example in Solidity (2026 Updated)

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 →

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.
ERC-20 token code example screenshot ERC-20 token tutorial screenshot OpenZeppelin ERC20 contract illustration
// 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.
OpenZeppelin tokens illustration Secure ERC20 tokens with OpenZeppelin Remix IDE screenshot for ERC20 deploy

How to Deploy This Example (Quick Overview)

  1. Go to remix.ethereum.org
  2. Create new file: MyToken.sol
  3. Paste the code above
  4. Compile with Solidity 0.8.20+
  5. In "Deploy" tab, enter initialSupply (e.g., 1000000 for 1 million tokens)
  6. Connect MetaMask and deploy on testnet first (Sepolia, Goerli)
  7. 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).
YouTube tutorial for ERC20 deploy in Remix Smart contract development 2026

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!

Share This Article
Yorum yapılmamış

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir