NEXUS

ERC-20 Interface

ERC-20 is the standard interface for implementing fungible tokens on the Ethereum network. IERC20 defines the required functions and events that compliant contracts must implement. This interface is provided by OpenZeppelin, a widely-used, secure smart contract library.


Events

Transfer

 event Transfer(address indexed from, address indexed to, uint256 value);
  • Triggered when tokens are transferred from from to to.
  • value indicates the number of tokens transferred.
  • value can be zero.

Approval

 event Approval(address indexed owner, address indexed spender, uint256 value);
  • Triggered when owner sets an allowance for spender.
  • value is the new approved amount.

Functions

totalSupply

 function totalSupply() external view returns (uint256);
  • Returns the total number of tokens in existence.

balanceOf

 function balanceOf(address account) external view returns (uint256);
  • Returns the number of tokens owned by account.

transfer

 function transfer(address to, uint256 value) external returns (bool);
  • Transfers value tokens from the caller to address to.
  • Returns true if successful.
  • Emits a Transfer event.

allowance

 function allowance(address owner, address spender) external view returns (uint256);
  • Returns the remaining number of tokens that spender is allowed to spend on behalf of owner.

approve

 function approve(address spender, uint256 value) external returns (bool);
  • Sets value as the allowance of spender over the caller's tokens.
  • Returns true if successful.
  • Emits an Approval event.

🔒 Note: Modifying allowances via approve() may lead to race conditions. A safer pattern is:

approve(spender, 0);
approve(spender, newValue);

transferFrom

function transferFrom(address from, address to, uint256 value) external returns (bool);
  • Transfers value tokens from from to to using the allowance mechanism.
  • The caller must have an allowance approved by from.
  • Returns true if successful.
  • Emits a Transfer event.

References


This document provides a quick reference to the ERC-20 interface for developers implementing or interacting with ERC-20 tokens. For full functionality and customization, refer to actual implementation contracts.


© 2025 NEXUS Co., Ltd. All Rights Reserved.