simulation_type API 参数允许您控制 Simulation API 返回结果的详细程度。它同时适用于单笔模拟和捆绑请求。
模拟类型
full(默认):包含调用追踪、函数输入与输出、状态差异等的详细原始与解码信息。quick:最少的原始值。abi:包含解码后的输入、输出和日志的最少信息。
Full 模拟会花费更多时间,具体取决于调用追踪的深度。当您不需要解码信息时,请使用 quick 模拟。
Full 模拟模式
- 调用追踪,包含函数名、在源文件中的位置、调用者地址及余额
- 解码后的函数输入与输出,所有参数附带 soltype。这适用于所有函数调用,包括来自 EOA 的对智能合约的直接调用、智能合约之间的内部调用,以及每个智能合约内部的函数调用。
- 解码后的状态差异(对状态的更改),修改的字段附带 soltype
- 解码后的日志(事件),包括产生它们的 Solidity event 和事件参数的值,每一项附带 type。
request.ts
dotenv.config();
const approveDai = async () => {
// assuming environment variables TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG and TENDERLY_ACCESS_KEY are set
// https://docs.tenderly.co/platform/account/projects/slug
// https://docs.tenderly.co/platform/account/projects/api-tokens
const { TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG, TENDERLY_ACCESS_KEY } = process.env;
console.time('Simulation');
const resp = await axios.post(
`https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate`,
// the transaction
{
/* Simulation Configuration */
save: false, // if true simulation is saved and shows up in the dashboard
save_if_fails: false, // if true, reverting simulations show up in the dashboard
simulation_type: 'full', // full, abi or quick (full is default)
network_id: '1', // network to simulate on
/* Standard EVM Transaction object */
from: '0xdc6bdc37b2714ee601734cf55a05625c9e512461',
to: '0x6b175474e89094c44da98b954eedeac495271d0f',
input: '0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b',
gas: 8000000,
value: 0,
},
{
headers: {
'X-Access-Key': TENDERLY_ACCESS_KEY as string,
},
},
);
console.timeEnd('Simulation');
const transaction = resp.data.transaction;
console.log(JSON.stringify(transaction, null, 2));
};
approveDai();
Quick 模拟模式
提供未经额外解码的原始数据。当您仅需要交易的基本详情时,此模式最为合适。request.ts
dotenv.config();
const approveDai = async () => {
// assuming environment variables TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG and TENDERLY_ACCESS_KEY are set
// https://docs.tenderly.co/platform/account/projects/slug
// https://docs.tenderly.co/platform/account/projects/api-tokens
const { TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG, TENDERLY_ACCESS_KEY } = process.env;
console.time('Simulation');
const resp = await axios.post(
`https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate`,
// the transaction
{
/* Simulation Configuration */
save: false, // if true simulation is saved and shows up in the dashboard
save_if_fails: false, // if true, reverting simulations show up in the dashboard
simulation_type: 'quick', // full, abi or quick (full is default)
network_id: '1', // network to simulate on
/* Standard EVM Transaction object */
from: '0xdc6bdc37b2714ee601734cf55a05625c9e512461',
to: '0x6b175474e89094c44da98b954eedeac495271d0f',
input: '0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b',
gas: 8000000,
value: 0,
},
{
headers: {
'X-Access-Key': TENDERLY_ACCESS_KEY as string,
},
},
);
console.timeEnd('Simulation');
const transaction = resp.data.transaction;
console.log(JSON.stringify(transaction, null, 2));
};
approveDai();
ABI 模拟模式
调用追踪,包含函数名、解码后的输入与输出变量。 解码后的日志(事件),包括产生它们的 Solidity event 和事件参数的值,每一项附带 type 描述。request.ts
dotenv.config();
const approveDai = async () => {
// assuming environment variables TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG and TENDERLY_ACCESS_KEY are set
// https://docs.tenderly.co/platform/account/projects/slug
// https://docs.tenderly.co/platform/account/projects/api-tokens
const { TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG, TENDERLY_ACCESS_KEY } = process.env;
console.time('Simulation');
const resp = await axios.post(
`https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate`,
// the transaction
{
/* Simulation Configuration */
save: false, // if true simulation is saved and shows up in the dashboard
save_if_fails: false, // if true, reverting simulations show up in the dashboard
simulation_type: 'abi', // full, abi or quick (full is default)
network_id: '1', // network to simulate on
/* Standard EVM Transaction object */
from: '0xdc6bdc37b2714ee601734cf55a05625c9e512461',
to: '0x6b175474e89094c44da98b954eedeac495271d0f',
input: '0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b',
gas: 8000000,
value: 0,
},
{
headers: {
'X-Access-Key': TENDERLY_ACCESS_KEY as string,
},
},
);
console.timeEnd('Simulation');
const transaction = resp.data.transaction;
console.log(JSON.stringify(transaction, null, 2));
};
approveDai();