> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-console/contracts/units.md).

# Units

The decimals that turn your contracts' raw integers into amounts you can read.

A unit tells you how many decimals sit behind an on-chain amount. On its own, `5000000000000000000` means nothing. With 18 decimals, it reads as `5.0`.

BaaS keeps those decimals for you, so the Console shows amounts you can read, and accepts the ones you type.

## Where units appear

* [Reading a function](/baas-console/contracts/read-and-write.md#read-a-value) shows the formatted amount, with a badge to switch back to the raw integer.
* [Writing a function](/baas-console/contracts/read-and-write.md#smart-unit-amounts) lets you type `12.5` and sends the raw integer for you.
* The [Explorer](/baas-console/contracts/explorer.md) formats stored values and event amounts the same way.
* A [monitor trigger](/baas-console/automations/triggers/monitor.md) hands your automation both forms of the amount. An amount whose unit depends on a token id, as on an ERC-6909, arrives raw.
* The [BaaS SDK](/baas-sdk/blockchain/smart-units.md) does the same in your app, sending amounts with `SmartUnits('12.5')` and reading them back formatted.

{% hint style="info" %}
**Switching Smart unit clears the field.** The same digits mean a different amount in each mode.
{% endhint %}

Every formatted amount comes in the same shape, raw value included:

```json
{
  "raw": "5000000000000000000",
  "formatted": "5.0",
  "metadata": { "encoding": "units", "decimals": "18" }
}
```

{% hint style="info" %}
**Raw on the chain, formatted on the screen.** BaaS stores and sends the integer your contract expects. Decimals only shape what you read and what you type.
{% endhint %}

## Where units come from

Units belong to an ABI version, like [mappings](/baas-console/contracts/mappings.md). Each new version gets its own set when you register it:

* By default, BaaS detects the [automatic units](/baas-console/contracts/units/automatic-units.md) of the token standards it recognizes.
* To decide them yourself, declare a [template of your own](/baas-console/contracts/units/custom-units.md) in the Add Contract panel.

Decimals are never assumed. A contract that exposes no way to read them gets no unit, and its values stay raw until you declare one yourself.

## When decimals are read

Decimals that depend on an argument, such as a token id, are known once that id has been seen: until then its values show raw and a decimal amount for it is refused, so type the raw integer.

{% hint style="info" %}
**A value that cannot be formatted appears raw.** An amount that cannot be converted is refused.
{% endhint %}

## Next

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Automatic units</strong></td><td>The decimals BaaS detects for ERC-20, ERC-4626, and ERC-6909 tokens.</td><td><a href="/baas-console/contracts/units/automatic-units.md">Automatic units</a></td></tr><tr><td><strong>Custom units</strong></td><td>Declare your own decimals, fixed or read from a contract.</td><td><a href="/baas-console/contracts/units/custom-units.md">Custom units</a></td></tr></tbody></table>
