---
eip: 20
label: ERC-20
title: Token Standard
status: Final
type: Standards Track
category: ERC
created: 2015-11-19
official: https://eips.ethereum.org/EIPS/eip-20
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-20.md
canonical: https://eips.huatuo.xyz/ko/eip-20/
lang: ko
tldr: 이더리움의 모든 대체 가능 토큰이 구현하는 표준 인터페이스. 지갑, 거래소, 컨트랙트가 같은 여섯 개 함수로 어떤 토큰이든 다룰 수 있게 한다.
tags: [token, fungible, standard, defi]
---

# ERC-20: Token Standard

> A standard interface for tokens.

**TL;DR:** 이더리움의 모든 대체 가능 토큰이 구현하는 표준 인터페이스. 지갑, 거래소, 컨트랙트가 같은 여섯 개 함수로 어떤 토큰이든 다룰 수 있게 한다.

## 어떤 문제를 해결하나요?

2015년에는 토큰을 발행하는 프로젝트마다 자기만의 함수 이름으로 컨트랙트를 작성했습니다. 지갑이나 거래소는 토큰마다 수작업으로 연동해야 했고, 스마트 컨트랙트는 "아무 토큰이나" 결제 수단으로 받을 수 없었습니다.

ERC-20은 작은 인터페이스 하나를 정의해 이 문제를 해결합니다. 컨트랙트가 이를 구현하면 ERC-20을 이미 지원하는 모든 도구가 첫날부터 동작합니다. 이더리움과 EVM 체인의 대체 가능 토큰(USDC, DAI, UNI, Wrapped ETH 등)은 사실상 모두 ERC-20입니다.

## 어떻게 동작하나요?

토큰 컨트랙트는 주소별 잔액을 보관하고 다음 함수를 노출합니다.

| 함수 | 역할 |
| --- | --- |
| `totalSupply()` | 전체 발행량 |
| `balanceOf(owner)` | 특정 주소의 잔액 |
| `transfer(to, value)` | 호출자에서 `to`로 전송 |
| `approve(spender, value)` | `spender`가 호출자 계정에서 최대 `value`까지 인출하도록 허용 |
| `allowance(owner, spender)` | `spender`가 아직 인출할 수 있는 양 |
| `transferFrom(from, to, value)` | 미리 허용된 한도(allowance)를 사용해 전송 |

`Transfer`와 `Approval` 두 이벤트 덕분에 인덱서와 지갑은 스토리지를 읽지 않고도 잔액을 추적할 수 있습니다. `name()`, `symbol()`, `decimals()`는 선택적 메타데이터이며 `decimals`는 보통 18입니다.

`approve` / `transferFrom` 조합이 바로 DEX나 대출 프로토콜이 여러분의 계정에서 토큰을 가져가는 방식입니다. 프로토콜을 한 번 승인하면, 이후 필요할 때 프로토콜이 `transferFrom`을 호출합니다.

## 샘플 코드

최소 인터페이스와 아주 작은 토큰(접근 제어 없음, 설명용):

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    function totalSupply() external view returns (uint256);
    function balanceOf(address owner) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function approve(address spender, uint256 value) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

contract MiniToken is IERC20 {
    string public name = "Mini";
    string public symbol = "MINI";
    uint8 public decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor(uint256 supply) {
        totalSupply = supply;
        balanceOf[msg.sender] = supply;
        emit Transfer(address(0), msg.sender, supply);
    }

    function transfer(address to, uint256 value) external returns (bool) {
        return _move(msg.sender, to, value);
    }

    function approve(address spender, uint256 value) external returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) external returns (bool) {
        uint256 allowed = allowance[from][msg.sender];
        require(allowed >= value, "allowance");
        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - value;
        return _move(from, to, value);
    }

    function _move(address from, address to, uint256 value) internal returns (bool) {
        require(balanceOf[from] >= value, "balance");
        balanceOf[from] -= value;
        balanceOf[to] += value;
        emit Transfer(from, to, value);
        return true;
    }
}
```

JavaScript에서 잔액 읽기(ethers v6):

```ts
import { Contract, JsonRpcProvider, formatUnits } from "ethers";

const provider = new JsonRpcProvider("https://eth.llamarpc.com");
const usdc = new Contract(
  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  ["function balanceOf(address) view returns (uint256)", "function decimals() view returns (uint8)"],
  provider,
);
const [raw, decimals] = await Promise.all([usdc.balanceOf(someAddress), usdc.decimals()]);
console.log(formatUnits(raw, decimals)); // "1234.56"
```

## 알아둘 점

- 일부 오래된 토큰(특히 USDT)은 `transfer`가 `bool`을 반환하지 않습니다. 토큰을 직접 호출하지 말고 OpenZeppelin의 `SafeERC20` 같은 래퍼를 사용하세요.
- allowance를 0이 아닌 값에서 다른 0이 아닌 값으로 바꾸는 데에는 알려진 경쟁 조건이 있습니다. 먼저 0으로 설정하거나 `increaseAllowance` 류의 헬퍼를 쓰는 것이 일반적입니다.
- "무한 승인"(`type(uint256).max`)은 편리하지만 해당 토큰에 대한 무제한 접근을 프로토콜에 넘기는 것입니다. [ERC-2612](/eip-2612/)의 `permit`이나 [ERC-7758](/eip-7758/) 같은 가스리스 대안은 allowance 패턴 자체를 피합니다.
- 프로덕션에서는 위 샘플 대신 감사를 거친 구현(OpenZeppelin `ERC20`)에서 시작하세요.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-20
