# `Cartouche.Wei`
[🔗](https://github.com/zenhive/cartouche/blob/main/lib/cartouche/wei.ex#L1)

Conversions between Ethereum denominations and wei.

Supports bare non-negative integer inputs (treated as wei), integer `:wei`,
integer `:gwei`, and integer or `Decimal` `:eth` inputs. `:eth` is the only
ETH-denomination atom accepted; `:ether` is not supported so callers use the
same short form as `:wei` and `:gwei`.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `maybe_to_wei` | 1 | Convert an optional fee amount to wei, passing through nil. | `amount: value` |
| `to_wei` | 1 | Convert an Ethereum-denominated amount into wei. | `amount: value` |

# `maybe_to_wei`

```elixir
@spec maybe_to_wei(non_neg_integer() | {non_neg_integer(), :wei | :gwei} | nil) ::
  non_neg_integer() | nil
```

Converts an optional fee amount to wei, passing through `nil`.

## Examples

    iex> Cartouche.Wei.maybe_to_wei(nil)
    nil

    iex> Cartouche.Wei.maybe_to_wei({1, :gwei})
    1000000000

# `to_wei`

```elixir
@spec to_wei(
  non_neg_integer()
  | {non_neg_integer(), :wei | :gwei | :eth}
  | {Decimal.t(), :eth}
) ::
  non_neg_integer()
```

Converts a number to wei, possibly from gwei or eth.

## Examples

    iex> Cartouche.Wei.to_wei(100)
    100

    iex> Cartouche.Wei.to_wei({100, :gwei})
    100000000000

    iex> Cartouche.Wei.to_wei({1, :eth})
    1000000000000000000

---

*Consult [api-reference.md](api-reference.md) for complete listing*
