NEP-17 is a Neo Improvement Proposal that defines a token standard for Neo smart contracts.
According to the NEP-17 standard a NEP-17 smart contract must have the following properties:
decimals
symbol
name
The standard actually calls them "methods", but for NEO•ONE smart contracts they will be public readonly properties which compile down to methods.
Let’s take a look at an example:
export class Token extends SmartContract {
public readonly name = 'Eon';
public readonly symbol = 'EON';
public readonly decimals = 8;
}
According to the NEP-17 standard a NEP-17 smart contract must have the following methods:
balanceOf
totalSupply
transfer
Let’s take a look at an example:
export class Token extends SmartContract {
@constant
public get totalSupply(): Fixed<8> {
return this.mutableSupply;
}
@constant
public balanceOf(address: Address): Fixed<8> {
const balance = this.balances.get(address);
return balance === undefined ? 0 : balance;
}
public transfer(from: Address, to: Address, amount: Fixed<8>): boolean {
// Sanity check that amount.
if (amount < 0) {
throw new Error(`Amount must be greater than 0: ${amount}`);
}
// Verify that the `from` `Address` has approved this call.
if (!Address.isCaller(from)) {
throw new Error('from Address did not approve the transfer');
}
// Sanity check that the `from` `Address` has enough balance
const fromBalance = this.balanceOf(from);
if (fromBalance < amount) {
throw new Error('From balance is insufficient');
}
// Update balances accordingly
const toBalance = this.balanceOf(to);
this.balances.set(from, fromBalance - amount);
this.balances.set(to, toBalance + amount);
return true;
}
}
According to the NEP-17 standard a NEP-17 smart contract must emit the following events:
Transfer
Let’s take a look at an example:
export class Token extends SmartContract {}
If all these criteria are met then the NEO•ONE compiler will produce a manifest with "NEP-17"
included in the supportedStandards
array.