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

# CLI 备忘单

> 按照分步指南和 CLI 命令备忘单， 初始化、构建和部署 Web3 Actions。

本指南展示使用 Tenderly CLI 初始化、构建和部署 Web3 Action 项目所需的命令。

**步骤 1：安装 Tenderly CLI**

使用 `curl` 命令在本地机器上下载并安装 Tenderly CLI 二进制文件。

在 macOS 上安装：

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
curl https://raw.githubusercontent.com/Tenderly/tenderly-cli/master/scripts/install-macos.sh | sh
```

在 Linux 上安装：

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
curl https://raw.githubusercontent.com/Tenderly/tenderly-cli/master/scripts/install-linux.sh | sh
```

**步骤 2：通过 CLI 登录 Tenderly**

运行以下命令，使用您的凭据登录 Tenderly CLI：

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
tenderly login
```

**步骤 3：初始化 Web3 Actions 项目**

要初始化 Web3 Action 项目，运行以下命令：

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

您可以通过两个标志更改默认的初始化设置：更改 Web3 Actions 根目录的名称（默认：`actions`）以及用于编写 Action 函数的语言（默认：`typescript` 或 `javascript`）。

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
tenderly actions init --sources=actions --language=typescript
```

系统会提示您将 Web3 Actions 添加到 Tenderly 项目。您可以创建新项目或选择现有项目。

**步骤 3**： **安装您需要的任何 NPM 依赖**

运行 `tenderly init` 后，您就有了一个 NPM 项目可供使用，因此可以按照熟悉的方式安装任何所需的 NPM 库。

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
cd actions
npm i --save-dev axios ethers
cd ..
```

**步骤 4：构建并部署 Web3 Actions**

在 **tenderly.yaml** 中编写好函数和触发器配置后，可以运行以下命令来构建和部署 Web3 Action。

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# run within the folder containing tenderly.yaml

# Build the project (optional)
tenderly actions build

# Publish the project to Tenderly without running it (start manually)
tenderly actions publish

# Deploy the project to Tenderly Runtime (or re-deploy any changes you make)
tenderly actions deploy
```

运行 `publish` 后不久，您的 Web3 Action 将在 Dashboard 中可用，并按您的配置监听事件。

<Note>
  您可以在编辑函数和触发器配置后运行 `publish` 命令，实现零停机升级
  Web3 Actions。
</Note>

**可选：验证您的 tenderly.yaml**

在部署之前，您可以在本地验证 `tenderly.yaml` 的结构和触发器配置。无需登录。

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Validate all projects in tenderly.yaml
tenderly actions validate

# Validate a single project only
tenderly actions validate --project username/project-slug

# Machine-readable JSON output (useful in CI pipelines)
tenderly actions validate --json
```

`--json` 标志输出结构化结果。当一切有效时：

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{ "valid": true }
```

当验证失败时，将包含 `schema_errors` 和/或 `trigger_errors`（为空时会省略）：

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "valid": false,
  "schema_errors": ["..."],
  "trigger_errors": [
    { "project": "my-org/my-project", "action": "myAction", "errors": ["..."] }
  ]
}
```

**可选：探索支持的功能**

要查看所有受支持的触发器类型、运行时、执行类型和间隔的机器可读清单：

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Print the capabilities manifest
tenderly actions capabilities

# Include the full embedded JSON Schema in the output
tenderly actions capabilities --include-schema
```

这对于需要在不解析文档的情况下发现 CLI 所支持内容的编辑器集成和工具很有用。

**可选：在本地使用 Tenderly Runtime**

安装 [**@tenderly/actions-test**](https://github.com/Tenderly/tenderly-actions/tree/main/packages/actions-test) 包，以便在本地测试您的 Web3 Action 函数。

假设您已经处于 npm 项目中，请运行以下命令：

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @tenderly/actions-test
```

<Note>
  建议将 web3-actions 的测试和运行脚本保留在 actions 目录之外，
  以避免增加 Web3 Actions 项目的体积。
</Note>

查看 [Web3 Actions 本地开发和测试指南](/monitoring/web3-actions/references/local-development) 了解更多细节和示例。
