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

# 将 Alerts 设置为 Web3Actions 的触发器

> 学习如何在 Tenderly 中设置和配置 Alerts 作为 Web3Actions 的触发器，实现对区块链事件的自动化响应。

Tenderly 中的 [Web3 Actions](/monitoring/web3-actions/introduction) 提供了一种强大的方式来自动响应区块链事件。本指南将引导您完成将 [Alerts](/monitoring/alerts/introduction) 设置为 Web3Actions 触发器的过程，使您能够基于特定的区块链条件创建自动化工作流。

<Note>
  本指南假定您已拥有 Tenderly 账户并对 Web3Actions 有基本了解。
</Note>

## 前提条件

在开始之前，请确保您已具备：

* 已安装 [Tenderly CLI](https://github.com/Tenderly/tenderly-cli)
* 一个具有相应权限的 Tenderly 账户
* 对 Web3Actions 的基本理解

## 设置流程

您可以通过 UI 或 CLI 两种方式为 Web3Actions 设置 Alert 触发器。

<Steps>
  ### UI 方式

  1. 登录您的 Tenderly dashboard
  2. 导航到 Web3Action 部分
  3. 点击 `Create New Action`
  4. 在触发器类型选择中，选择 `Alert`
  5. 配置您的 action：

  * 为您的 action 设置一个名称
  * 定义将要执行的函数
  * 指定任何必要的环境变量

  6. 点击 `Deploy` 以创建并部署您的 Web3Action

  ### CLI 方式

  1. 在您的 Tenderly dashboard 中创建 Alert 并记录 `ALERT_ID`
  2. 初始化您的 Web3Action：

  ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  tenderly actions init
  ```

  3. 配置您的 `tenderly.yaml`：

  ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  account_id: "<YOUR_ACCOUNT_ID>"
  actions:
    <YOUR_ACCOUNT_ID>/<YOUR_PROJECT_SLUG>:
      runtime: v2
      sources: actions
      specs:
        <YOUR_ACTION_NAME>:
          description: "Description of what your action does"
          function: example:actionFn
          trigger:
            type: alert
            alert: { <YOUR_ALERT_ID> }
          execution_type: parallel
  project_slug: "<YOUR_PROJECT_SLUG>"
  ```

  <Warning>
    请务必将所有占位符值（`<YOUR_ACCOUNT_ID>`、`<YOUR_PROJECT_SLUG>` 和 `<ALERT_ID>`）替换为您的实际值。
  </Warning>

  5. 实现您的 action 代码
  6. 使用以下命令部署：

  ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  tenderly actions deploy
  ```
</Steps>

## 理解配置

以下是每个配置项的含义：

* `account_id` 和 `project_slug`：标识您的 Tenderly 账户和项目
* `runtime`：指定 action 的运行时版本
* `sources`：指示包含 action 代码的目录
* `specs`：定义您的 action 规范
* `trigger`：配置 action 的触发方式
* `execution_type`：确定如何处理多个实例

## 最佳实践

1. 为您的 actions 和 alerts 使用具有描述性的名称
2. 保持 action 代码模块化且专注
3. 对敏感信息使用环境变量
4. 部署前进行充分测试
5. 定期监控您的 action 执行

<Note>
  遵循这些最佳实践将有助于确保您的 Web3Actions 平稳运行。
</Note>

## 故障排除

如果遇到问题：

* 验证您的 `ALERT_ID` 与创建的 alert 一致
* 检查 alert 条件是否正确配置
* 查看 Tenderly dashboard 日志以查找错误
* 确保 CLI 是最新的并已正确认证

<Warning>
  如果您的 action 未被触发，请先在 Tenderly dashboard 中检查 alert 配置和 action 日志。
</Warning>

## 总结

通过遵循本指南，您现在应该已经设置好了一个基于 Alert 触发的 Web3Action。这一强大组合允许您创建自动化的响应式系统，能够实时响应特定的区块链事件或条件。
