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

# Solana 数据流快速入门

> 在 5 分钟内启动您的第一个实时 Solana 数据流。LaserStream gRPC、LaserStream WebSocket 和 Webhooks 设置指南。

## 快速设置

通过工作代码示例在几分钟内获取流式 Solana 数据。根据您的需求选择方法：

| 方法                        | 最佳用途                | 需要计划                                             | 延迟     |
| ------------------------- | ------------------- | ------------------------------------------------ | ------ |
| **Shred Delivery**        | HFT、MEV、套利 — 执行前数据  | 所有计划（[付费附加功能](/zh/billing/plans#shred-delivery)） | **尽早** |
| **LaserStream gRPC**      | 关键任务，后端服务           | 所有计划（Devnet），Business+（Mainnet）                  | **最快** |
| **LaserStream WebSocket** | 大多数应用程序，实时UI，广泛兼容性。 | Free+（Helius扩展：Developer+）                       | **快速** |
| **Webhooks**              | 服务器通知，事件驱动应用程序      | Free+                                            | **可变** |

<Tip>
  需要原始快递数据？在你的Helius仪表板中从[快递数据选项卡](https://dashboard.helius.dev/shred-delivery-seats)订阅。查看[如何订阅原始快递数据](/zh/shred-delivery/raw-shreds)获取设置步骤。
</Tip>

## 选项 1: LaserStream gRPC

最可靠的选项，具有[24小时历史重播](/zh/laserstream/historical-replay)和多节点故障转移。最适合关键任务后端和索引器。

```bash theme={"system"}
npm install helius-laserstream
```

```typescript theme={"system"}
import { subscribe, CommitmentLevel, LaserstreamConfig, SubscribeRequest } from 'helius-laserstream';

async function main() {
  const subscriptionRequest: SubscribeRequest = {
    transactions: {
      "token-filter": { // user-defined label for this filter
        accountInclude: ['TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'],
        accountExclude: [],
        accountRequired: [],
        vote: false,
        failed: false
      }
    },
    commitment: CommitmentLevel.CONFIRMED,
    accounts: {},
    slots: {},
    transactionsStatus: {},
    blocks: {},
    blocksMeta: {},
    entry: {},
    accountsDataSlice: [],
  };

  const config: LaserstreamConfig = {
    apiKey: 'YOUR_API_KEY',
    endpoint: 'https://laserstream-mainnet-ewr.helius-rpc.com',
  }

  await subscribe(config, subscriptionRequest, async (data) => {
    console.log(data);
  }, async (error) => {
    console.error(error);
  });
}

main().catch(console.error);
```

<CardGroup cols={2}>
  <Card title="LaserStream指南" icon="book" href="/zh/laserstream">
    完整的LaserStream文档及历史重播
  </Card>

  <Card title="快速开始" icon="rocket" href="https://dashboard.helius.dev/laserstream">
    从你的Helius仪表板启用LaserStream并开始流式处理。
  </Card>
</CardGroup>

## 选项 2: LaserStream WebSocket

[LaserStream WebSocket](/zh/rpc/websocket) 提供 [标准 Solana 订阅方法](/zh/api-reference/rpc/websocket-methods) 和 Helius 扩展，比如 `transactionSubscribe`，在一个统一的端点上。非常适合浏览器/UI 客户端和广泛的生态系统兼容性。

```javascript theme={"system"}
const WebSocket = require('ws');

const ws = new WebSocket('wss://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY');

ws.on('open', () => {
  console.log('WebSocket connected');

  // Helius extension: transactionSubscribe with rich filtering
  ws.send(JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "transactionSubscribe",
    params: [
      {
        accountInclude: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
        vote: false,
        failed: false
      },
      {
        commitment: "confirmed",
        encoding: "jsonParsed",
        transactionDetails: "full"
      }
    ]
  }));

  // Keep connection alive
  setInterval(() => ws.ping(), 30000);
});

ws.on('message', (data) => {
  const message = JSON.parse(data);
  console.log('Transaction:', message);
});
```

**替换 `YOUR_API_KEY`** 使用您在 [dashboard.helius.dev](https://dashboard.helius.dev) 的密钥。

<Card title="LaserStream WebSocket 概览" icon="arrow-right" href="/zh/rpc/websocket">
  所有订阅方法（标准 Solana + Helius 扩展），包括参数参考和示例
</Card>

## 选项 3: Webhooks

适用于无需保持持续连接需要事件通知的服务器端应用程序。

```bash theme={"system"}
# Create a webhook
curl -X POST "https://mainnet.helius-rpc.com/v0/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "webhookURL": "https://your-server.com/webhook",
    "transactionTypes": ["Any"],
    "accountAddresses": ["YOUR_ACCOUNT_ADDRESS"],
    "webhookType": "enhanced"
  }'
```

```javascript theme={"system"}
// Handle webhook events (Express.js example)
app.post('/webhook', (req, res) => {
  req.body.forEach(event => {
    console.log('Blockchain event:', event);
  });
  res.status(200).send('OK');
});
```

<Card title="Webhooks 指南" icon="arrow-right" href="/zh/webhooks">
  完整的 webhook 设置和事件处理
</Card>

## 常见用例

**监控代币转移**

```javascript theme={"system"}
// Subscribe to Token Program activity
method: "programSubscribe",
params: ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", {...}]
```

**跟踪 Pump.fun 交易**

```javascript theme={"system"}
// Subscribe to Pump.fun program transactions
method: "transactionSubscribe",
params: [
  {
    accountInclude: ["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"],
    vote: false,
    failed: false
  },
  { commitment: "confirmed" }
]
```

**监视钱包活动**

```javascript theme={"system"}
// Monitor specific wallet
method: "accountSubscribe",
params: ["WALLET_ADDRESS", {...}]
```

## 下一步

<CardGroup cols={2}>
  <Card title="流媒体概述" icon="play" href="/zh/data-streaming">
    了解所有流媒体选项及各自的使用时机
  </Card>

  <Card title="API 参考" icon="book" href="/zh/api-reference">
    完整的方法文档和参数
  </Card>
</CardGroup>

**需要帮助？** 加入我们的[Discord](https://discord.com/invite/6GXdee3gBj)或查看[支持文档](/zh/support)。
