How to Impersonate any Address as a Simulation Sender
In some scenarios, you may want to simulate the transaction execution as if it was sent from an arbitrary address, even though in the real world you couldn’t. When a transaction is simulated via API, Tenderly doesn’t deal with signatures, so you can set any from value - you can even simulate sending transactions from another contract.
The way to achieve this is not as complicated, just send a transaction with any from address:
1
...
2
dotenv.config();
3
​
4
const SIMULATE_API = `https://api.tenderly.co/api/v1/account/${process.env.TENDERLY_USER}/project/${process.env.TENDERLY_PROJECT}/simulate`
5
​
6
const DAI_ADDRESS = "0x6b175474e89094c44da98b954eedeac495271d0f";
7
​
8
// tx data obtained using other means
9
const TX_DATA = const unsignedTx = await contract.populateTransaction[funcName](...args);
10
​
11
const transaction = {
12
network_id: '1',
13
from: "0x0000000000000000000000000000000000000000",
14
input: TX_DATA,
15
to: DAI_ADDRESS,
16
block_number: null,
17
// tenderly specific
18
save: true
19
}
20
​
21
const opts = {
22
headers: {
23
'X-Access-Key': process.env.TENDERLY_ACCESS_KEY || "",
24
}
25
}
26
const resp = await axios.post(SIMULATE_API, transaction, opts);
27
console.log(resp.data);
Copied!
Copy link