Skip to main content

Class: Erc20Value

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

Class: Erc20Value

@moralisweb3/common-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

Constructors

Methods

create

Static create(value, options?): Erc20Value

Create a new instance of Erc20Value from any valid input

Example

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

Throws

CoreError 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


parse

Static parse(«destructured»): Erc20ValueData

Parameters

NameType
«destructured»Object
› amountBigNumberInput
› decimalsErc20ValueInputDecimals
› token?Erc20Tokenish

Returns

Erc20ValueData


display

display(): string

Displays the token in text format

Example

value.display();

Returns

string

the value and also the token symbol if available


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


format

format(): string

Deprecated

This method will be removed soon. To format the value, use one of the properties.

Returns

string

Implementation of

MoralisData.format


toJSON

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

Displays the token in JSON format

Example

value.toJSON();

Returns

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

the value and also the token if available


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

Accessors

amount

get amount(): BigNumber

Example

value.amount; // BigNumber

Returns

BigNumber

the token amount


decimals

get decimals(): number

Example

value.decimals; // 15

Returns

number

the token decimals


token

get token(): null | Erc20Token

Example

value.token; // Erc20Token

Returns

null | Erc20Token

the token


value

get value(): string

Example

value.value; // "1000"

Returns

string

the token value

Constructors

constructor

new Erc20Value(amount, options?)

Parameters

NameType
amountBigNumberInput
options?Erc20Options