
- The ERC-20(Ethereum Request for Comments 20) is a Token Standard that implements an API for tokens within Smart Contracts.
- Ethereum 블록체인을 사용하여 생성된 대체 가능한 토큰에 대해 구현된 표준이다. ERC-20은 다른 스마트 계약 토큰과 상호 교환할 수 있도록 이더리움 블록체인에서 새로운 토큰 생성을 가이드한다.
openzeppelin ERC20 코드 뜯어보기
// 인출 허용량 ; 더블매핑
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
//approve를 실행하면 spender에게 amount만큼 허락해줌
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true; //아웃풋값이 없으면 트레킹이 힘드니까 편하게 확인하려고 true설정
}
//approve된 컨트랙트가 내가 돈을 줘야하는 사람에게 (내)돈을 전달해줌
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
//추가적으로 allowance 더 증가
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
//approve allowance를 0으로 만듦
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique. 👉 코드 뜯어 보기
ERC1155 is a novel token standard that aims to take the best from previous standards to create a fungibility-agnostic and gas-efficient token contract. ERC1155 draws ideas from all of ERC20, ERC721, and ERC777. 👉 코드 뜯어 보기
ERC165 is a standard to detect and publish what interfaces a smart contract implements.
openzeppelin의 ERC코드는 필수적인 요소 외에도 사용하기 편한 기능들이 많이 포함되어 있다.