How to Change Storage Values on a Fork
This call allows you to change any storage slot of any contract, within the boundary of the Tenderly Fork you're working with.
If you want to simulate a transaction in a very specific state of the involved contract(s), there are two ways to do it.
  • You can execute several transactions to get them in the desired state.
  • Alternatively, you can plant a specific value into one or more storage slots of your Smart Contract(s).
If you decide to go with the second option, you need to use tenderly_setStorageAt JSON-RPC call.
This is a custom JSON-RPC call that is applicable only for Tenderly Forks.
Hereโ€™s an example. You can play around with this using this Tenderly Sandbox.
const forkRpcUrl = ...;
const provider = new ethers.providers.JsonRpcProvider(forkRpcUrl);
const two32BHexStr = ethers.utils.hexZeroPad(ethers.utils.hexValue(2), 32);
const fiftyFive32BHexStr = ethers.utils.hexZeroPad(ethers.utils.hexValue(55), 32);
await provider.send("tenderly_setStorageAt", [
// the contract address
const newValue = await fork.provider.getStorageAt(greeter.address, 2);
The first parameter is the contract address, the second is the storage slot, and the third is the value we want to set. The last two parameters have to be a string representation of a 32-byte number.
Copy link