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

# 向 Virtual Environments 发送交易

> 通过 JSON-RPC 向 Virtual Environment 发送已签名和未签名的交易，并使用 Admin RPC 作弊码为账户注资。

Virtual Environments 允许您向虚拟网络发送交易。发送交易的过程与在真实网络上发送交易完全相同。

交易可以通过 Dashboard UI 或 RPC 发送。本页面向您展示如何使用这两种方法进行操作。

## 通过 RPC 发送

使用 `eth_sendRawTransaction` RPC 方法向您的 Virtual Environment 发送交易。

下面的示例展示了如何使用 Viem、Ethers.js 和 cURL 命令发送交易。这些代码片段无需修改即可运行。

<Tabs>
  <Tab title="Shell">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    curl $TENDERLY_VIRTUAL_TESTNET_RPC \
        -X POST \
        -H "Content-Type: application/json" \
        -d '{
              "jsonrpc": "2.0",
              "id": 0,
              "method": "eth_sendRawTransaction",
              "params": [
                "0x095ea7b300000000000000000000000040bdb4497614bae1a67061ee20aade3c2067ac9e00000000000000000000000000000000000000000000000000000000000186a0"
              ]
        }'
    ```
  </Tab>

  <Tab title="virtual-environments/src/viem-send-tx.ts">
    阅读[本指南](/virtual-environments/libraries/viem)以获取有关 Viem 集成的更多详细信息。

    ```typescript showLineNumbers title="virtual-environments/src/viem-send-tx.ts" lines={2,4, 17, 23} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}

    const EXPLORER_BASE_URL = vMainnet.blockExplorers.default;

    const account = privateKeyToAccount(generatePrivateKey());

    (async () => {
      const client = createWalletClient({
        account,
        chain: vMainnet,
        transport: http(vMainnet.rpcUrls.default.http[0]),
      });

      await tenderlySetBalance(client, [
        [account.address],
        "0xDE0B6B3A7640000",
      ]);


      const tx = await client.sendTransaction({
        to: "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
        value: parseEther("0.01"),
      });

      console.log(`${EXPLORER_BASE_URL}/tx/${tx}`);
    })();
    ```
  </Tab>

  <Tab title="send-tx.ts">
    阅读[本指南](/virtual-environments/libraries/ethers)以获取有关 Ethers 集成的更多详细信息。

    ```ts title="send-tx.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}

    await (async () => {
      const provider = new ethers.JsonRpcProvider(process.env.TENDERLY_VIRTUAL_TESTNET_RPC!);

      const signer = Wallet.fromPhrase(Mnemonic.fromEntropy(ethers.randomBytes(24)).phrase, provider);

      await provider.send("tenderly_setBalance", [
        signer.address,
        "0xDE0B6B3A7640000",
      ]);

      const tx = await signer.sendTransaction({
        to: "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
        value: ethers.parseEther("0.01"),
      });

      console.log(`${process.env.VIRTUAL_MAINNET_EXPLORER!}/tx/${tx.hash}`);
    })();
    ```
  </Tab>
</Tabs>

## 从 Dashboard 发送

从 Dashboard 发送的交易将记录在 Virtual Environment 的状态中。这些交易**无需签名**，可以在 Virtual Environment 上的任意地址之间发送。

在 Explorer 视图中，单击右上角的 **Send 图标**以访问 **Send Transaction** 输入表单。

[在 Loom 上观看 →](https://www.loom.com/embed/e376ad4184ab4294b9e0ca57033af568?sid=0cdaf910-aad4-41fc-86a6-6bc678032341)

<Steps>
  ### 选择合约

  在 **address** 字段中，粘贴 DAI 稳定币合约的地址：`0x6B175474E89094C44Da98b954EedeAC495271d0F`。

  接收合约可以是以下任意一种：

  * [部署在 Virtual Environment 上](/virtual-environments/develop/deploy-contracts)的 Virtual Contract
  * 添加到您 [Tenderly 项目](/platform/account/projects/overview)中的合约
  * 网络上任何已有的合约

  ### 指定调用数据

  对于[在 Tenderly 上验证过](/contract-verification/overview)（私有或公开）或在 Etherscan 或 Blockscout 上公开验证过的合约，您可以使用 **Choose function and parameters**。

  1. 选择 **`approve`** 函数
  2. 粘贴您希望批准 DAI 的地址（`0x40BdB4497614bAe1A67061EE20AAdE3c2067AC9e`）
  3. 设置您想要批准的 DAI 以 wei 计的数量。例如，`10000000000000000000`。

  <Note>对于未验证的合约，您需要以十六进制形式**输入原始输入数据/calldata**。</Note>

  ### 填写交易参数

  您可以填写以下选项：

  * **From**：任何账户地址，因为 Virtual Environments 上的交易无需签名。使用 `0xbd8daa414fda8a8a129f7035e7496759c5af8570` 或您为其注资过 DAI 的任何地址。
  * **Gas**：默认为 `800000`，或设置期望的 gas（上限）
  * **Gas Price**：默认为 `0`，或任意 gas 价格
  * **Value**：默认为 `0`，或指定任意交易 value，将从发送方（**from**）余额中扣除。

  <Note>
    发送账户需要有足够的资金来发送交易。在 Virtual Environments 上发送交易之前，请使用[无限水龙头](/virtual-environments/unlimited-faucet)为任意账户充值任意余额。
  </Note>

  ### 发送交易

  单击 **Send Transaction**。

  已发送的交易将出现在 [Virtual Environment Explorer](/virtual-environments/explorer) 中。单击该交易可以检查调用跟踪，使用 Debugger 进行调试，或使用不同参数重新模拟。

  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/testnets/dai-send-tx.png?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=e87158c2e275276447fb71683b0f03e2" alt="" width="3456" height="2160" data-path="images/testnets/dai-send-tx.png" />
</Steps>

## 后续步骤

* [模拟交易](/virtual-environments/interact/simulate-transactions)：从 Dashboard 或通过 RPC 运行交易模拟
* [部署智能合约](/virtual-environments/develop/deploy-contracts)：开始部署和监控智能合约
* [暂存 dapp](/virtual-environments/ci-cd/stage-dapps)：了解如何将 Virtual Environment 连接到您 dapp 的 UI
* 使用 Tenderly Debugger [调试交易](/virtual-environments/develop/debug-transactions)。
