NEO•ONE provides mixins for common smart contract patterns.
This guide will walk you through how to use a mixin.
Install the following packages if you have not done so:
Important
The package
@neo-one/smart-contract-lib
contains the mixins and is important to this guide.
A mixin is a class (abstract or non-abstract) in which some or all of its methods and/or properties are unimplemented.
We use mixin as a way to insert common properties and methods (sometimes required such as in the case of meeting a token standard) into your contract.
Tip
You can think of our mixins as a template or a base where you can build your contracts on.
If you find the syntax NEP5Token(SmartContract)
strange, checkout this page on Mixins from the TypeScript Handbook for more details.
Tip
We encourage you to look at the NEP5Token mixin to understand how we are implementing a NEP5 token. Go here to see the source code for the NEP5Token mixin
The following example set uses a mixin to design a new token that follows the NEP5 token standard.
Note
A token standard simply defines a set of methods and properties that must exist in the token.
SimpleToken.ts
SimpleToken is injected with NEP5Token
's methods and properties.
Redtoken.ts
RedToken
inherits methods and properties that adheres to the NEP5 token standard because of the mixin. It also inherits everything defined in SimpleToken
.
this.ownerOnly()
; to the beginning of all public functions will throw an error anytime an address other than the primary makes requests.this.primaryOnly()
; to the beginning of all public functions will throw an error anytime an address other than the primary makes requests.