Skip to main content

Class: EvmNative

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

Class: EvmNative

@moralisweb3/common-evm-utils.EvmNative

The EvmNative class is a MoralisData that references to the value of an EVM 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


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


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


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

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
nativeEvmNativeInputthe 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
valueAEvmNativeInputthe first value to compare
valueBEvmNativeInputthe second value to compare

Returns

boolean

true if the values are equal


fromJSON

Static fromJSON(json): EvmNative

Parameters

NameType
jsonstring

Returns

EvmNative


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


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(): string

Returns

string


toString

toString(): string

Converts the EvmNative to a string.

Example

native.toString()

Returns

string

the value of the EvmNative as a string