# @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

```javascript
import utils from "@compass/utils";
```

### API Reference

#### `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)`

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)`

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)`

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()`

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:

```javascript
import utils from "@compass/utils";

export default async function() {
    const value = '1.5';
    const parsedEther = utils.parseEther(value);
    return { parsedEther };
}
```

To parse a decimal value to a specific unit:

```javascript
import utils from "@compass/utils";

export default async function() {
    const value = '1000';
    const unit = 'wei';
    const parsedUnits = utils.parseUnits(value, unit);
    return { parsedUnits };
}
```

To format a BigNumber to a decimal value:

```javascript
import utils from "@compass/utils";

export default async function() {
    const value = '1.5';
    const formattedEther = utils.formatEther(value);
    return { formattedEther };
}
```

To format a BigNumber to a specific unit:

```javascript
import utils from "@compass/utils";

export default async function() {
    const value = '1000';
    const unit = 'wei';
    const formattedUnits = utils.formatUnits(value, unit);
    return { formattedUnits };
}
```

To get the current gas fee data:

```javascript
import utils from "@compass/utils";

export default async function() {
    const feeData = await utils.getFeeData();
    return { feeData };
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.compass.art/automations/custom-actions/compass-utils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
