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

# Helius TypeScript SDK for Agents

> 关于Helius TypeScript SDK的完整指南，适用于AI代理。针对DAS API、交易、Helius Sender、webhooks、WebSockets、staking、ZK压缩和编程注册的类型安全方法。

[Helius TypeScript SDK](https://github.com/helius-labs/helius-sdk)为所有Helius API提供类型安全的方法，使代理与Solana进行交互的速度最快。

* **Package**: `helius-sdk` (npm / pnpm / yarn)
* **Version**: 2.x (使用 `@solana/kit`，而不是 `@solana/web3.js`)
* **Runtime**: 任何JavaScript运行时 — 浏览器、Deno、Bun、edge runtimes（Cloudflare Workers, Vercel Edge）, Node.js 20+
* **TypeScript**: 5.8+ （包含完整类型定义）
* **License**: ISC

## 安装

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

## 快速开始

```typescript theme={"system"}
import { createHelius } from "helius-sdk";

const helius = createHelius({
  apiKey: "YOUR_API_KEY",
  network: "mainnet", // or "devnet"
});

// Get all NFTs and tokens owned by a wallet
const assets = await helius.getAssetsByOwner({
  ownerAddress: "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
  page: 1,
  limit: 50,
});

// Get transaction history (with token account activity)
const txs = await helius.getTransactionsForAddress([
  "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
  { limit: 100, transactionDetails: "full", filters: { tokenAccounts: "balanceChanged" } },
]);

// Send a transaction via Helius Sender (ultra-low latency)
const sig = await helius.tx.sendTransactionWithSender({
  instructions: [transferInstruction],
  signers: [walletSigner],
  region: "US_EAST",
});
```

## 客户端选项

```typescript theme={"system"}
const helius = createHelius({
  apiKey: "YOUR_API_KEY",       // Required for webhooks, enhanced txs, wallet API
  network: "mainnet",           // "mainnet" (default) or "devnet"
  baseUrl: "https://custom..",  // Override RPC URL (optional)
  rebateAddress: "wallet",      // Wallet for RPC rebates (optional)
  userAgent: "my-agent/1.0",   // Sent as X-Helius-Client header (optional)
});
```

## 命名空间

所有方法通过`helius`客户端访问。DAS API 方法和标准Solana RPC 方法可直接在`helius.*`上使用。其他功能组织为命名空间：

| Namespace      | 访问                                                                    | 目的                         |
| -------------- | --------------------------------------------------------------------- | -------------------------- |
| DAS API        | `helius.getAsset()`, `helius.getAssetsByOwner()`, 等                   | 查询NFTs、代币、压缩资产             |
| RPC V2         | `helius.getTransactionsForAddress()`, `helius.getProgramAccountsV2()` | 增强的RPC，支持分页和过滤             |
| Transactions   | `helius.tx.*`                                                         | 智能交易和Helius Sender         |
| Enhanced       | `helius.enhanced.*`                                                   | 将交易解析成人类可读格式               |
| Webhooks       | `helius.webhooks.*`                                                   | 创建和管理webhook订阅             |
| WebSockets     | `helius.ws.*`                                                         | 实时区块链数据流                   |
| Staking        | `helius.stake.*`                                                      | 将SOL质押到Helius验证者           |
| ZK Compression | `helius.zk.*`                                                         | 压缩账户和证明                    |
| Wallet API     | `helius.wallet.*`                                                     | 余额、历史、身份查找                 |
| Standard RPC   | `helius.getBalance()`, `helius.getSlot()`, 等                          | 通过代理实现所有标准Solana RPC方法     |
| Raw RPC        | `helius.raw`                                                          | 直接访问底层`@solana/kit` Rpc客户端 |
| Auth           | `import { makeAuthClient } from "helius-sdk/auth/client"`             | 代理注册和API密钥管理（独立导入）         |

## 编程注册（认证模块）

认证模块是一个独立的导入——不是在主`HeliusClient`上。用于编程代理注册流程。

```typescript theme={"system"}
import { makeAuthClient } from "helius-sdk/auth/client";

const auth = makeAuthClient();

// Hosted-link signup (returns a paymentUrl the user opens in a browser):
const link = await auth.signup({
  secretKey: keypair.secretKey,
  plan: "agent",
  email: "you@example.com",
  firstName: "Ada",
  lastName: "Lovelace",
});
// link: { kind: "payment_required", jwt, refId, walletAddress, paymentLink: { paymentUrl, ... } }

// Or pay USDC directly from the local keypair and provision in one call:
const result = await auth.signupAndPay({
  secretKey: keypair.secretKey,
  plan: "agent",
  email: "you@example.com",
  firstName: "Ada",
  lastName: "Lovelace",
});
// result.kind: "completed" | "pending" | "expired" | "failed" | "already_subscribed" | "upgrade_required"
// On "completed": result has { jwt, walletAddress, projectId, apiKey, endpoints, txSignature }
```

## 深入探讨

<CardGroup cols={2}>
  <Card title="最佳实践" icon="lightbulb" href="/zh/agents/typescript-sdk/best-practices">
    推荐模式、分页、常见错误和错误处理
  </Card>

  <Card title="API 参考" icon="book" href="/zh/agents/typescript-sdk/api-reference">
    每个命名空间的完整方法列表
  </Card>
</CardGroup>

## 资源

<CardGroup cols={2}>
  <Card title="GitHub 仓库" icon="github" href="https://github.com/helius-labs/helius-sdk">
    源代码、示例和问题跟踪
  </Card>

  <Card title="代码示例" icon="code" href="https://github.com/helius-labs/helius-sdk/tree/main/examples">
    按命名空间组织的每个方法的工作示例
  </Card>

  <Card title="SDK API 文档（TypeDoc）" icon="book" href="https://helius-labs.github.io/helius-sdk/">
    从源代码生成的完整 API 文档
  </Card>

  <Card title="迁移指南（1.x 到 2.x）" icon="arrow-right" href="https://github.com/helius-labs/helius-sdk/blob/main/MIGRATION.md">
    从 @solana/web3.js 升级到 @solana/kit
  </Card>
</CardGroup>
