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
Name | Type | Description |
---|---|---|
value | Erc20Valueish | The value to create |
options? | Erc20Options | The options for the token |
Returns
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
Name | Type | Description |
---|---|---|
valueA | Erc20Valueish | The first value to compare |
valueB | Erc20Valueish | The second value to compare |
Returns
boolean
True if the values are equal
parse
▸ Static
parse(«destructured»
): Erc20ValueData
Parameters
Name | Type |
---|---|
«destructured» | Object |
› amount | BigNumberInput |
› decimals | Erc20ValueInputDecimals |
› token? | Erc20Tokenish |
Returns
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
Name | Type | Description |
---|---|---|
value | Erc20Valueish | The 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
Name | Type |
---|---|
amount | BigNumberInput |
options? | Erc20Options |