| title | Token Standard | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| actions |
|
||||||||
| material |
|
Ideally, once a developer knows how to use one token in NEO's network, they shouldn't have to learn to use any other token in NEO. That is the purpose of NEP-5. It is a "token standard for the NEO blockchain that will provide systems with a generalized interaction mechanism for tokenized Smart Contracts". All tokens in the network should ideally follow this standard for ease of use.
NEP-5 standardized tokens should provide the following methods:
name ()- returns the name of the token. e.g. "MyToken".symbol ()- returns a short string symbol of the token managed in this contract. e.g. "MYT".decimals ()- returns the number of decimals used by the token - e.g.decimals (8)means to divide the token amount by 10^8 (100,000,000) to get its user representation. For tokens that do not subdivide, the method should return 0.totalSupply ()- returns the total token supply deployed in the system.balanceOf ()- returns the token balance of the account.transfer ()- transfers an amount of tokens from the from account to the to account.
It also has a standardized transfer event:
transferevent triggers when the method of the same name is invoked.
Since balanceOf () and transfer () require more complex operations, we will have dedicated chapters for them later in the lesson.
Tag: C# Basics
There is a shorthand in C# to shortern method bodies into a single line. It is called an expression body definition. It can be useful for methods that contain very simpe operations. For example,
public static string FullName (string fName, string lName) => fName + lName; is an expression body definition of:
public static string FullName (string fName, string lName) {
return fName + lName;
}- Implement four methods by following the method definitions on the NEP-5 standard page (they were provided for you in the editor). Use the => operator for all four methods.
- The token will be called "Alien", with "ALI" as its symbol.
- Aliens are non-divisible.
- Total supply can be obtained from a method we have previously written.