@compass/utils
This package provides utility functions for handling Ether values. The functions are bound from the ethers.js
package and are used to parse and format Ether and unit values as well as get the current gas fee data.
Usage
API Reference
utils.parseEther(value: string)
utils.parseEther(value: string)
Parse a decimal value to a BigNumber.
value
(required, string): The value to parse.
Returns a string representation of the BigNumber.
utils.parseUnits(value: string, unit: string)
utils.parseUnits(value: string, unit: string)
Parse a decimal value to a BigNumber.
value
(required, string): The value to parse.unit
(required, string): The unit to parse the value to.
Returns a string representation of the BigNumber.
utils.formatEther(value: string)
utils.formatEther(value: string)
Format a BigNumber to a decimal value.
value
(required, string): The value to format.
Returns a string representation of the formatted value.
utils.formatUnits(value: string, unit: string)
utils.formatUnits(value: string, unit: string)
Format a BigNumber to a decimal value.
value
(required, string): The value to format.unit
(required, string): The unit to format the value to.
Returns a string representation of the formatted value.
utils.getFeeData()
utils.getFeeData()
Get the current gas fee data.
Returns a Promise that resolves with an object containing gasPrice
, maxFeePerGas
, and maxPriorityFeePerGas
.
Examples
To parse a decimal value to a BigNumber:
To parse a decimal value to a specific unit:
To format a BigNumber to a decimal value:
To format a BigNumber to a specific unit:
To get the current gas fee data:
Last updated