- Create a wallet
- Generate a deposit address within the wallet
- Deposit tokens into the wallet and track the transaction status
- Withdraw tokens from the wallet
- 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.
Prerequisites
- Follow the instructions in Send your first request 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.
1. Create a wallet
To create an Asset Wallet, call the Create wallet operation and specify the properties in the request body as follows:wallet_type
:Custodial
.wallet_subtype
:Asset
.
Sample code in Python
Sample code in Python
Sample code in Java
Sample code in Java
2. Generate deposit addresses
After setting up a wallet, you now need to generate deposit addresses within the wallet to receive tokens. To generate deposit addresses within the Asset Wallet you have just created, 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
3. 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 completed.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
4. 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
:Asset
.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 Set up a callback or webhook endpoint.
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
5. 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
Feel free to share your feedback to improve our documentation!