Loading...
You never write ERC-20 from scratch in production. You inherit OpenZeppelin's audited base and customize.
The ERC-20 standard is deceptively simple — transfers, approvals, allowances. But getting it right (no reentrancy, correct event emission, zero-address checks, overflow protection) is where tokens get hacked. OpenZeppelin Contracts is the most-audited codebase in DeFi. Use it.
solidity// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract MyToken is ERC20 { constructor(uint256 initialSupply) ERC20("MyToken", "MTK") { _mint(msg.sender, initialSupply); } }
transfer, transferFrom, approve, allowance, balanceOf, totalSupply, name, symbol, decimalsTransfer and Approval events_mint, _burn, _update)ERC20Burnable — adds public burnERC20Pausable — emergency pauseERC20Permit — gasless approvals (EIP-2612)ERC20Capped — hard supply capWrite KraftyToken with 1,000,000 initial supply minted to the deployer, symbol KFT, inheriting from OpenZeppelin's ERC20.