- BEP-20: Tokens on Binance Smart Chain
This BEP proposes an interface standard to create token contracts on Binance Smart Chain.
The following standard defines the implementation of APIs for token smart contracts. It is proposed by deriving the ERC20 protocol of Ethereum and provides the basic functionality to transfer tokens, allow tokens to be approved so they can be spent by another on-chain third party, and transfer between Binance Chain and Binance Smart Chain.
A standard interface allows any tokens on Binance Smart Chain to be used by other applications: from wallets to decentralized exchanges in a consistent way. Besides, this standard interface also extends ERC20 to facilitate cross chain transfer.
This BEP is under draft.
NOTES:
- The following specifications use syntax from Solidity 0.5.16 (or above)
- Callers MUST handle false from returns (bool success). Callers MUST NOT assume that false is never returned!
function name() public view returns (string)
- 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 symbol() public view returns (string)
- Returns the symbol of the token. E.g. “HIX”.
- This method can be used to improve usability
- NOTE - This method is optional in EIP20. In BEP20, this is a required method. Tokens which don’t implement this method will never flow across the Binance Chain and Binance Smart Chain.
function decimals() public view returns (uint8)
- Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.
- This method can be used to improve usability
- NOTE - This method is optional in EIP20. In BEP20, this is a required method. Tokens which don’t implement this method will never flow across the Binance Chain and Binance Smart Chain.
function totalSupply() public view returns (uint256)
- Returns the total token supply. If the token will flow across the Binance Chain and Binance Smart Chain, the number should be the total of circulation across 2 blockchains.
function balanceOf(address _owner) public view returns (uint256 balance)
- Returns the account balance of another account with address
_owner
.
function getOwner() external view returns (address);
- Returns the bep20 token owner which is necessary for binding with bep2 token.
- NOTE - This is an extended method of EIP20. Tokens which don’t implement this method will never flow across the Binance Chain and Binance Smart Chain.
function transfer(address _to, uint256 _value) public returns (bool success)
- 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 transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
- 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 approve(address _spender, uint256 _value) public returns (bool success)
- 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 allowance(address _owner, address _spender) public view returns (uint256 remaining)
- Returns the amount which
_spender
is still allowed to withdraw from_owner
.
event Transfer(address indexed _from, address indexed _to, uint256 _value)
- 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 Approval(address indexed _owner, address indexed _spender, uint256 _value)
MUST trigger on any successful call to approve(address _spender, uint256 _value)
.
There are already plenty of BEP20-compliant tokens deployed on the Binance Smart Chain network. Different implementations have been written by various teams that have different trade-offs: from gas saving to improved security. Example implementations are available at Binance Implementation
The content is licensed under CC0.