> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 常见问题：Simulations

> 关于 Tenderly 模拟的常见问题解答：Dashboard 可见性、API 与 RPC、状态覆盖、gas 估算和速率限制。

<div className="flex flex-col gap-4 mt-8">
  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-see-simulations-in-dashboard" className="text-xl font-semibold">我可以在 Dashboard 中看到模拟吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        Dashboard 会显示您通过 Simulator UI、Simulation API（将 `save` 或 `save_if_fails` 设置为 `true`）执行的模拟。RPC 模拟不会被持久化，也不会显示在 Dashboard 中。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-delete-a-simulation" className="text-xl font-semibold">我可以删除某个模拟吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        不可以，模拟无法被删除。如有其他疑问，请随时通过 [support@tenderly.co](mailto:support@tenderly.co) 联系
        支持团队。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="does-running-the-same-simulation-multiple-times-co" className="text-xl font-semibold">多次运行相同的模拟与运行一次费用相同吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        不相同——即使您发送完全相同的负载来模拟相同的交易多次，每次对 simulate 端点的 API 调用都会被计为一次单独的请求。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-advance-a-block-number-timestamp-in-a-simula" className="text-xl font-semibold">我可以在模拟中推进区块高度/时间戳吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        可以，您可以使用 [Increase block](/simulator-ui/parameters#increase-block) 和 [Override timestamp](/simulator-ui/parameters#override-timestamp) cheatcode 在模拟中推进区块高度或时间戳。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-simulate-transactions-on-behalf-of-a-user-wi" className="text-xl font-semibold">我可以在没有用户私钥的情况下代表他们模拟交易吗？换句话说，我可以模拟来自任意地址的交易吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        在模拟中，所有地址默认都是解锁的。这意味着您可以模拟来自任意地址到任意地址的交易。

        在此了解更多关于[在开发和测试期间如何使用 Transaction
        Simulator](/simulations/quickstart)。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="what-is-the-difference-between-api-and-rpc-simulat" className="text-xl font-semibold">API 与 RPC 模拟有何区别？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        API 模拟通过 [Simulation API](/api-reference#/operations/simulateTransaction) 端点发起，而 RPC 模拟通过 [**`tenderly_simulateTransaction`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_simulateTransaction) RPC 方法发起。

        通过将 `save` 或 `save_if_fails` 设置为 `true`，API 模拟可以保存到 Dashboard。RPC 模拟不会保存到 Dashboard。

        API 和 RPC 模拟都提供相同的模拟结果，包括交易详情、调用追踪、日志和余额变化。
        是的，您可以使用状态覆盖来修改合约存储变量、账户余额以及模拟中的其他链上数据。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="which-rate-limits-are-applied-for-api-simulations" className="text-xl font-semibold">对 API 模拟应用了哪些速率限制？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        API 模拟受速率限制约束。如需讨论速率限制或为您的账户申请更高的配额，请[联系我们的销售团队](https://tenderly.co/contact-us)。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="what-is-the-correct-format-of-a-tuple-when-simulat" className="text-xl font-semibold">通过 Dashboard 模拟交易时，tuple 的正确格式是什么？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        tuple 的格式为 JSON。以下是一个 tuple 的示例：

        ```json filename="example.json" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        {
          "tokenIn": "0x3Df2f692132f55b97cc9DA04A1fFFEA82F511333",
          "tokenOut": "0x31254874432f55b97cc9DA04A1fFFEA82F5d7122",
          "fee": 100,
          "recipient": "0x3D555552132f55b97cc9DA04A1fFFEA82F5d7122",
          "deadline": 1630403200,
          "amountIn": 10000,
          "amountOutMinimum": 9000,
          "sqrtPriceLimitX96": 7894561250
        }
        ```
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-test-the-effects-of-a-token-transfer-bef" className="text-xl font-semibold">如何在部署智能合约之前测试代币转账的效果？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/single-simulations"

        您可以通过使用 Simulation API 运行单笔模拟来模拟代币转账。这将允许您在部署前验证代币在地址之间的流动，并确保合约逻辑正确。

        [了解更多 →](/simulations/single-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-integrate-tenderly-simulations-into-the" className="text-xl font-semibold">如何将 Tenderly 模拟集成到 UI 中，为用户预览交易结果？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/overview"

        您可以将 Tenderly 的 [Simulation API](/simulations/overview) 或 [Simulation RPC](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_simulateTransaction) 集成到您的 dApp UI 中，通过调用该 API 模拟交易，并在用户确认之前向他们展示由此产生的状态变化、资产流动和 gas 估算。

        [了解更多 →](/simulations/overview)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-simulate-contract-interactions-that-involve" className="text-xl font-semibold">我可以模拟涉及多个外部智能合约的合约交互吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/bundled-simulations"

        可以，捆绑模拟允许您在一次模拟中测试多个合约交互。每笔交易后状态都会更新，从而使您能够验证复杂的合约交互。

        您也可以使用 [**`tenderly_simulateBundle` RPC**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_simulateBundle) 模拟交易捆绑包

        [了解更多 →](/simulations/bundled-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-does-the-simulation-api-handle-reverts-in-smar" className="text-xl font-semibold">Simulation API 如何处理智能合约调用中的回滚？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/single-simulations"

        当交易在模拟期间回滚时，API 会提供详细的错误信息，帮助调试回滚原因。这可用于在广播交易之前纠正逻辑。

        [了解更多 →](/simulations/single-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-display-detailed-balance-changes-to-user" className="text-xl font-semibold">模拟交易后，如何向用户显示详细的余额变化？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/asset-balance-changes"

        Tenderly Simulation API 会在模拟结果中返回资产余额变化。您可以使用这些数据向用户展示他们的代币余额将在交易后如何变化。

        [了解更多 →](/simulations/asset-balance-changes)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-estimate-the-gas-required-for-contract-funct" className="text-xl font-semibold">我可以使用 simulation API 估算合约函数所需的 gas 吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/gas-estimation"

        可以，Tenderly 中的 gas 估算功能允许您模拟合约函数，并在交易执行前获得准确的 gas 估算。这有助于确保交易成功并最大限度地降低 gas 费用。

        除了 Simulation API，您还可以使用 [**`tenderly_estimateGas`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGas) 和 [**`tenderly_estimateGasBundle`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGasBundle)。

        [了解更多 →](/simulations/gas-estimation)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="what-is-the-difference-between-gas-and-gasused" className="text-xl font-semibold">gas 和 gasUsed 有什么区别？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        gas 是为交易分配的最大 gas 限额（"预算"），而 gasUsed 表示执行期间实际消耗的 gas。
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-do-bundled-simulations-help-in-testing-complex" className="text-xl font-semibold">捆绑模拟如何帮助测试涉及多次合约调用的复杂工作流？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/bundled-simulations"

        捆绑模拟允许您按顺序模拟多笔交易，并将状态从一笔交易保留到下一笔交易。这对于测试复杂工作流（例如多合约交互或 dApp 用户流程）非常有用。

        [了解更多 →](/simulations/bundled-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-do-i-handle-simulation-failures-and-errors-in" className="text-xl font-semibold">如何在 dApp UI 中处理模拟失败和错误？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/quickstart"

        当模拟失败时，Tenderly API 会提供详细的错误消息。您可以使用这些消息在 dApp UI 中向用户显示有意义的错误反馈，帮助他们在重试之前更正交易。

        [了解更多 →](/simulations/quickstart)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-do-i-trigger-simulations-programmatically-from" className="text-xl font-semibold">如何从后端以编程方式触发模拟，以在执行前验证交易是否成功？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/quickstart"

        您可以通过向 [**`/simulate`** REST API](/api-reference#/operations/simulateTransaction) 端点或 [**`tenderly_simulateTransaction`** RPC](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_simulateTransaction) 发起 POST 请求并传入交易详情，以编程方式触发模拟。这有助于在交易发送到网络之前在受控环境中验证其是否成功。

        [了解更多 →](/simulations/quickstart)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-modify-storage-variables-during-a-simulation" className="text-xl font-semibold">我可以在模拟期间修改存储变量以测试不同的场景吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/state-overrides"

        可以，您可以使用状态覆盖来修改合约存储变量、账户余额以及模拟中的其他链上数据。

        [了解更多 →](/simulations/state-overrides)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-create-a-ui-that-shows-gas-estimates-for-use" className="text-xl font-semibold">我可以创建一个使用 Tenderly API 显示用户交易 gas 估算的 UI 吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/gas-estimation"

        可以，您可以将 Tenderly API 的 gas 估算功能集成到您的 UI 中，在用户确认之前向他们显示其交易的预估 gas 费用。

        或者，您也可以使用 [**`tenderly_estimateGas`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGas) 和 [**`tenderly_estimateGasBundle`**](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_estimateGasBundle)。

        [了解更多 →](/simulations/gas-estimation)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-simulate-calls-from-different-wallets-to" className="text-xl font-semibold">如何模拟来自不同钱包对我的合约的调用，以测试多用户场景？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/single-simulations"

        您可以通过使用不同的 `from` 地址运行单独的模拟来模拟来自多个钱包的交易。这允许您测试合约在多用户场景下的行为。

        [了解更多 →](/simulations/single-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-simulate-invalid-or-out-of-bound-inputs" className="text-xl font-semibold">如何模拟无效或越界的输入，以在各种边缘情况下验证合约的健壮性？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/single-simulations"

        您可以在模拟请求中设置自定义输入值，来模拟具有无效或越界输入的函数调用。这允许您测试合约如何处理边缘情况并防止潜在漏洞。

        [了解更多 →](/simulations/single-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="can-i-simulate-flash-loan-attacks-or-multi-contrac" className="text-xl font-semibold">我可以模拟闪电贷攻击或多合约交互漏洞吗？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/bundled-simulations"

        可以，您可以通过将交易捆绑在一次模拟中来模拟复杂交易，例如闪电贷攻击或跨多个合约的交互。这对于测试 DeFi 协议中的漏洞非常有用。

        [了解更多 →](/simulations/bundled-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-simulate-cross-contract-interactions-and" className="text-xl font-semibold">如何模拟跨合约交互并确保交易流程的正确性？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/bundled-simulations"

        通过将交易捆绑到单次模拟中，您可以测试跨合约交互，并验证交易流程在多个合约之间是否行为正确。这对于依赖复杂合约交互的 dApp 至关重要。

        [了解更多 →](/simulations/bundled-simulations)
      </div>
    </div>
  </Card>

  <Card>
    <div className="flex flex-col gap-2">
      <h2 id="how-can-i-bundle-multiple-user-actions-into-a-sing" className="text-xl font-semibold">如何将多个用户操作捆绑到一次模拟中，为复杂流程提供反馈？</h2>

      <hr className="dark:border-neutral-800" />

      <div>
        [//]: # "/simulations/bundled-simulations"

        您可以将多个用户操作作为单次捆绑模拟的一部分进行模拟，来将它们打包处理。这允许您为涉及 dApp 中多次交互的复杂交易流程提供反馈。

        [了解更多 →](/simulations/bundled-simulations)
      </div>
    </div>
  </Card>
</div>
