# `OpenPayments.Types.Amount`
[🔗](https://github.com/interledger/open-payments-elixir/blob/v1.0.0/lib/open_payments/types/amount.ex#L1)

A monetary amount in the smallest units of its asset.

`value` is a decimal string from `"0"` through `"18446744073709551615"`.
`asset_scale` is an integer from 0 through 255. For example, a value of
`"1000"` with asset code `"USD"` and scale `2` represents USD 10.00.

`new/3` and `from_map/1` validate input without coercing numbers or changing
asset codes. Additional JSON fields are retained in `extensions`, as permitted
by the amount schema. JSON encoding uses the protocol's `assetCode` and
`assetScale` field names.

Struct literals can bypass constructor checks. Call `validate/1` before using
a manually constructed or modified amount; `to_map/1` only converts its shape.

# `t`

```elixir
@type t() :: %OpenPayments.Types.Amount{
  asset_code: String.t(),
  asset_scale: 0..255,
  extensions: %{optional(String.t()) =&gt; term()},
  value: String.t()
}
```

# `from_map`

```elixir
@spec from_map(map()) :: {:ok, t()} | {:error, OpenPayments.Error.t()}
```

Decodes a string-keyed JSON object and retains additional fields.

# `new`

```elixir
@spec new(String.t(), String.t(), integer()) ::
  {:ok, t()} | {:error, OpenPayments.Error.t()}
```

Constructs and validates an amount, keeping the supplied decimal string.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Converts an amount to its JSON field names without validating it.

# `validate`

```elixir
@spec validate(t()) :: :ok | {:error, OpenPayments.Error.t()}
```

Checks a struct against the shared amount contract.

---

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