> ## 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.

# 调查失败的交易

> 使用调用跟踪、Debugger 和 Evaluate 将回滚的交易追溯到其根本原因，然后通过重新模拟来验证修复。

在本指南中，我们将调查交易失败的根本原因并验证修复。

我们将查看一笔 [Uniswap 交易](https://www.tdly.co/tx/1/0xbe082dcc8ae59868f5b2330173902bb88c6643b5c2fdf0d8a9f43d03dbca0c36)。此交易尝试执行 `swapExactTokensForTokens`。

<Steps>
  ### 在 Tenderly dashboard 搜索中粘贴交易哈希

  交易哈希：`0xbe082dcc8ae59868f5b2330173902bb88c6643b5c2fdf0d8a9f43d03dbca0c36`

  ### 探索错误

  回滚发生在 `swapExactTokensForTokens` 中，检查涉及输入参数 `amountOutMin` 的条件时。它以下列错误消息回滚：
  错误消息：`UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT`

  从输入部分，我们可以看到 `amountOutMin` 的值为 `1102820622890207119`。

  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/debugger/failed-tx-1.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=7870862a8fb522c861f797116435d338" alt="" width="3360" height="2100" data-path="images/debugger/failed-tx-1.webp" />

  ### 探索回滚条件

  跳到 [debugger 视图](https://dashboard.tenderly.co/tx/1/0xbe082dcc8ae59868f5b2330173902bb88c6643b5c2fdf0d8a9f43d03dbca0c36/debugger?trace=0.1)。注意 require 涉及 `amounts[amounts.length - 1]`。

  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/debugger/failed-tx-2.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=c8d985b4f74f9a446462dda13ecbc3bb" alt="" width="3360" height="2100" data-path="images/debugger/failed-tx-2.webp" />

  ### 评估表达式

  要获取此表达式的值，您可以使用 Evaluate：

  1. 确保 debugger 位于回滚行，
  2. 粘贴表达式 `amounts[amounts.length - 1]`，
  3. 按下 "Evaluate" 按钮。

  值是：
  值为 `1029855063181377015`。

  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/debugger/failed-tx-3.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=29e7a31e020dbf5e3d1abc5e8bd407c2" alt="" width="3360" height="2100" data-path="images/debugger/failed-tx-3.webp" />

  ### 从调用信息中获取值

  您还可以通过分析产生该值的函数来提取所讨论表达式的值：

  1. 将 debugger 移动到左侧执行跟踪中的 [`getAmountsOut`](https://dashboard.tenderly.co/tx/1/0xbe082dcc8ae59868f5b2330173902bb88c6643b5c2fdf0d8a9f43d03dbca0c36/debugger?trace=0.0)
  2. 在下方窗格中找到 `output`
  3. 由于表达式 `amounts[amounts.length - 1]` 获取数组的最后一个元素，我们得出结论：所讨论的值是 `1029855063181377015`。

  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/debugger/failed-tx-4.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=32dc026b46ee2100859b2d74caca7792" alt="" width="3360" height="2100" data-path="images/debugger/failed-tx-4.webp" />

  ### 潜在解决方案

  如果 `amountOutMin` 的值为 `1029855063181377015`，则此交易将会成功。

  ### 验证解决方案

  要验证解决方案，请点击 "Re-Simulate" 按钮：

  1. 将值 `1029855063181377015` 粘贴到第二个参数
  2. 点击 **Simulate**。

  模拟已成功，这意味着我们找到了正确的参数值。

  <Info>
    Swap 交易对时间敏感，它们会考虑 `block.timestamp` 值。
    默认情况下，模拟在原始区块和原始时间戳上执行。
    只有在需要自定义区块和时间戳值时，才可以使用区块头覆盖来实现此目的。
  </Info>
</Steps>
