ERC-20 대체 가능 토큰 표준
교환 가능한 토큰을 만들기 위한 ERC-20 표준의 사양과 기능을 이해합니다.
ERC-20 대체 가능 토큰 표준은(는) CoddyKit의 무료 Blockchain Smart Contracts with Solidity 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Blockchain Smart Contracts with Solidity 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Blockchain Smart Contracts with Solidity 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Intro to Blockchain Tokens
Welcome to the world of blockchain tokens! Beyond cryptocurrencies like Ether, blockchains host many other digital assets.
These assets, often called 'tokens', can represent anything from digital currency to ownership of real-world items, or even voting rights in a decentralized organization.
Fungibility: Interchangeable Assets
A key concept for tokens is fungibility. What does it mean?
- Fungible: Each unit is identical and interchangeable with another. Like a dollar bill – one $1 bill is the same as any other $1 bill.
- Non-Fungible: Each unit is unique and cannot be replaced by another. Like a piece of art or a specific house.
ERC-20 tokens are fungible, meaning every token is equal to every other token of the same type.
Meet the ERC-20 Standard
ERC-20 (Ethereum Request for Comment 20) is a technical standard for fungible tokens on the Ethereum blockchain.
It defines a common set of rules that all compliant tokens must follow. This ensures they can interact seamlessly with wallets, exchanges, and other smart contracts.
Interoperability Through Standards
Why is a standard so important?
- Compatibility: Any wallet that supports ERC-20 can manage any ERC-20 token.
- Ecosystem Growth: Decentralized applications (dApps) can easily integrate different tokens.
- Predictable Behavior: Developers know exactly how an ERC-20 token will behave, making integration safer and faster.
Core Function: `totalSupply()`
The totalSupply() function returns the total number of tokens in existence. It's a public view function, meaning it doesn't change the blockchain state and costs no gas to call.
Try running this simple contract to see how totalSupply might be represented:
pragma solidity ^0.8.0;
contract SimpleTokenInfo {
uint256 public totalTokens = 1000; // Example supply
function totalSupply() public view returns (uint256) {
return totalTokens;
}
}Core Function: `balanceOf()`
The balanceOf(address account) function returns the token balance of a specific address. It helps you check how many tokens a user owns.
Let's add balanceOf to our example. The deployer will start with all tokens.
pragma solidity ^0.8.0;
contract SimpleTokenInfo {
uint256 public totalTokens = 1000;
mapping(address => uint256) public balances;
constructor() {
balances[msg.sender] = totalTokens; // Assign all to deployer
}
function totalSupply() public view returns (uint256) {
return totalTokens;
}
function balanceOf(address account) public view returns (uint256) {
return balances[account];
}
}Core Function: `transfer()`
The transfer(address recipient, uint256 amount) function allows the sender of the transaction to send tokens directly to another address.
This is the most common way to move tokens between users.
pragma solidity ^0.8.0;
contract SimpleTokenInfo {
uint256 public totalTokens = 1000;
mapping(address => uint256) public balances;
constructor() {
balances[msg.sender] = totalTokens;
}
function totalSupply() public view returns (uint256) {
return totalTokens;
}
function balanceOf(address account) public view returns (uint256) {
return balances[account];
}
function transfer(address recipient, uint256 amount) public returns (bool) {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
balances[recipient] += amount;
return true;
}
}Delegated Transfers: `approve()` & `allowance()`
ERC-20 also supports delegated transfers, where one user (the owner) allows another address (the spender) to move tokens on their behalf.
approve(address spender, uint256 amount): The owner grants permission to a spender to withdraw a specificamountof tokens.allowance(address owner, address spender): Returns the amount of tokens that thespenderis currently allowed to withdraw from theowner.
Executing Delegated Transfers: `transferFrom()`
Once an approve() call has been made, the designated spender can then use the transferFrom() function.
transferFrom(address sender, address recipient, uint256 amount): Allows a spender to transfer amount tokens from the sender's balance to the recipient, provided the spender has enough allowance from the sender.
Tracking Actions: ERC-20 Events
ERC-20 defines two standard events: Transfer and Approval. These events are crucial for off-chain applications (like wallets or block explorers) to track token movements and approvals without having to read the entire blockchain state.
They emit logs that can be efficiently indexed and queried.
pragma solidity ^0.8.0;
contract EventExample {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function demonstrateTransferEvent(address _to, uint256 _value) public {
// Imagine actual transfer logic here
emit Transfer(msg.sender, _to, _value);
}
function demonstrateApprovalEvent(address _spender, uint256 _value) public {
// Imagine actual approval logic here
emit Approval(msg.sender, _spender, _value);
}
}Check Your Understanding
The ERC-20 standard outlines specific functions that all compliant tokens must implement. Understanding these is crucial for working with tokens.
ERC-20: Your Token Blueprint
You've now learned about the ERC-20 Fungible Token Standard! It's the blueprint for most interchangeable tokens on Ethereum.
- It defines core functions like
totalSupply(),balanceOf(), andtransfer(). - It enables delegated transfers with
approve(),allowance(), andtransferFrom(). - Standard events
TransferandApprovalhelp track token activity.
This standard ensures that all ERC-20 tokens are compatible, making the Ethereum ecosystem robust and easy to navigate. Next, we'll dive into implementing your own ERC-20 token!
자주 묻는 질문
“ERC-20 대체 가능 토큰 표준” 강의는 무료인가요?
네 — “ERC-20 대체 가능 토큰 표준” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Blockchain Smart Contracts with Solidity 강의 전체를 잠금 해제할 수 있습니다. Blockchain Smart Contracts with Solidity 강의에는 총 4개의 강의가 포함되어 있습니다.
“ERC-20 대체 가능 토큰 표준”에서 뭘 배우나요?
교환 가능한 토큰을 만들기 위한 ERC-20 표준의 사양과 기능을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Blockchain Smart Contracts with Solidity을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Blockchain Smart Contracts with Solidity을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Blockchain Smart Contracts with Solidity은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“ERC-20 대체 가능 토큰 표준” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Blockchain Smart Contracts with Solidity 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Blockchain Smart Contracts with Solidity 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- ERC-20 대체 가능 토큰 표준
- ERC-20 토큰 구현
- ERC-721 대체 불가능 토큰(NFT)
- ERC-1155 멀티 토큰 표준