ERC-20

ERC-20

ERC-20 是基于以太坊网络的标准代币发行协议。有了 ERC-20,开发者可以以高效、可靠和低成本的创造属于自己的代币。

ERC-20 协议

一组 token 的标准接口。
标准接口允许以太坊上的任何代币被其他应用程序重复使用:从钱包到去中心化交易所。
以下标准允许在智能合约中实现令牌的标准 API。该标准提供了转移代币的基本功能,并允许代币获得批准,以便由另一个链上第三方使用。

Method

name

Returns the name of the token - e.g. MyToken.

OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

function name() public view returns (string)
symbol

Returns the symbol of the token. E.g. HIX.

OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

function symbol() public view returns (string)
decimals

Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.

OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

function decimals() public view returns (uint8)
totalSupply

Returns the total token supply.

function totalSupply() public view returns (uint256)
balanceOf

Returns the account balance of another account with address _owner.

function balanceOf(address _owner) public view returns (uint256 balance)
transfer

Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend.

Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.

function transfer(address _to, uint256 _value) public returns (bool success)
transferFrom

Transfers _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.

The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw unless the _from account has deliberately authorized the sender of the message via some mechanism.

Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
approve

Allows _spender to withdraw from your account multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.

NOTE: To prevent attack vectors like the one described here and discussed here, clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. THOUGH The contract itself shouldn’t enforce it, to allow backwards compatibility with contracts deployed before

function approve(address _spender, uint256 _value) public returns (bool success)
allowance

Returns the amount which _spender is still allowed to withdraw from _owner.

function allowance(address _owner, address _spender) public view returns (uint256 remaining)

Events

Transfer

MUST trigger when tokens are transferred, including zero value transfers.

A token contract which creates new tokens SHOULD trigger a Transfer event with the _from address set to 0x0 when tokens are created.

event Transfer(address indexed _from, address indexed _to, uint256 _value)
 Approval

MUST trigger on any successful call to approve(address _spender, uint256 _value).

event Approval(address indexed _owner, address indexed _spender, uint256 _value)

ERC-20 例子

ERC-20 的应用案例

为了让你对 ERC-20 有更具象化的认识,这里援引 Alyssa HertigWhat is the ERC-20 Ethereum Token Standard? 中列举的一些比较知名的基于ERC-20协议代币:

Tether (USDT)
Chainlink (LINK)
Binance coin (BNB)
USD coin (USDC)
Wrapped bitcoin (WBTC)
Dai (DAI)

参考

ERC-20 具体内容
什么是ERC-20?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值