TEMPLATES

ERC-20 TOKEN

Fungible token standard for creating currencies and utility tokens.

OVERVIEW

ERC-20 is the most widely adopted token standard on Ethereum and EVM-compatible chains. It defines a common interface for fungible tokens, enabling interoperability with wallets, exchanges, and DeFi protocols.

TEMPLATE FEATURES

Mintable

Owner can create new tokens

Burnable

Holders can destroy their tokens

Pausable

Owner can pause transfers in emergencies

Ownable

Single owner with administrative rights

SOURCE CODE

Token.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, ERC20Burnable, ERC20Pausable, Ownable {
    constructor(
        string memory name,
        string memory symbol,
        uint256 initialSupply
    ) ERC20(name, symbol) Ownable(msg.sender) {
        _mint(msg.sender, initialSupply * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function _update(
        address from,
        address to,
        uint256 value
    ) internal override(ERC20, ERC20Pausable) {
        super._update(from, to, value);
    }
}

KEY FUNCTIONS

FunctionDescription
transfer(to, amount)Send tokens to an address
approve(spender, amount)Allow spender to use tokens
transferFrom(from, to, amount)Transfer from allowed account
mint(to, amount)Create new tokens (owner only)
burn(amount)Destroy your tokens

NEXT STEPS