Class: Erc20Value

moralis-monorepo / @moralisweb3/evm-utils / Erc20Value

Class: Erc20Value

@moralisweb3/evm-utils.Erc20Value

The Erc20Value class is a MoralisData that references to a the value of an Erc20Token
It holds data about the data about the amount of tokens and the number of decimals.

Implements

  • MoralisData

Table of contents

Methods

Accessors

Methods

create

Static create(value, options?): Erc20Value

Create a new instance of Erc20Value from any valid input

Example

Erc20Value.create(1000, { decimals: 3 });

Throws

MoralisCoreError if the value is invalid

Parameters

NameTypeDescription
valueErc20ValueishThe value to create
options?Erc20OptionsThe options for the token

Returns

Erc20Value

The created value


equals

Static equals(valueA, valueB): boolean

Compares two Erc20Valueish instances.

Example

const valueA = Erc20Value.create(1000, { decimals: 3 });
const valueB = Erc20Value.create(10000, { decimals: 4 });
Erc20Value.equals(valueA, valueB); // true

Parameters

NameTypeDescription
valueAErc20ValueishThe first value to compare
valueBErc20ValueishThe second value to compare

Returns

boolean

True if the values are equal


equals

equals(value): boolean

Compares Erc20Value with current instance.

Example

value.equals(valueA);

Parameters

NameTypeDescription
valueErc20ValueishThe value to compare

Returns

boolean

True if the values are equal

Implementation of

MoralisData.equals


toNumber

toNumber(): number

Convert the value to a number

Example

value.toNumber();

Returns

number

the value in number format


toString

toString(): string

Convert the value to a string

Example

value.toString();

Returns

string

the value in string format


display

display(): string

Displays the token in text format

Example

value.display();

Returns

string

the value and also the token symbol if available


format

format(): string

Convert the value to a string

Example

value.format();

Returns

string

the value in string format

Implementation of

MoralisData.format


toJSON

toJSON(): { value: string ; token: { contractAddress: string ; chain: string | number ; decimals: number ; name: string ; symbol: string ; logo?: null | string ; logoHash?: null | string ; thumbnail?: null | string } } | { token: undefined ; value: string }

Displays the token in JSON format

Example

value.toJSON();

Returns

{ value: string ; token: { contractAddress: string ; chain: string | number ; decimals: number ; name: string ; symbol: string ; logo?: null | string ; logoHash?: null | string ; thumbnail?: null | string } } | { token: undefined ; value: string }

the value and also the token if available

Accessors

decimals

get decimals(): number

Example

value.decimals; // 15

Returns

number

the token decimals


amount

get amount(): BigNumber

Example

value.amount; // BigNumber

Returns

BigNumber

the token amount


value

get value(): string

Example

value.value; // "1000"

Returns

string

the token value


token

get token(): null | Erc20Token

Example

value.token; // Erc20Token

Returns

null | Erc20Token

the token


Did this page help you?