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

# 发送您的第一个 API 请求

> 使用 WaaS 2.0 API 的入门指南，包括帐户设置、API Key 生成、请求认证和发送 API 请求。

<Tip>
  即刻安装 [Cobo WaaS Skill](/v2_cn/guides/overview/cobo-waas-skill)，在 Claude Code、Cursor 等 AI 开发环境中使用自然语言集成 WaaS API，显著提升开发效率 🚀
</Tip>

## 概述

本指南介绍如何使用钱包即服务 (WaaS) 2.0 API。阅读本指南后，您将能够成功调用一个 API 操作，并接收响应。

## 开始之前

如果您选择使用 WaaS SDK 而不是手动编写 API 请求，则需要先安装相应编程语言的正确版本。例如，如果您想使用 [Python SDK](/v2_cn/developer-tools/quickstart-python)，则需要安装 Python 3.7 或更新版本。

## 设置账户

按照[快速入门](https://manuals.cobo.com/cn/portal/quick-start-guide)中的说明设置您的 Cobo 账户并创建您的团队。如果团队已经创建，请让您的团队管理员邀请您加入团队。

<Note>本指南的所有示例都使用开发环境。请在开发环境 [https://portal.dev.cobo.com/](https://portal.dev.cobo.com/) 中创建您的团队。</Note>

## 生成 API Key 和 API Secret

生成一对 Ed25519 密钥对作为 API Key 和 API Secret。本指南以 OpenSSL 为例。要了解有关生成密钥对的其他方法，请参阅[生成 API Key 和 API Secret](/v2_cn/guides/overview/cobo-auth#generate-an-api-key-and-an-api-secret)。

1. 在终端窗口中，运行以下 OpenSSL 命令：

```shell theme={null}
# Generate a private key and save it in the `private.key.pem` file.
openssl genpkey -algorithm ed25519 -out private_key.pem

# Extract the public key from the private key and save it in the `public.key.pem` file.
openssl pkey -in private_key.pem -pubout -out public_key.pem
```

私钥保存在 `private.key.pem` 文件中，公钥保存在 `public.key.pem` 文件中。

2. 您可以通过运行以下命令打印密钥：

```shell theme={null}
# Export the private key in hexadecimal format.
openssl pkey -in private_key.pem -text | grep 'priv:' -A 3 | tail -n +2 | tr -d ':\n '

# Export the public key in hexadecimal format.
openssl pkey -pubin -in public_key.pem -text | grep 'pub:' -A 3 | tail -n +2 | tr -d ':\n '
```

## 注册 API Key

在 Cobo Portal 上注册您的 API Key 并配置相关权限。要了解有关注册 API Key 的更多信息，请参阅[注册 API Key](https://manuals.cobo.com/cn/portal/developer-console/create-api-key)。

1. 登录 [Cobo Portal](https://portal.dev.cobo.com/login)（开发环境）。
2. 在左侧导航菜单中，点击 **开发者** > **API Keys**。
3. 点击 **注册 API Key**。
4. 输入 API Key 名称（最多 30 个字符）。
5. 输入您在上一步中生成的公钥。
6. 在**用户角色 & 钱包范围**下，设置**用户角色**为 **Viewer**，并设置**钱包范围**为**任何类型钱包**。用户角色用于确定 API Key 可以进行的操作，钱包范围用于确定 API Key 可以控制的钱包。
7. 点击**确认**保存设置。
8. 选择**临时**作为**密钥类型**。<Note>如果您已经有静态 IP 地址，您可以将密钥类型设置为**长期**，并在**IP 白名单**中输入您的 IP 地址。</Note>
9. 点击**注册**。
10. 通知您的团队管理员在 Cobo Guard 上批准请求。
    <Note>默认情况下，需要至少一半的管理员批准才能成功注册 API Key。</Note>

只有在 API Key 状态变为**活跃中**后，您才能开始使用它。

## 为您的请求添加身份认证信息

<Note>如果您选择[使用 WaaS SDK](/v2_cn/developer-tools/quickstart-python)，则可以跳过此步骤，因为 SDK 封装了认证机制。</Note>

在发送 API 请求时，您需要在请求头中包含 API Key、`Biz-Api-Nonce`（随机字符串）和 API 签名，以作为身份认证信息。有关更多信息，请参阅 [Cobo Auth](/v2_cn/guides/overview/cobo-auth)。

```
headers = {
  "Biz-Api-Key": {YOUR_API_KEY}.hex(),
  "Biz-Api-Nonce": {Nonce},
  "Biz-Api-Signature": {YOUR_API_SIGNATURE}.hex(),
}
```

* Biz-Api-Key：API Key。要了解如何生成 API Key，请参阅[生成 API Key 和 API Secret](/v2_cn/guides/overview/cobo-auth#generate-an-api-key-and-an-api-secret)。
* Biz-Api-Nonce：用作请求 nonce 的随机字符串。
* Biz-Api-Signature：API 签名。要了解如何计算 API 签名，请参阅[计算 API 签名](/v2_cn/guides/overview/cobo-auth#calculate-the-api-signature)。

## 发送请求

<Note>如果您选择[使用 WaaS SDK](/v2_cn/developer-tools/quickstart-python)，则可以跳过此步骤，因为 SDK 已经包含了处理该逻辑的现成函数。</Note>

本指南使用 [List supported chains](/v2/api-references/wallets/list-supported-chains) 操作作为示例来演示如何发送 API 请求。此操作检索特定钱包类型或子类型支持的所有链。在以下示例中，我们检索[全托管钱包](https://manuals.cobo.com/cn/portal/custodial-wallets/introduction)支持的所有链。

```shell theme={null}
curl --location --request GET 'https://api.dev.cobo.com/v2/wallets/chains?wallet_type=Custodial&wallet_subtype=&chain_ids=&limit=10&before=&after='
  
  # Replace the following with your own authentication information
  --header 'BIZ-API-KEY: {YOUR_API_KEY}' \
  --header 'Biz-Api-Nonce: {NONCE}' \
  --header 'Biz-Api-Signature: {YOUR_API_SIGNATURE}'

```

如果请求成功，您应该收到以下响应：

```JSON theme={null}
{
    "data": [
        {
            "chain_id": "ARBITRUM_ETH",
            "symbol": "Arbitrum",
            "icon_url": "https://d.cobo.com/public/logos/ARB.png",
            "explorer_tx_url": "https://arbiscan.io/tx/{txn_id}",
            "explorer_address_url": "https://arbiscan.io/address/{address}",
            "require_memo": false
        },
        {
            "chain_id": "AVAXC",
            "symbol": "Avalanche C-Chain",
            "icon_url": "https://d.cobo.com/public/logos/AVAXC-logo.png",
            "explorer_tx_url": "https://avascan.info/blockchain/c/tx/{txn_id}",
            "explorer_address_url": "https://avascan.info/blockchain/c/address/{address}",
            "require_memo": false
        },
        ...
    ],
    "pagination": {
        "before": "",
        "after": "41KxruMakf",
        "total_count": 19
    }
}
```

## 使用 WaaS SDK

本节介绍如何使用 Python SDK 调用一个 API 操作。

要了解如何安装 Python SDK 并完成初始设置，请参阅 [Python SDK 入门](/v2_cn/developer-tools/quickstart-python)。

以下是调用 [List supported chains](/v2/api-references/wallets/list-supported-chains) 操作的示例代码。在配置 HTTP host 字段时，请使用开发环境的 URL，因为您在上一步已在开发环境中注册了 API Key。

```python theme={null}
import cobo_waas2
from pprint import pprint

configuration = cobo_waas2.Configuration(
   # Replace `<YOUR_API_SECRET>` with your API secret.
   api_private_key="<YOUR_API_SECRET>",
   # Use the development environment 
   host="https://api.dev.cobo.com/v2"
)

# Enter a context with an instance of the API client
with cobo_waas2.ApiClient(configuration) as api_client:
   # Create an instance of the API class
   api_instance = cobo_waas2.WalletsApi(api_client)
   try:
       # List all supported chains
       api_response = api_instance.list_supported_chains()
       print("The response of WalletsApi->list_supported_chains:\n")
       pprint(api_response)
   except Exception as e:
       print("Exception when calling WalletsApi->list_supported_chains: %s\n" % e)

```

## 下一步

您已成功发送 API 请求并接收响应。但是，在您创建钱包、进行交易或实现其他功能之前，还有一些事情要做。

* 要开始使用钱包，您必须购买付费套餐或激活免费版套餐（如有）。要了解定价计划、账单与付款的详细信息，请参阅[账单与支付简介](https://manuals.cobo.com/cn/portal/bills-and-payments/introduction)。
* 要从您的钱包中提取代币，您必须首先设置 Callback Endpoint 以接收和批准提币请求。强烈建议您同时设置 Webhook Endpoint 以接收有关交易状态更新和其他重要事件的实时通知。要了解如何设置和注册 Webhook 和 Callback Endpoint，请参阅 [Webhook 和 Callback 介绍](/v2_cn/guides/webhooks-callbacks/introduction)。

## 另请参阅

* 要了解 Cobo Portal 提供的功能，包括如何选择钱包类型，请参阅 [Cobo Portal 简介](https://manuals.cobo.com/cn/portal/introduction)。

* 要了解 WaaS 2.0 API 的具体内容，请参阅 [API 参考](/v2/api-references)或从 [GitHub](https://github.com/CoboGlobal/developer-site/blob/master/v2/cobo_waas2_openapi_spec/dev_openapi.yaml) 下载 WaaS 2.0 API 规范。

* 要了解如何通过 WaaS API 使用全托管钱包（资产钱包），请参阅[全托管钱包（资产钱包）入门](/v2_cn/guides/custodial-wallets/get-started-asset-wallets)。

* 要了解如何查看 API 相关数据和日志，请参阅[开发者控制台简介](https://manuals.cobo.com/cn/portal/developer-console/introduction)。
