> For the complete documentation index, see [llms.txt](https://utxoswap.gitbook.io/zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utxoswap.gitbook.io/zh/dev/sdk/quick-start.md).

# SDK 快速入门

我们已经成功实现了 UTXOSwap SDK 的 Stage 1，提供了满足基本 swap 需求的功能。

以下是 UTXOSwap SDK 的安装和使用指南，旨在帮助开发者快速集成和开始使用。如果在使用过程中遇到任何问题，请随时与我们联系（[Telegram](https://t.me/UTXOSwap)）。我们非常感谢您的反馈，这对我们持续改进产品至关重要。

GitHub 链接: <https://github.com/UTXOSwap/utxoswap-sdk-js>

## 安装

您可以通过 yarn 或 npm 来安装 UTXOSwap SDK。安装时，SDK 将自动处理所有必要的依赖项，包括 RGB++ SDK，无需进行额外的配置。

使用 yarn 安装：

```bash
$ yarn add @utxoswap/swap-sdk-js
```

或使用 npm 安装：

```bash
$ npm install @utxoswap/swap-sdk-js
```

## 使用方法

在项目中使用 UTXOSwap SDK，您可以根据您的开发环境选择使用 `import` 或 `require` 语法。后续文档中的示例将采用 ES6 语法。

使用 ES6 `import`：

```jsx
import { Collector, Token, Client, Pool } from '@utxoswap/swap-sdk-js';
```

或使用 CommonJS `require`：

```jsx
const UTXOSwap_SDK = require('@utxoswap/swap-sdk-js');
```

## 配置

首先，您需要配置 CKB 节点信息和 UTXOSwap 的后端服务 apiKey，以便后续可以查询链上数据和交互。

```tsx
import { Collector, Token, Client, Pool } from '@utxoswap/swap-sdk-js';

// 配置 CKB 索引器 URL
const ckbIndexerUrl = '<https://mainnet.ckbapp.dev/>'; // 示例 URL
const collector = new Collector({ ckbIndexerUrl });

// 配置 apiKey
const apiKey = "your api key"; // 替换为您的 apiKey
const client = new Client(false, apiKey); // false 为测试网，true 为主网
```

下表列出了 CKB 公开的 RPC 地址，您可以根据需要选择适合的环境：

| Type        | URL                           |
| ----------- | ----------------------------- |
| CKB Mainnet | <https://mainnet.ckbapp.dev/> |
| CKB Mainnet | <https://mainnet.ckb.dev/>    |
| CKB Testnet | <https://testnet.ckbapp.dev/> |
| CKB Testnet | <https://testnet.ckb.dev/>    |

更多关于节点配置和 API 的使用，请参考 [Nervos Network 官方文档](https://docs.nervos.org/docs/node/rpcs)。

* 获取 apiKey：您可以通过联系 **<developer@utxoswap.xyz>** 来免费获取一个 apiKey，这是访问 UTXOSwap 后端服务的必需条件。

确保以上信息正确配置，以保证 SDK 的顺利运行和接口的正确调用。

## Demo

我们提供了一个 Demo，以便您快速了解和体验 UTXOSwap SDK 的功能。请通过以下链接访问 UTXOSwap SDK 的 Demo 和查看源代码：

* Demo：[Swap demo](https://utxoswap-sdk-demo.vercel.app/)
* 源代码：[GitHub repository](https://github.com/UTXOSwap/utxoswap-sdk-js/tree/main/example)

#### 运行 Demo

首先，安装所需的依赖包：

```bash
$ yarn
```

接着，构建 SDK 并链接到本地项目：

```bash
$ yarn build
$ yarn link
```

最后，切换到 example 目录，链接 SDK，并启动 Demo：

```bash
$ cd example/
$ yarn
$ yarn link @utxoswap/swap-sdk-js
$ yarn dev
```

这些步骤将帮助您快速启动并运行 UTXOSwap SDK Demo，以便您可以直观地理解 SDK 的功能和操作方式。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://utxoswap.gitbook.io/zh/dev/sdk/quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
