Token-Standard
Last updated
Last updated
Check standards source code here.
Why do we need a token standard? Simple because everything is a smart contract, your favorite token in this protocol is just your balance stored somewhere, I mean what else is money anyway. And to make a common interface for every smart contract which should behave like a token we use a token-standard. Like ERC-20 for example in Ethereum.
This means any contract which implements the necessary function is at the bare minimum a token. There can be more functionality on top, or some clever ways to implement the functions. The main thing, though, is that every dapp existing now or in the future can interact with your token / contract. To give a proper example: the AMM currently available operates with this standard in mind, therefore every token you create which has the token-standard functions, can be swapped at the AMM.
transfer(to: string, value: number)
this function transfers from the sender
to the to
the amount of value
. It should check to see if the sender
has enough balance.
transferFrom(from: string, to: string, value: number)
this behaves similar to the above. However, it is more powerful and allows every token interaction imaginable. Read here to see why it is necessary. Checks if the from
has given the sender
the allowance to transfer the token amount of value
out of his wallet to the to
wallet. Reduces the allowance
after successful transfer
approve(spender: string, value: number)
allows the spender
to transfer the token out of the sender
s wallet with the transferFrom
function
name() returns string
the name of the token
symbol() returns string
the symbol of the token
decimals() returns number
the number of decimals, because we only use integer values internally to prevent rounding errors
totalSupply() returns number
the current supply of tokens
balanceOf(owner: string) returns number
the balance of the owner
allowance(owner: string, spender: string) returns number
the allowance set by the owner
for the spender
Transfer(from, to, value)
logged when a transfer happened
Approval(owner, spender, value)
logged when an approval happened
TBA