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

# 模拟交易

> 使用这些代码片段示例，通过 Tenderly SDK 执行单笔和捆绑交易。

[Tenderly SDK](/platform/sdk/introduction) 提供了 **`Simulator`** 类用于模拟交易。有关按步骤的演示，请参见 [模拟交易教程](/platform/sdk/tutorials/simulate-transactions)。要运行模拟，请在 **`tenderly`** 实例上调用 **`simulator`** 命名空间中的 **`simulateTransaction`** 方法：

```javascript title="example.js" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const transaction = await tenderly.simulator.simulateTransaction({
  transaction: {
    from: callerAddress,
    to: counterContract,
    gas: 20000000,
    gas_price: '19419609232',
    value: 0,
    input: counterContractAbiInterface.encodeFunctionData('inc', []),
  },
  blockNumber: 3237677,
});
```

您也可以通过调用 **`simulateBundle`** 方法模拟一组交易：

```javascript title="example.js" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const simulations = await tenderly.simulator.simulateBundle({
  transactions: [
    {
      from: fromWalletAddress,
      to: myTokenAddress,
      gas: 0,
      gas_price: '0',
      value: 0,
      input: myTokenAbiInterface.encodeFunctionData('approve', [toWalletAddress, 1234567890]),
    },
    {
      from: toWalletAddress,
      to: myTokenAddress,
      gas: 0,
      gas_price: '0',
      value: 0,
      input: myTokenAbiInterface.encodeFunctionData('transferFrom', [
        fromWalletAddress,
        toWalletAddress,
        1234567890,
      ]),
    },
  ],
  blockNumber: 3262454,
  overrides: {
    [myTokenAddress]: {
      state: {
        [`_balances[${fromWalletAddress}]`]: '1234567891',
      },
    },
  },
});
```
