> 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/mappings.md).

# Mappings

Read your contracts' on-chain values from BaaS, refreshed as their events arrive.

A mapping is one rule: when an event fires, call a view function and store the result under a data key.

```
Transfer → read balanceOf(event.from) + balanceOf(event.to) → store as balance
```

BaaS runs these rules for you, so your project reads stored values instead of calling the chain itself.

## The four shapes

A mapping's shape comes from the arguments its getter takes:

| Getter                                   | Shape              | What it keeps                         |
| ---------------------------------------- | ------------------ | ------------------------------------- |
| `totalSupply()`                          | Deployment-wide    | One value for the contract            |
| `balanceOf(address account)`             | Per wallet         | One value per user                    |
| `totalSupply(uint256 id)`                | Keyed              | One value per key, such as a token id |
| `balanceOf(address account, uint256 id)` | Per wallet and key | One value per user, per key           |

A value without a wallet shows in the [Explorer](/baas-console/contracts/explorer.md#contract-data), and a value per wallet shows on the [Users](/baas-console/users.md) page.

## Set at registration

Mappings belong to an ABI version. Each new version gets its set when you register it:

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

## The Mappings viewer

The **Mappings** button on a class card shows the rules of its latest version, and its badge counts them. Previous versions keep their own button under **Previous ABI versions**.

Each rule states the events that refresh it, the call it makes, and the data key it stores, with badges for its shape: **Per wallet** or **Deployment-wide**, plus **Keyed** for one value per key. An **Immutable** badge marks a rule that declares no event. Click a rule for a sample of the value it produces.

## When values appear

* Deployment-wide values are read when you register the deployment.
* Per wallet and keyed values fill in as events name their wallet or key.
* Events are recorded for every address, user or not. When such an address signs in for the first time, its values are read then.

{% hint style="info" %}
**Values are read as of the event's block.**
{% endhint %}

{% hint style="info" %}
**No backfill.** BaaS keeps values from the moment you register a deployment. Events emitted before that stay on-chain and are not replayed.
{% 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 mappings</strong></td><td>The mappings BaaS sets up for ERC-20, ERC-721, and ERC-1155 tokens.</td><td><a href="/baas-console/contracts/mappings/automatic-mappings.md">Automatic mappings</a></td></tr><tr><td><strong>Custom mappings</strong></td><td>Write your own template to replace the automatic set.</td><td><a href="/baas-console/contracts/mappings/custom-mappings.md">Custom mappings</a></td></tr></tbody></table>
