Class: EvmNative

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

Class: EvmNative

@moralisweb3/evm-utils.EvmNative

The EvmNative class is a MoralisData that references to a the value of a native currency (like ETH, BNB etc.)

Implements

  • MoralisData

Table of contents

Accessors

Methods

Accessors

ONE_ETH

Static get ONE_ETH(): EvmNative

Returns value of one ether.

Example

EvmNative.ONE_ETH

Returns

EvmNative


ONE_GWEI

Static get ONE_GWEI(): EvmNative

Returns value of one gwei.

Example

EvmNative.ONE_GWEI

Returns

EvmNative


ONE_WEI

Static get ONE_WEI(): EvmNative

Returns value of one wei.

Example

EvmNative.ONE_WEI

Returns

EvmNative


value

get value(): BigNumber

Example

native.value

Returns

BigNumber

the value of the EvmNative as a BigNumber


wei

get wei(): string

Converts the EvmNative to a string representation of the value in wei.

Example

native.wei

Returns

string

the value of the EvmNative as a string


gwei

get gwei(): string

Converts the EvmNative to a string representation of the value in gwei.

Example

native.gwei

Returns

string

the value of the EvmNative as a string


ether

get ether(): string

Converts the EvmNative to a string representation of the value in ether.

Example

native.ether

Returns

string

the value of the EvmNative as a string

Methods

create

Static create(native, unit?): EvmNative

Create a new instance of EvmNative from any valid EvmNativeish value.

Example

const native = EvmNative.create(2, 'gwei');
const native = EvmNative.create(2);
const native = EvmNative.create(2, 'wei');

Parameters

NameTypeDescription
nativeEvmNativeishthe value to create the EvmNative from
unit?UnitOrDecimalsthe unit of the value (optional), defaults to ether

Returns

EvmNative

a new instance of EvmNative


equals

Static equals(valueA, valueB): boolean

Compares two EvmNative values.

Example

EvmNative.equals(EvmNative.create(1, 'ether'), EvmNative.create(1, 'ether')); // true

Parameters

NameTypeDescription
valueAEvmNativeishthe first value to compare
valueBEvmNativeishthe second value to compare

Returns

boolean

true if the values are equal


equals

equals(value): boolean

Compares EvmNative with current instance.

Example

const native = EvmNative.create(1, 'gwei');
native.equals(EvmNative.create(1, 'ether')); // false

Parameters

NameTypeDescription
valueEvmNativethe value to compare with

Returns

boolean

true if the values are equal

Implementation of

MoralisData.equals


toString

toString(): string

Converts the EvmNative to a string.

Example

native.toString()

Returns

string

the value of the EvmNative as a string


format

format(): string

Converts the EvmNative to a string.

Example

native.format()

Returns

string

the value of the EvmNative as a string

Implementation of

MoralisData.format


Did this page help you?