> ## 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 dành cho tác nhân

> Hướng dẫn đầy đủ về Helius TypeScript SDK dành cho tác nhân AI — các phương thức Solana an toàn kiểu cho DAS API, giao dịch, Sender, webhook và ZK Compression.

[Helius TypeScript SDK](https://github.com/helius-labs/helius-sdk) cung cấp các phương thức an toàn kiểu cho tất cả API của Helius, giúp tác nhân tương tác với Solana nhanh nhất.

* **Gói**: `helius-sdk` (npm / pnpm / yarn)
* **Phiên bản**: 2.x (sử dụng `@solana/kit`, không phải `@solana/web3.js`)
* **Môi trường chạy**: Mọi môi trường chạy JavaScript — trình duyệt, Deno, Bun, môi trường chạy biên (Cloudflare Workers, Vercel Edge), Node.js 20+
* **TypeScript**: 5.8+ (bao gồm đầy đủ định nghĩa kiểu)
* **Giấy phép**: ISC

## Cài đặt

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

## Bắt đầu nhanh

```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",
});
```

## Tùy chọn client

```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)
});
```

## Không gian tên

Tất cả phương thức đều được truy cập thông qua client `helius`. Các phương thức DAS API và phương thức Solana RPC tiêu chuẩn có sẵn trực tiếp trên `helius.*`. Các chức năng khác được sắp xếp theo không gian tên:

| Không gian tên | Cách truy cập                                                         | Mục đích                                                      |
| -------------- | --------------------------------------------------------------------- | ------------------------------------------------------------- |
| DAS API        | `helius.getAsset()`, `helius.getAssetsByOwner()`, v.v.                | Truy vấn NFT, token và tài sản nén                            |
| RPC V2         | `helius.getTransactionsForAddress()`, `helius.getProgramAccountsV2()` | RPC nâng cao với phân trang và bộ lọc                         |
| Giao dịch      | `helius.tx.*`                                                         | Giao dịch thông minh và Helius Sender                         |
| Nâng cao       | `helius.enhanced.*`                                                   | Phân tích giao dịch thành định dạng con người có thể đọc được |
| Webhook        | `helius.webhooks.*`                                                   | Tạo và quản lý đăng ký webhook                                |
| WebSocket      | `helius.ws.*`                                                         | Luồng dữ liệu blockchain theo thời gian thực                  |
| Staking        | `helius.stake.*`                                                      | Stake SOL vào trình xác thực Helius                           |
| ZK Compression | `helius.zk.*`                                                         | Tài khoản nén và bằng chứng                                   |
| Wallet API     | `helius.wallet.*`                                                     | Số dư, lịch sử và tra cứu danh tính                           |
| RPC tiêu chuẩn | `helius.getBalance()`, `helius.getSlot()`, v.v.                       | Tất cả phương thức Solana RPC tiêu chuẩn thông qua proxy      |
| RPC thô        | `helius.raw`                                                          | Truy cập trực tiếp vào client Rpc `@solana/kit` bên dưới      |
| Xác thực       | `import { makeAuthClient } from "helius-sdk/auth/client"`             | Đăng ký tác nhân và quản lý khóa API (import độc lập)         |

## Đăng ký bằng lập trình (mô-đun xác thực)

Mô-đun xác thực là một import độc lập — mô-đun này không nằm trên `HeliusClient` chính. Sử dụng mô-đun này cho các luồng đăng ký tác nhân bằng lập trình.

```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 }
```

## Tìm hiểu chuyên sâu

<CardGroup cols={2}>
  <Card title="Best Practices" icon="lightbulb" href="/docs/vi/agents/typescript-sdk/best-practices">
    Các mẫu được đề xuất, phân trang, lỗi thường gặp và xử lý lỗi
  </Card>

  <Card title="API Reference" icon="book" href="/docs/vi/agents/typescript-sdk/api-reference">
    Danh sách đầy đủ các phương thức cho từng không gian tên
  </Card>
</CardGroup>

## Tài nguyên

<CardGroup cols={2}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/helius-labs/helius-sdk">
    Mã nguồn, ví dụ và theo dõi vấn đề
  </Card>

  <Card title="Code Examples" icon="code" href="https://github.com/helius-labs/helius-sdk/tree/main/examples">
    Các ví dụ hoạt động cho từng phương thức, được sắp xếp theo không gian tên
  </Card>

  <Card title="SDK API Docs (TypeDoc)" icon="book" href="https://helius-labs.github.io/helius-sdk/">
    Tài liệu API đầy đủ được tạo từ mã nguồn
  </Card>

  <Card title="Migration Guide (1.x to 2.x)" icon="arrow-right" href="https://github.com/helius-labs/helius-sdk/blob/main/MIGRATION.md">
    Nâng cấp từ @solana/web3.js lên @solana/kit
  </Card>
</CardGroup>
