Skip to main content

Overview

This guide introduces how to get started with using the Cobo WaaS 2.0 Java SDK, which allows you to integrate the WaaS service into your existing application using the Java programming language. To learn more about the initial setup steps necessary for utilizing the WaaS API, see Get started with Wallet-as-a-Service (WaaS) 2.0.

Prerequisites

  • Install Java 1.8 or newer
  • Install Maven 3.8.3 or newer / Gradle 7.2 or newer
  • Follow the instructions in Quick start guide to set up your Cobo account and create your organization. If an organization has already been set up, ask your organization admin to invite you to join the organization.
  • You have generated an API key, and registered the API key on Cobo Portal.

Add dependency

For Maven users, add the dependency to your project’s POM:
<dependency>
  <groupId>com.cobo.waas2</groupId>
  <artifactId>cobo-waas2</artifactId>
  <version>{VERSION}</version>
  <scope>compile</scope>
</dependency>
For Gradle users, add the dependency to your project’s build file:
  repositories {
    mavenCentral()     // Fetch the dependency from Maven Central
  }

  dependencies {
     implementation "com.cobo.waas2:cobo-waas2:{VERSION}"
  }
Replace {VERSION} with the lastest version number, for example, 1.2.0. Obtain the latest version number from the GitHub repository.

Configure API key and HTTP host

  1. Set the private key.
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setPrivKey("<YOUR_API_PRIVATE_KEY_IN_HEX>");
  1. Select which environment you want to use. The SDK uses the production environment by default.
// Select the development environment
defaultClient.setEnv(Env.DEV);

// Select the production environment
defaultClient.setEnv(Env.PROD);

Code samples

For operation-specific documentation and sample code, see the docs folder in the WaaS SDK GitHub repository.

List supported chains

// Import classes 
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();
    // Use the development environment 
    defaultClient.setEnv(Env.DEV);
    // Set the private key
    defaultClient.setPrivKey("<YOUR_API_PRIVATE_KEY_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 {
      // List supported chains
      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();
    }
  }
}

Create a wallet

// Import classes 

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();
        // Use the development environment 
        defaultClient.setEnv(Env.DEV);
        // Set the private key
        defaultClient.setPrivKey("<YOUR_API_PRIVATE_KEY_IN_HEX>");
        WalletsApi apiInstance = new WalletsApi();
        CreateWalletParams createWalletParams = new CreateWalletParams(
                new CreateCustodialWalletParams()
                        .name("Example Wallet")
                        .walletType(WalletType.CUSTODIAL)
                        .walletSubtype(WalletSubtype.ASSET)
        );
        try {
            // Create a Custodial Wallet
            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();
        }
    }
}