How to Change Storage Values on a Fork
Migrate to Virtual TestNets
Virtual TestNets are publicly available!
For new projects, we recommend starting with TestNets.
For automatic migration of Forks to TestNets, .
For new projects, we recommend starting with TestNets.
For automatic migration of Forks to TestNets, .
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 it using this Tenderly Sandbox.
example.tsx
...
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
contractAddress,
two32BHexStr,
fiftyFive32BHexStr,
]);
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.