- Query the chains and tokens you can use
- Set up a wallet
- Deposit and withdraw tokens
- Query wallet balances
This guide uses the development environment in all its code samples. It is recommended that you use the development environment to test your new features first before deploying them to the production environment.
Technical architecture
The following diagram illustrates the components within a fully-functioning MPC vault:- Each vault has two root extended public keys, one derived from the Secp256k1 curve and the other derived from the EdDSA curve.
- Each root extended public key can be used to derive multiple addresses.
- Each vault can have multiple key share holder groups. Each holder group has a set of TSS Nodes storing the private key shares that can collectively sign a transaction or recover the root private key. For Main Groups and Signing Groups, one key share holder will always be Cobo. To learn more about key share holder groups, see Create holder groups.
- Each TSS key share group consists of two or three private key shares, depending on the number of holders. Each key share group can form a key pair with the root extended public key derived from the same curve. Each key share is unique.
Prerequisites
- Follow the instructions in Get started with WaaS 2.0 to set up your account and send your first API request to the WaaS 2.0 service.
- If you choose to use a WaaS SDK instead of manually writing the API requests, refer to the SDK guide corresponding to the programming language of your choice (Python, Java, Go, JavaScript) to integrate the SDK into your project.
- Prepare some test tokens as you will need them when testing the deposit feature. To know which test tokens you can use, refer to Query chain and token information. In most cases, you can use XTN as the test token.
- It is highly recommended that you set up a callback endpoint to receive and approve withdrawal requests and a webhook endpoint to receive real-time notifications regarding transaction status updates and other events of your concern. To learn how to set up and register webhook and callback endpoints, refer to Introduction to webhooks and callbacks.
1. Query chain and token information
Before you begin setting up your wallet and generating deposit addresses, it’s important to know which chains and tokens you can use.Query enabled chains
To retrieve the chains you can use for Organization-Controlled Wallets and their corresponding chain IDs, call List enabled chains and specify the query parameters as follows:wallet_type:MPC.wallet_subtype:Org-Controlled.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Query enabled tokens
To retrieve the tokens you can use for Organization-Controlled Wallets and their corresponding token IDs, call List enabled tokens and specify the query parameters as follows:wallet_type:MPC.wallet_subtype:Org-Controlled.chain_ids: Specify the chain of your choice. You can also leave this parameter empty to query enabled tokens on all chains.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
2. Set up a wallet
The setup of an Organization-Controlled Wallet usually involves the following steps:- Create a vault.
- Create a key share holder group.
- Generate root extended public keys and private key shares.
- Create an Organization-Controlled Wallet.
Create a vault
Now that you have confirmed which chains and tokens you can use, the next step is to set up a vault. To create an vault, call the Create vault operation and specify the properties in the request body as follows:vault_type:Org-Controlled.name: The vault’s name.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Create a key share holder group
A key share holder group has a set of TSS Nodes storing the private key shares that can collectively sign a transaction or recover the root private key. In this step, you will set up to be a key share holder, get the TSS Node ID, and call the WaaS API to create a holder group.Become a key share holder
A Main Group consists of two key share holders. One holder is always Cobo, so you now need to find another holder to make up a Main Group. If you already have Cobo Guard installed on your phone, you can become a key share holder by using your phone as a mobile co-signer. As an alternative, you can set up a TSS node and use it as an API co-signer. To learn the differences between the two co-signer types, how to complete the setup, and how to acquire their TSS Node IDs, see Co-signer Type.Create a Main Group
Creating a Main Group is mandatory before you can create an MPC Wallet. To help you get started quickly, this guide will only introduces how to create a Main Group. However, in your actual projects, it is highly recommended that you also create a Signing Group and Recovery Group, as well as to back up your key shares. For more information, see Create holder groups and Back up key shares. To create a Main Group, call the Create key share holder group operation and specify the parameters and properties as follows:- Path:
vault_id: The ID of the vault you have just created.
- Request body:
key_share_holder_group_type:MainGroup.participants:2.threshold:2.key_share_holders: The information about the key share holder. You do not need to provide the information about Cobo as the key share holder, as it will be automatically filled by the WaaS service.name: Use a name that can help you easily identify the key share holder.type:Mobileif you use a mobile co-signer, orAPIif you use an API co-signer.tss_node_id: The TSS Node ID you have prepared in the previous step.signer:true
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Generate a root extended public key and key shares
After you create the Main Group, you need to generate root extended public keys and private key shares for your Main Group.-
Call the Create TSS request operation and specify the parameters and properties as follows:
-
Path:
vault_id: The ID of the vault you have just created.
-
Request body:
type:KeyGen.target_key_share_holder_group_id: The ID of the key share holder group you have just created.
-
Path:
-
Generate key shares.
- If you choose to use a mobile co-signer, you need to approve the “Approve Become Key Holder” request on Cobo Guard, and click Generate Key Shares to initiate the key generation process. Wait a brief moment for the key shares to be generated.
- If you choose to use an API co-signer, the key share generation process will be automatically initiated unless you have also configured a TSS Node callback server, in which case the generation process will be initiated upon approval from the TSS Node callback server.
Success. You can subscribe to TSS request-related event types to receive real-time status updates or call Get TSS request to query the latest request status.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Create a wallet
Now that you have created a vault, created a key share holder group, and generated the key shares, the next step is to set up a wallet. To create an Organization-Controlled Wallet, call the Create wallet operation and specify the properties in the request body as follows:name: Your wallet name.wallet_type:MPC.wallet_subtype:Org-Controlled.vault_id: The ID of the vault you have just created.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
3. Deposit and withdraw tokens
After setting up an Organization-Controlled Wallet, it is time to deposit some tokens into it and learn how to make withdrawals.Generate deposit addresses
To receive tokens, you need to generate deposit addresses within the wallet. To do so, call the Create addresses in wallet operation and specify the parameters and properties as follows:- Path:
wallet_id: The ID of the wallet you have just created.
- Request body:
chain_id: The ID of the blockchain.count: Use this parameter to specify the number of addresses you want to create.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Process deposit
After depositing tokens to the addresses you have generated, you can track the status of your deposit using one of the following two options. Compared with using API to query the transaction status, webhooks can give you real-time notifications and are thus the recommended option.Option 1: Use webhooks for real-time notifications
Webhook is an essential mechanism for the WaaS service to communicate with your application. After you register a webhook endpoint on Cobo Portal, the WaaS service sends push messages to the designated URL when an event occurs. To learn how to set up a webhook endpoint and register it on Cobo Portal, refer to Introduction to webhooks and callbacks. To track the status of your deposit, you can subscribe to the following webhook event types:- wallets.transaction.created
- wallets.transaction.updated
- wallets.transaction.succeeded
- wallets.transaction.failed
Option 2: Get transaction status by API call
To query the status of a deposit transaction, call the List all transactions operation and set the query parameters as follows:types:Deposit.statuses:Confirming, Completed. If you are depositing from an external address, you will be able to query the transaction details when the transaction is waiting for the required number of confirmations or when it is successfully executed.wallet_ids: The ID of the wallet you have created in the first step.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Withdraw tokens
Now that you have tokens in your wallet, it’s time to try withdrawing them.Set up a callback endpoint
To enhance the security of your transactions, it is highly recommended that you set up a callback endpoint to receive and approve withdrawal requests. Once you initiate a withdrawal using the WaaS 2.0 API, the callback endpoint will receive a callback message containing the transaction details. The transaction will proceed only if you approve the withdrawal request. To learn how to set up a callback endpoint and register it on Cobo Portal, refer to Introduction to webhooks and callbacks.Withdraw tokens
To withdraw tokens from the Asset Wallet, call the Transfer token operation and set the properties in the request body as follows:request_id: Your request ID.source.source_type:Org-Controlled.source.wallet_id: The ID of the wallet you have just created.token_id: The ID of the token you want to withdraw.destination.destination_type:Address.destination.account_output: The receiving address and memo (if applicable), and the amount you want to withdraw.category_names: The custom category for you to identify your transactions.description: The description of the transfer.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
Confirm the withdrawal
If you have set up a callback endpoint, after you initiate the withdrawal transaction, your callback endpoint will receive a message containing the transaction details. Check if the transaction meets expectations, and respond with a success status code (200 or 201) and a response body ofok to approve the transaction. To learn more about handling a callback message, see Handle messages.
Monitor the withdrawal status
In addition to webhook events, you can also call the Get transaction information operation to query the status of the transaction. Set the path parametertransaction_id to the transaction ID returned in the response of the previous withdrawal request.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
4. Query wallet balances
After successfully withdrawing tokens from your wallet, you can call List token balances by wallet to query the wallet balances. Specify the path and query parameters as follows:wallet_id: The ID of the wallet you have just created.token_ids: You can leave it empty to query the balances of all tokens, or set it to the specific token you want to query.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
