# 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](https://doc.tryethernal.com/getting-started/cli) or [Hardhat plugin](https://doc.tryethernal.com/getting-started/hardhat-project-setup) 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](https://997528971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU0UuQSTIoh1QDp3u2I%2F-MU9UdiKk7JX3rOJrJWK%2F-MU9YwgWjeQ0YFQkGF_0%2FSG8KLrjWYR.gif?alt=media\&token=74e6a5fa-9d0a-4e21-9647-082932ecad4d)

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](https://997528971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU0UuQSTIoh1QDp3u2I%2F-MU9UdiKk7JX3rOJrJWK%2F-MU9h6PQvUXIjIVe2Iuh%2FScreen%20Shot%202021-02-22%20at%2018.03.54.png?alt=media\&token=ab2267ce-d10e-457b-9b85-3e535009ffa4)

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 %}
