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
ONE_GWEI
• Static
get
ONE_GWEI(): EvmNative
Returns value of one gwei.
Example
EvmNative.ONE_GWEI
Returns
ONE_WEI
• Static
get
ONE_WEI(): EvmNative
Returns value of one wei.
Example
EvmNative.ONE_WEI
Returns
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
Name | Type | Description |
---|---|---|
native | EvmNativeInput | the value to create the EvmNative from |
unit? | UnitOrDecimals | the unit of the value (optional), defaults to ether |
Returns
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
Name | Type | Description |
---|---|---|
valueA | EvmNativeInput | the first value to compare |
valueB | EvmNativeInput | the second value to compare |
Returns
boolean
true if the values are equal
fromJSON
▸ Static
fromJSON(json
): EvmNative
Parameters
Name | Type |
---|---|
json | string |
Returns
equals
▸ equals(value
): boolean
Compares EvmNative with current instance.
Example
const native = EvmNative.create(1, 'gwei');
native.equals(EvmNative.create(1, 'ether')); // false
Parameters
Name | Type | Description |
---|---|---|
value | EvmNative | the 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