Skip to main content
State overrides allow you to customize the network state for the purpose of your simulation. This feature is useful when you need to test scenarios under conditions that aren’t currently present on the live network. To apply the same overrides through the dashboard instead of the API, see state overrides in the Simulator UI. To illustrate how state overrides work, let’s use the DAI stablecoin contract. In the DAI system, certain actions, like minting new DAI tokens, can only be performed by addresses designated as wards. If your address isn’t a ward, you can’t test minting operations.

Setting up as a ward through state overrides

To simulate a transaction where we mint DAI, we need to override the state to make our address appear as a ward. We need to adjust the wards map in the DAI contract to include our address with the necessary permissions. To be able to mint, the sender of the transaction must be a ward. In other words, the following condition must hold: wards['0xe2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2'] == 1. In the API request, assign a map of overrides to the state_objects object. This map points to specific storage locations in the smart contract and assigns new values for the simulation.
  • DAI contract address: 0x6b175474e89094c44da98b954eedeac495271d0f
  • Storage slot location: 0xedd7d04419e9c48ceb6055956cbb4e2091ae310313a4d1fa7cbcfe7561616e03
  • Override value: 0x0000000000000000000000000000000000000000000000000000000000000001
example.json
The script below shows how to set the overrides and send a request to Simulation API. Make sure to have TENDERLY_ACCOUNT_SLUG and TENDERLY_ACCESS_KEY set as environment variables. Learn how to obtain the slug and access key.
example.ts

Storage Slot Calculation

The key part of setting an override is calculating the correct storage location. This depends on the structure of the contract’s storage and the specific variable you want to override. For the DAI contract, the storage location for the wards mapping for our address is calculated based on the Solidity storage layout rules, and is given by this expression:
example.js
In our example, the storage location is: 0xedd7d04419e9c48ceb6055956cbb4e2091ae310313a4d1fa7cbcfe7561616e03.

Explore

How to override Gnosis Safe contracts