From 70e014c88a219cd20361ae1ac87d7fe599005458 Mon Sep 17 00:00:00 2001 From: borus-dev Date: Thu, 29 Jun 2023 15:24:04 +0200 Subject: [PATCH] docs: improved impersonating on fork documentation --- ...nate-any-address-as-a-simulation-sender.md | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/simulations-and-forks/reference/tenderly-fork-customization-via-api/how-to-impersonate-any-address-as-a-simulation-sender.md b/simulations-and-forks/reference/tenderly-fork-customization-via-api/how-to-impersonate-any-address-as-a-simulation-sender.md index cd57fc5..d0e3c13 100644 --- a/simulations-and-forks/reference/tenderly-fork-customization-via-api/how-to-impersonate-any-address-as-a-simulation-sender.md +++ b/simulations-and-forks/reference/tenderly-fork-customization-via-api/how-to-impersonate-any-address-as-a-simulation-sender.md @@ -11,19 +11,23 @@ To achieve this, just send a transaction with any `from` address: ```tsx ... dotenv.config(); -const { TENDERLY_USER, TENDERLY_PROJECT, TENDERLY_ACCESS_KEY } = process.env; +const { TENDERLY_USER, TENDERLY_PROJECT, TENDERLY_ACCESS_KEY, TENDERLY_FORK_ID } = process.env; -const SIMULATE_API = `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/simulate` +const SIMULATE_API = `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/fork/${TENDERLY_FORK_ID}/simulate`; + +const provider = new ethers.providers.JsonRpcProvider(process.env.TENDERLY_FORK_URL); const DAI_ADDRESS = "0x6b175474e89094c44da98b954eedeac495271d0f"; -// tx data obtained using other means -const TX_DATA = await contract.populateTransaction[funcName](...args); +// DAI contract instance +const dai = ERC20__factory.connect(DAI_ADDRESS, provider); + +const TX_DATA = await dai.populateTransaction[funcName](...args); const transaction = { network_id: '1', from: "0x0000000000000000000000000000000000000000", - input: TX_DATA, + input: TX_DATA.data, to: DAI_ADDRESS, block_number: null, // tenderly specific @@ -32,9 +36,16 @@ const transaction = { const opts = { headers: { - 'X-Access-Key': process.env.TENDERLY_ACCESS_KEY || "", + "content-type": "application/JSON", + 'X-Access-Key': TENDERLY_ACCESS_KEY || "", } } -const resp = await axios.post(SIMULATE_API, transaction, opts); -console.log(resp.data); + +try { + const resp = await axios.post(SIMULATE_API, transaction, opts); + console.log(resp.data); +} catch (err: any) { + console.log(err.response.data.error); +} + ```