# Reading variables

{% hint style="warning" %}
This feature needs contracts AST upload, which is disabled by default. To learn how to activate it check the [CLI](/getting-started/cli.md) or [Hardhat plugin](/getting-started/hardhat-project-setup.md) doc.
{% endhint %}

Decoding variables works using the [Truffle Decoder](https://www.trufflesuite.com/docs/truffle/codec/modules/_truffle_decoder.html) package.

The first section of this tab will show all the decodable variables and their types.

To decode a variable, it first needs to be watched.\
\
By default, all variables that are declared in the contract **except for mappings** are watched and will be decoded automatically.

For mappings, you need to specify the key that you want to watch.

Let's take the following smart contract as an example

```javascript
contract Store {
    mapping(address => uint256) public values;
    uint256 latest;
    Transaction[] history;
    
    struct Transaction {
        address from;
        address to;
        uint256 amount;
    }
}
```

In this case, when a transaction arrives `latest` and `history` will be decoded automatically.

In the case of `history`, the struct will be decoded as well.

For `values`, you need to explicitly tell which keys you want to watch using the "+" button next to the name of the variable.

It is possible to watch nested mappings. You just need to specify the key at each nesting level until you arrive at a non-mapping variable.

![Adding keys to mappings](/files/-MU9YwgWjeQ0YFQkGF_0)

Below this section, you will find the list of transactions. Clicking on a transaction will show in a panel all the values for the watched variables, as well as the function signature, its params, and emitted events.

![Example with the variables of the above contract](/files/-MU9h6PQvUXIjIVe2Iuh)

You can re-decode the transaction, by clicking on the circling arrow icon on the top right of the "Data" section. It can be useful if you just added a new key to track and want to see its value in past blocks.

{% hint style="warning" %}
The AST is necessary for this feature to work. It is uploaded by the CLI and the Hardhat plugin. However, for free users, it's deleted from the database after 1 week in order to save space. Data that has been decoded stays available on the transaction page though.
{% endhint %}


---

# 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://doc.tryethernal.com/dashboard-pages/contracts/reading-variables.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.
