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,显著提升开发效率 🚀
本指南介绍如何开始使用 Cobo WaaS 2.0 Java SDK,它允许您使用 Java 编程语言将 WaaS 服务集成到您的现有 App 中。
要了解使用 WaaS API 所需的初始设置步骤,请参阅发送您的第一个 API 请求。
您可以访问 GitHub 查看 SDK 的源代码。
前提条件
添加依赖
对于 Maven 用户,将依赖添加到您项目的 POM 文件中:
<dependency>
<groupId>com.cobo.waas2</groupId>
<artifactId>cobo-waas2</artifactId>
<version>{VERSION}</version>
<scope>compile</scope>
</dependency>
对于 Gradle 用户,将依赖添加到您项目的构建文件中:
repositories {
mavenCentral() // 从 Maven Central 获取依赖
}
dependencies {
implementation "com.cobo.waas2:cobo-waas2:{VERSION}"
}
将 {VERSION} 替换为最新版本号,例如
1.2.0。从
GitHub 仓库获取最新版本号。
配置 API Key 和 HTTP Host
- 设置 API Secret。
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setPrivKey("<YOUR_API_SECRET_IN_HEX>");
- 选择环境。
// 选择开发环境
defaultClient.setEnv(Env.DEV);
// 选择生产环境
// defaultClient.setEnv(Env.PROD);
示例代码
API 操作级别的文档和示例代码请参照 WaaS SDK GitHub 仓库内的 docs 文件夹。
列出支持的链
// 导入类
import com.cobo.waas2.ApiClient;
import com.cobo.waas2.ApiException;
import com.cobo.waas2.Configuration;
import com.cobo.waas2.Env;
import com.cobo.waas2.model.*;
import com.cobo.waas2.api.WalletsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 使用开发环境
defaultClient.setEnv(Env.DEV);
// 设置 API Secret
defaultClient.setPrivKey("<YOUR_API_SECRET_IN_HEX>");
WalletsApi apiInstance = new WalletsApi();
WalletType walletType = WalletType.fromValue("Custodial");
WalletSubtype walletSubtype = WalletSubtype.fromValue("Asset");
String chainIds = "";
Integer limit = 10;
String before = "";
String after = "";
try {
// 列出支持的链
ListSupportedChains200Response result = apiInstance.listSupportedChains(walletType, walletSubtype, chainIds, limit, before, after);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WalletsApi#listSupportedChains");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
创建钱包
// 导入类
import com.cobo.waas2.ApiClient;
import com.cobo.waas2.ApiException;
import com.cobo.waas2.Configuration;
import com.cobo.waas2.Env;
import com.cobo.waas2.model.*;
import com.cobo.waas2.api.WalletsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 使用开发环境
defaultClient.setEnv(Env.DEV);
// 设置 API Secret
defaultClient.setPrivKey("<YOUR_API_SECRET_IN_HEX>");
WalletsApi apiInstance = new WalletsApi();
CreateWalletParams createWalletParams = new CreateWalletParams(
new CreateCustodialWalletParams()
.name("Example Wallet")
.walletType(WalletType.CUSTODIAL)
.walletSubtype(WalletSubtype.ASSET)
);
try {
// 创建 Custodial 钱包
CreatedWalletInfo result = apiInstance.createWallet(createWalletParams);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WalletsApi#createWallet");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}