ERC-20
ERC20¶
ERC20 is one of the most commonly used fungible token standards on the Ethereum blockchain. It defines a set of common interfaces that make creating and managing tokens on the Ethereum blockchain simple and standardized. The standardized common interfaces provide interoperability for ecosystem applications including wallets, exchanges, and dApps, allowing tokens to be easily traded and used across various platforms.
ERC20 Main Interfaces and Events¶
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
- totalSupply: Returns the total supply of tokens.
- balanceOf: Returns the token balance of a specified address.
- transfer: Transfers a specified amount of tokens from the caller's account to another account.
- approve: Allows another account to spend a specified amount of tokens.
- transferFrom: Transfers a specified amount of tokens from one account to another (requires prior approval via approve).
- allowance: Returns the amount of tokens an authorized account is allowed to spend.
ERC20 Token Contract Example¶
Below is a simple ERC20 token contract example based on OpenZeppelin code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor() ERC20("MyToken", "MTK") {
// Initial mint: mint 1000 tokens to the contract deployer
_mint(msg.sender, 1000 * 10 ** decimals());
}
// Function to mint new tokens
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
The above contract example demonstrates how to implement these interfaces. Developers can extend and modify the contract according to specific requirements to build their own tokens. By following the ERC20 standard, you can ensure broad interoperability and compatibility of tokens within the Ethereum ecosystem.
Notable Tokens¶
The following are some well-known tokens on the Ethereum blockchain that use the ERC-20 standard:
- Tether (USDT): Tether is a stablecoin pegged to the US dollar, widely used in the cryptocurrency market for trading and as a stable store of value. Website: tether.to
- USD Coin (USDC): USDC is another stablecoin pegged to the US dollar, managed by the Centre consortium, which includes Circle and Coinbase. Website: centre.io/usdc
- Chainlink (LINK): A decentralized oracle network that provides real-world data to smart contracts on the blockchain. Website: chain.link
- Uniswap (UNI): Uniswap is a decentralized exchange (DEX) protocol built on Ethereum. The UNI token is used for governance and liquidity incentives. Website: uniswap.org
- Wrapped Bitcoin (WBTC): WBTC is an ERC-20 token on the Ethereum blockchain that represents Bitcoin (BTC). Each WBTC is backed 1:1 by Bitcoin. Website: wbtc.network
- Dai (DAI): A decentralized stablecoin soft-pegged to the US dollar, backed by other cryptocurrencies as collateral on the MakerDAO platform. Website: makerdao.com
- Aave (AAVE): AAVE is the native token of the Aave protocol, a decentralized lending platform. Website: aave.com
- COMP: COMP is the governance token of the Compound protocol, a decentralized money market platform that allows users to lend and borrow cryptocurrencies. Website: compound.finance