Skip to main content

Overview

This guide introduces how to get started with using the Cobo WaaS 2.0 JavaScript SDK, which allows you to integrate the WaaS service into your existing application using the JavaScript 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 NPM.
  • 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.

Install the SDK

Run the following command to install the SDK:
npm install @cobo/cobo-waas2 --save

Configure API key and HTTP host

  1. Set the private key.
// Initialize the default API client
const apiClient = CoboWaas2.ApiClient.instance
// Set the private key
apiClient.setPrivateKey("<YOUR_API_PRIVATE_KEY_IN_HEX>");
  1. Select which environment you want to use.
// Select the development environment
apiClient.setEnv(CoboWaas2.Env.DEV);

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

Code sample

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

List supported chains

const CoboWaas2 = require('@cobo/cobo-waas2');
// Initial default API client
const apiClient = CoboWaas2.ApiClient.instance
// Use the development environment
apiClient.setEnv(CoboWaas2.Env.DEV);
// Set the private key
apiClient.setPrivateKey("<YOUR_API_PRIVATE_KEY_IN_HEX>");
// Call the API
const apiInstance = new CoboWaas2.WalletsApi();
const opts = {
  'wallet_type': CoboWaas2.WalletType.Custodial,
  'wallet_subtype': CoboWaas2.WalletSubtype.Asset,
  'chain_ids': "BTC,ETH",
  'limit': 10,
  'before': "",
  'after': ""
};
apiInstance.listSupportedChains(opts).then((data) => {
  console.log('API called successfully. Returned data: ' + data);
}, (error) => {
  console.error(error);
});

Create a wallet

const CoboWaas2 = require('@cobo/cobo-waas2');
// Initial default API client 
const apiClient = CoboWaas2.ApiClient.instance
// Use the development environment
apiClient.setEnv(CoboWaas2.Env.DEV);
// Set the private key
apiClient.setPrivateKey("<YOUR_API_PRIVATE_KEY_IN_HEX>");
// Call the API
const apiInstance = new CoboWaas2.WalletsApi();
const walletName = "My Wallet"
const walletType = "Custodial"
const walletSubtype = "Asset"
const opts = {
    'CreateWalletParams': new CoboWaas2.CreateWalletParams(
        new CoboWaas2.CreateCustodialWalletParams(
            walletName,
            walletType,
            walletSubtype
        )
    )
};
apiInstance.createWallet(opts).then((data) => {
    console.log('API called successfully. Returned data: ' + data);
}, (error) => {
    console.error(error);
});