Types

The following AssemblyScript types can be helpful in your smart contract journey without having to reinvent the wheel.

Note

You know a nugget that could be added to this list or you have a specific need for a new type? Open an issue to discuss about it!

Currency

A representation of a monetary unit used to express a value.

Usage

import {Currency} from 'mscl-type';

const euro = new Currency("Euro", 2);
const yen = new Currency("Japanese yen", 0);
const isSame = euro.sameAs(yen); // False

More info at module repository.

Amount

A representation of a value in a Currency.

Warning

Amount implements Valider as some operations, such as subtraction leading to a negative value, can result in an invalid Amount.

Usage

import {Currency} from 'mscl-type';
import {Amount} from 'mscl-type';

const euro = new Currency("Euro", 2);

const price = new Amount(500, euro);
const accountBalance = new Amount(100, euro);

cont isEnough = price.lessThan(accountBalance); // False
const isValidAmount = accountBalance.substract(price).isValid(); // False

More info at module repository.

Valider

An interface to unify how invalid types are handled.

Note

Then this is the only way to perform an action on a type and check later if the type is still valid.

Usage

import {Valider} from 'mscl-type';

export MyAwesomeType implements Valider {
    ...
    isValid():bool {
        // check if the type is still valid
    }
}
...

More info at module repository.