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.
即刻安装 Cobo WaaS Skill,在 Claude Code、Cursor 等 AI 开发环境中使用自然语言集成 WaaS API,显著提升开发效率 🚀
本指南介绍如何使用钱包即服务 (WaaS) 2.0 API。阅读本指南后,您将能够成功调用一个 API 操作,并接收响应。
开始之前
如果您选择使用 WaaS SDK 而不是手动编写 API 请求,则需要先安装相应编程语言的正确版本。例如,如果您想使用 Python SDK,则需要安装 Python 3.7 或更新版本。
设置账户
按照快速入门中的说明设置您的 Cobo 账户并创建您的团队。如果团队已经创建,请让您的团队管理员邀请您加入团队。
生成 API Key 和 API Secret
生成一对 Ed25519 密钥对作为 API Key 和 API Secret。本指南以 OpenSSL 为例。要了解有关生成密钥对的其他方法,请参阅生成 API Key 和 API Secret。
- 在终端窗口中,运行以下 OpenSSL 命令:
# 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 文件中。
- 您可以通过运行以下命令打印密钥:
# 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。
- 登录 Cobo Portal(开发环境)。
- 在左侧导航菜单中,点击 开发者 > API Keys。
- 点击 注册 API Key。
- 输入 API Key 名称(最多 30 个字符)。
- 输入您在上一步中生成的公钥。
- 在用户角色 & 钱包范围下,设置用户角色为 Viewer,并设置钱包范围为任何类型钱包。用户角色用于确定 API Key 可以进行的操作,钱包范围用于确定 API Key 可以控制的钱包。
- 点击确认保存设置。
- 选择临时作为密钥类型。
如果您已经有静态 IP 地址,您可以将密钥类型设置为长期,并在IP 白名单中输入您的 IP 地址。
- 点击注册。
- 通知您的团队管理员在 Cobo Guard 上批准请求。
默认情况下,需要至少一半的管理员批准才能成功注册 API Key。
只有在 API Key 状态变为活跃中后,您才能开始使用它。
为您的请求添加身份认证信息
在发送 API 请求时,您需要在请求头中包含 API Key、随机数和 API 签名,以作为身份认证信息。有关更多信息,请参阅 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。
- Biz-Api-Nonce:随机数是 Unix 时间戳格式的当前时间,以毫秒为单位。
- Biz-Api-Signature:API 签名。要了解如何计算 API 签名,请参阅计算 API 签名。
发送请求
本指南使用 List supported chains 操作作为示例来演示如何发送 API 请求。此操作检索特定钱包类型或子类型支持的所有链。在以下示例中,我们检索全托管钱包支持的所有链。
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}'
如果请求成功,您应该收到以下响应:
{
"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 入门。
以下是调用 List supported chains 操作的示例代码。在配置 HTTP host 字段时,请使用开发环境的 URL,因为您在上一步已在开发环境中注册了 API Key。
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 请求并接收响应。但是,在您创建钱包、进行交易或实现其他功能之前,还有一些事情要做。
- 要开始使用钱包,您必须购买付费套餐或激活免费版套餐(如有)。要了解定价计划、账单与付款的详细信息,请参阅账单与支付简介。
- 要从您的钱包中提取代币,您必须首先设置 Callback Endpoint 以接收和批准提币请求。强烈建议您同时设置 Webhook Endpoint 以接收有关交易状态更新和其他重要事件的实时通知。要了解如何设置和注册 Webhook 和 Callback Endpoint,请参阅 Webhook 和 Callback 介绍。
另请参阅