Reading variables

Decode your contract's variables

This feature needs contracts AST upload, which is disabled by default. To learn how to activate it check the CLI or Hardhat plugin doc.

Decoding variables works using the Truffle Decoder 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

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.

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.

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.

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.

Last updated