> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n 集成

> 通过 n8n-nodes-chainstream 社区节点，将 ChainStream 连接到 n8n 工作流自动化。

`n8n-nodes-chainstream` 是一个社区节点，可将 ChainStream 的链上数据直接引入 [n8n](https://n8n.io) 工作流自动化。查询代币元数据、监控交易、跟踪钱包活动——无需编写代码。

<Info>
  **包名：** `n8n-nodes-chainstream` v0.0.92 | **已发布版本：** 63 | 已在 [n8n Creator Portal](https://n8n.io) 上架
</Info>

## 安装

1. 打开你的 n8n 实例。
2. 前往 **Settings > Community Nodes**。
3. 点击 **Install** 并输入：

```
n8n-nodes-chainstream
```

4. 确认安装，如有提示则重启 n8n。

## 认证

该节点通过 ChainStream Dashboard 签发的 API 凭证进行认证。

1. 在 ChainStream Dashboard 中，导航至 **Settings > API Keys**。
2. 创建新的密钥对。你将获得：
   * **API Client ID**
   * **API Client Secret**
3. 在 n8n 中，前往 **Credentials > New Credential > ChainStream API**。
4. 输入 Client ID 和 Client Secret，然后保存。

```json theme={null}
{
  "credentials": {
    "chainstreamApi": {
      "clientId": "cs_live_xxxxxxxxxxxxxxxx",
      "clientSecret": "your_client_secret_here"
    }
  }
}
```

## 支持的资源和操作

| 资源         | 操作                                      |
| ---------- | --------------------------------------- |
| **Token**  | 获取元数据、获取价格、列出持有者、查询流动性、运行安全审计、列出铸造/销毁事件 |
| **Trade**  | 列出交易、获取活动、查看排行榜                         |
| **Wallet** | 查询余额、获取盈亏、列出活动                          |

## 节点配置

以下是查询代币元数据的 n8n 节点配置示例：

```json theme={null}
{
  "nodes": [
    {
      "parameters": {
        "resource": "token",
        "operation": "getMetadata",
        "chain": "solana",
        "tokenAddress": "So11111111111111111111111111111111111111112"
      },
      "name": "ChainStream",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [450, 300],
      "credentials": {
        "chainstreamApi": {
          "id": "1",
          "name": "ChainStream API"
        }
      }
    }
  ]
}
```

获取代币价格数据：

```json theme={null}
{
  "parameters": {
    "resource": "token",
    "operation": "getPrice",
    "chain": "solana",
    "tokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "currency": "usd"
  },
  "name": "Get Token Price",
  "type": "n8n-nodes-chainstream.chainstream",
  "typeVersion": 1,
  "position": [450, 300]
}
```

查询钱包余额：

```json theme={null}
{
  "parameters": {
    "resource": "wallet",
    "operation": "getBalances",
    "chain": "solana",
    "walletAddress": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
  },
  "name": "Get Wallet Balance",
  "type": "n8n-nodes-chainstream.chainstream",
  "typeVersion": 1,
  "position": [650, 300]
}
```

## 示例工作流

### 1. 价格告警机器人

监控代币价格，当价格超过阈值时发送 Telegram 通知。

```json theme={null}
{
  "nodes": [
    {
      "parameters": {
        "resource": "token",
        "operation": "getPrice",
        "chain": "solana",
        "tokenAddress": "So11111111111111111111111111111111111111112",
        "currency": "usd"
      },
      "name": "Get SOL Price",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [450, 300]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.price }}",
              "operation": "largerEqual",
              "value2": 200
            }
          ]
        }
      },
      "name": "Price Threshold",
      "type": "n8n-nodes-base.if",
      "position": [650, 300]
    },
    {
      "parameters": {
        "chatId": "-100XXXXXXXXXX",
        "text": "SOL price alert: ${{ $json.price }}"
      },
      "name": "Telegram Alert",
      "type": "n8n-nodes-base.telegram",
      "position": [850, 200]
    }
  ]
}
```

### 2. 投资组合追踪器

按计划运行，获取钱包余额并将数据追加到 Google Sheet。

```json theme={null}
{
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "hours", "hoursInterval": 1 }] }
      },
      "name": "Every Hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [250, 300]
    },
    {
      "parameters": {
        "resource": "wallet",
        "operation": "getBalances",
        "chain": "solana",
        "walletAddress": "YOUR_WALLET_ADDRESS"
      },
      "name": "Fetch Balances",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [450, 300]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "YOUR_SHEET_ID",
        "range": "Sheet1!A:D"
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [650, 300]
    }
  ]
}
```

### 3. 巨鲸监控

检测大额钱包活动并发送 Slack 通知。

```json theme={null}
{
  "nodes": [
    {
      "parameters": {
        "resource": "wallet",
        "operation": "getActivity",
        "chain": "solana",
        "walletAddress": "WHALE_WALLET_ADDRESS"
      },
      "name": "Whale Activity",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [450, 300]
    },
    {
      "parameters": {
        "channel": "#whale-alerts",
        "text": "Whale movement detected: {{ $json.type }} of {{ $json.amount }} {{ $json.token }}"
      },
      "name": "Slack Notification",
      "type": "n8n-nodes-base.slack",
      "position": [650, 300]
    }
  ]
}
```

### 4. 合规扫描器

当新的充值到达时，运行 KYT（了解你的交易）检查并标记可疑活动。

```json theme={null}
{
  "nodes": [
    {
      "parameters": {
        "resource": "wallet",
        "operation": "getActivity",
        "chain": "ethereum",
        "walletAddress": "DEPOSIT_WALLET_ADDRESS",
        "activityType": "deposit"
      },
      "name": "New Deposits",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "resource": "token",
        "operation": "securityAudit",
        "chain": "ethereum",
        "tokenAddress": "={{ $json.tokenAddress }}"
      },
      "name": "KYT Check",
      "type": "n8n-nodes-chainstream.chainstream",
      "typeVersion": 1,
      "position": [450, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.flagged }}",
              "operation": "equal",
              "value2": true
            }
          ]
        }
      },
      "name": "Flagged?",
      "type": "n8n-nodes-base.if",
      "position": [650, 300]
    }
  ]
}
```

## 下一步

<CardGroup cols={2}>
  <Card title="触发器节点" icon="bolt" href="/cn/docs/ecosystem/n8n/trigger-node">
    使用 ChainStream Webhook 设置实时事件驱动触发器。
  </Card>

  <Card title="API 参考" icon="code" href="/api-reference">
    浏览驱动此节点的完整 ChainStream API。
  </Card>
</CardGroup>
