Skip to main content
This content applies to WaaS 1.0 only. We highly recommend that you upgrade to WaaS 2.0.
This article provides an end-to-end demonstration of creating a crypto wallet application for your platform or exchange. Throughout the article, you will learn::
  1. How to initialize RestClients with Cobo SDKs.
  2. How to create your first deposit address.
  3. How to retrieve transaction information.
  4. How to make withdraw transactions.

Before you start:

Make sure you have finished your wallet setup based on Quickstart. Before writing your first demo, make sure that the following actions have been completed:
  1. You have pulled your preferred SDK for development.
  2. You have completed key pair generation for API Authentication.
  3. You have added your API Key to your Custodial Wallet, MPC Wallet, or MPC Lite Wallet.

Initialize

Cobo SDKs have packaged RestClients to interact with Cobo Wallet-as-a-Service APIs. To start, you need to initialize these Clients as well as the ApiSigner for API Authentication. Custodial Wallet
from cobo_custody.client import Client
from cobo_custody.config import DEV_ENV
from cobo_custody.signer.local_signer import LocalSigner

# input your API SECRET
signer = LocalSigner("YOUR_API_SECRET")
client = Client(signer=signer, env=DEV_ENV, debug=True)
import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboApiRestClient;
import com.cobo.custody.api.client.config.CoboApiConfig;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.impl.LocalSigner;

CoboApiRestClient client = CoboApiClientFactory.newInstance(
                new LocalSigner(apiSecret),
                Env.DEV,
                false).newRestClient();


MPC Wallet
from cobo_custody.client import MPCClient
from cobo_custody.config import DEV_ENV
from cobo_custody.signer.local_signer import LocalSigner

# input your API SECRET
signer = LocalSigner("YOUR_API_SECRET")
mpc_client = MPCClient(signer=signer, env=DEV_ENV, debug=True)
import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboMPCApiRestClient;
import com.cobo.custody.api.client.config.CoboApiConfig;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.impl.LocalSigner;

CoboMPCApiRestClient mpcClient = CoboApiClientFactory.newInstance(
                new LocalSigner(apiSecret),
                Env.DEV,
                false).newMPCRestClient();


Use the correct Client and Environment

Client is for custodial wallet, MPCClient is for MPC and MPC Lite wallet.
DEV_ENV is development environment, PROD_ENV is for production environment.

Create your first deposit address

Now you are able to create your first deposit address. Let us take Goerli ETH as an example. Please make sure that you or your admin have added GETH in the wallet. To verify, you can use Get Account Details for Custodial Wallet or Get Wallet Supported Coins for MPC Wallets. Cusotidal Wallet
response = client.get_account_info()
ApiResponse<OrgInfo> orgInfo = client.getOrgInfo();
MPC Wallet
response = mpc_client.get_wallet_supported_coins()
ApiResponse<MPCCoins> getSupportedCoinsResponse = mpcClient.getWalletSupportedCoins();

{
  "success": true,
  "result": {
    "name": "Your Account",
    "assets": [
      {
        "coin": "GETH",
        "display_code": "GETH",
        "description": "Ethereum Goerli Testnet",
        "decimal": 18,
        "can_deposit": true,
        "can_withdraw": true,
        "require_memo": false,
        "minimum_deposit_threshold": "0",
        "balance": "8765237351068000",
        "abs_balance": "0.008765237351068",
        "fee_coin": "GETH",
        "abs_estimate_fee": "0.000000000385476",
        "abs_estimate_fee_usd": "0.00",
        "confirming_threshold": 64,
        "dust_threshold": 1,
        "token_address": ""
      },
    ]
  }
}
If GETH is already available, you can create your first deposit address: Cusotidal Wallet
response = client.new_deposit_address("GETH")
ApiResponse<NewAddresses> newAddresses = client.newAddresses("GETH", 1, false);

MPC Wallet
response = mpc_client.generate_addresses("GETH",1)
ApiResponse<MPCAddressList> generateAddressResponse = mpcClient.generateAddresses("GETH", 1);

{
  "success": true,
  "result": {
    "coin": "GETH",
    "address": "0xec323f3743b96e020c234c216fa650f96b66fc9d"
  }
}

Check your first deposit transaction

You can make a deposit transaction to your newly created GETH address from an external address. After that, you can query the transaction by latest transaction time. Cusotidal Wallet
response = client.get_transactions_by_time(side="deposit", limit="1")
ApiResponse<List<Transaction>> getTransactionsByTime = client.getTransactionsByTime(null, Side.Deposit, null, 0, 0, 1, null);

MPC Wallet
response = mpc_client.list_transactions(transaction_type=1000, order_by="created_time", order="DESC", limit=1)
ApiResponse<MPCTransactions> listTransactionsResponse = mpcClient.listTransactions(null, null, null, "created_time", "DESC", 1000, null, null, null, 1);

{
  "success": true,
  "result": [
    {
      "id": "20230720143713000129950000008444",
      "coin": "GETH",
      "display_code": "GETH",
      "description": "Ethereum Goerli Testnet",
      "decimal": 18,
      "address": "0xe41f750d651d0385896704112f22e4a645ba454e",
      "source_address": "0xda4d48e9b9492999def195ef620af17d35ce65e0",
      "side": "deposit",
      "amount": "10000000000000000",
      "abs_amount": "0.01",
      "txid": "0x27cdd4750fc9a873ae62a7d0466ceaf40946d1e1bedd7dbe521a9a72a5851020",
      "vout_n": 0,
      "request_id": null,
      "status": "success",
      "abs_cobo_fee": "0",
      "created_time": 1689835033529,
      "last_time": 1689835033529,
      "confirmed_num": 34,
      "tx_detail": {
        "txid": "0x27cdd4750fc9a873ae62a7d0466ceaf40946d1e1bedd7dbe521a9a72a5851020",
        "blocknum": 9375296,
        "blockhash": "0xd7c3562bf373d126959adb4fa376b10eb9104c1e47807d8df1ab53d34008d045",
        "hexstr": ""
      },
      "source_address_detail": "0xda4d48e9b9492999def195ef620af17d35ce65e0",
      "confirming_threshold": 64,
      "type": "external"
    }
  ]
}
You may find other different ways of transaction query in API References: Custodial Wallet. MPC Wallet.

Make your first withdraw transaction

BBefore making the withdraw, you may want to find out the transaction fees. In Custodial Wallet, abs_estimate_fee in Get Coin Details indicates the withdraw fees in fee_coin. In MPC Wallets, gas_price in Get Estimate Fee indicates the on-chain real-time transaction fees. Cusotidal Wallet
response = client.get_coin_info("GETH")
print(f"Get Estimated Fee: {response.result['abs_estimate_fee']}")
ApiResponse<CoinInfo> getCoinInfo =client.getCoinInfo("GETH");
System.out.println("getAbsEstimateFee:" + getCoinInfo.getResult().getAbsEstimateFee());

{
  "success": true,
  "result": {
    "coin": "GETH",
    "display_code": "GETH",
    "description": "Ethereum Goerli Testnet",
    "decimal": 18,
    "can_deposit": true,
    "can_withdraw": true,
    "require_memo": false,
    "minimum_deposit_threshold": "0",
    "balance": "8765237351068000",
    "abs_balance": "0.008765237351068",
    "fee_coin": "GETH",
    "abs_estimate_fee": "0.000000000385476",
    "abs_estimate_fee_usd": "0.00",
    "confirming_threshold": 64,
    "dust_threshold": 1,
    "token_address": ""
  }
}
MPC Wallet
response = mpc_client.estimate_fee("GETH",1,"To_Address")
ApiResponse<EstimateFeeDetails> estimateFeeResponse = mpcClient.estimateFee(coin, withdraw_amount, fromAddr, null,
                null, null, null, null, null, null);

{
  "success": true,
  "result": {
    "fee_coin": "GETH",
    "fee_decimal": 18,
    "slow": {
      "fee_per_byte": 0,
      "fee_amount": 0,
      "gas_price": 18354,
      "gas_limit": 21000
    },
    "average": {
      "fee_per_byte": 0,
      "fee_amount": 0,
      "gas_price": 18354,
      "gas_limit": 21000
    },
    "fast": {
      "fee_per_byte": 0,
      "fee_amount": 0,
      "gas_price": 36708,
      "gas_limit": 21000
    }
  }
}
Now you can create your first withdraw transaction, please use UUID for request_id to prevent any confusion in future reconcilation. From address is required in MPC wallets whereas exampted in Custodial wallet. Meanwhile, pay attention to amount value and decimal format of each coin (amount = abs_amount*10^decimal).
Here is an example of withdrawing 0.01 GETH to an external account:
Cusotidal Wallet
request_id = f"request_id_{sha256(address.encode()).digest().hex()[:8]}_{str(int(time.time() * 1000))}"
response = client.withdraw("GETH","To_addres","10000000000000000",request_id)
String requestId = String.valueOf(System.currentTimeMillis());
ApiResponse<String> withdraw = client.withdraw("GETH",requestId,"toAddr","10000000000000000", null, null, null);

MPC Wallet
request_id = f"request_id_{sha256(address.encode()).digest().hex()[:8]}_{str(int(time.time() * 1000))}"
response = mpc_client.create_transaction("GETH",request_id,"From_address","To_Address","10000000000000000")
String requestId = String.valueOf(System.currentTimeMillis());
ApiResponse<MPCPostTransaction> createTransactionResponse = mpcClient.createTransaction("GETH", requestId, "10000000000000000", "fromAddr", "toAddr",
                toAddressDetails, fee, gasPrice, gasLimit, operation, extraParameters, null, null, null);

Then you may use the request_id to query the transaction status. Please note that the transaction will only be confirmed once the on-chain confirmation blocks reach confirming_threshold. Before that, you may use the GET /v1/custody/pending_transactions/ endpoint to query the details of a pending transaction under a Custodial Wallet. For an MPC Wallet, you may refer to the status field with code 501 PENDING_CONFIRMATION in any transactional APIs to retrieve the details of a pending transaction. Prior to using any endpoints, however, you need to first head to Cobo Custody Web and enable the “Transaction Notification - Includes Block Confirmation Number” Status feature. Failure to enable this feature will result in the inability to fetch transaction information. Do note that some transactions cannot be retrieved due to fast on-chain confirmations (e.g., TRON). Cusotidal Wallet
response = client.get_transactions_by_request_ids(request_ids="your request_id")
ApiResponse<List<Transaction>> getTransactionsByRequestIds = client.getTransactionsByRequestIds("your requestId");

MPC Wallet
response = mpc_client.transactions_by_request_ids("your request_id")
ApiResponse<MPCTransactionInfos> transactionsByRequestIdsResponse = mpcClient.transactionsByRequestIds("your requestId", null);

Congratulations! You have successfully created your first wallet application with Cobo Wallet-as-a-Service.

Code Samples

The sample codes are for reference only. Please use Cobo SDKs for your development.
Note: The code samples for Custodial Wallet and MPC Wallet are different.
Custodial Wallet
from cobo_custody.client import Client
from cobo_custody.config import DEV_ENV
from cobo_custody.signer.local_signer import LocalSigner
import time

api_secret = "your_api_secret"  # Your wallet api secret
coin_code = "GETH"  # Your testing coin
amount = 10000000000000000  # Withdraw amount:0.01GETH
to_address = "your address"  # Your external address

# Initialize Cobo Client
client = Client(signer=LocalSigner(api_secret), env=DEV_ENV, debug=False)

# Check if GETH has been added in your wallet
response = client.get_coin_info(coin=coin_code)
print(f"Get Coin Info: {response.result}")

# Create GETH address
response = client.new_deposit_address(coin=coin_code)
print(f"New Deposit Address: {response.result}")

# Get deposit transaction
response = client.get_transactions_by_time(side="deposit", limit="1")
print(f"Get Transactions By Time: {response.result}")

# Get estimated withdraw fee
response = client.get_coin_info(coin=coin_code)
print(f"Get Estimated Fee: {response.result['abs_estimate_fee']}")

# Withdraw 0.01GETH
request_id = f"ApiTransaction-{int(time.time() * 1000)}"    # Your custom request_id
response = client.withdraw(
    coin=coin_code,
    request_id=request_id,
    amount=amount,
    address=to_address,
)
print(f"Withdraw: {response.result}")

# Get transaction by request_id
response = client.get_transactions_by_request_ids(request_ids=request_id)
print(f"Get Transactions By Request Ids: {response.result}")

package com.cobo.custody.api.client.impl;

import java.math.BigInteger;
import java.util.List;

import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboApiRestClient;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.domain.ApiResponse;
import com.cobo.custody.api.client.domain.account.CoinInfo;
import com.cobo.custody.api.client.domain.account.NewAddresses;
import com.cobo.custody.api.client.domain.transaction.Side;
import com.cobo.custody.api.client.domain.transaction.Transaction;


public class CoboApiExample {
    public static void main(String[] args) {
        String apiSecret = "your_api_secret";  // Your wallet api secret
        String coin = "GETH";  // Your testing coin
        String requestId = String.valueOf(System.currentTimeMillis());  // Your custom request_id
        String toAddr = "your_address";  // Your external address
        BigInteger withdraw_amount = new BigInteger("10000000000000000");  // Withdraw amount:0.01GETH

        // Initialize Cobo Client
        CoboApiRestClient client = CoboApiClientFactory.newInstance(
                new LocalSigner(apiSecret),
                Env.DEV,
                false).newRestClient();

        // Check if GETH has been added in your wallet
        ApiResponse<CoinInfo> response = client.getCoinInfo(coin);
        System.out.println("getCoinInfo:" + response.getResult());

        // Create GETH address
        ApiResponse<NewAddresses> newAddresses = client.newAddresses(coin, 1, false);
        System.out.println("generateAddresses:" + newAddresses.getResult());

        // Get deposit transaction
        ApiResponse<List<Transaction>> getTransactionsByTime = client.getTransactionsByTime(null, Side.Deposit, null, 0, 0, 1, null);
        System.out.println("getTransactionsByTime: " + getTransactionsByTime.getResult());

        // Get estimated withdraw fee
        ApiResponse<CoinInfo> getCoinInfo = client.getCoinInfo(coin);
        System.out.println("getAbsEstimateFee:" + getCoinInfo.getResult().getAbsEstimateFee());

        // Withdraw 0.01GETH
        ApiResponse<String> withdraw = client.withdraw(
            coin,
            requestId,
            toAddr,
            withdraw_amount,
            null,
            null,
            null
        );
        System.out.println("withdraw:" + withdraw.getResult());

        // Get transaction by request_id
        ApiResponse<List<Transaction>> getTransactionsByRequestIds = client.getTransactionsByRequestIds(requestId);
        System.out.println(getTransactionsByRequestIds.getResult());
    }
}


MPC Wallet
from cobo_custody.client.mpc_client import MPCClient
from cobo_custody.config import DEV_ENV
from cobo_custody.signer.local_signer import LocalSigner
import time


api_secret = "your api secret"  # Your wallet api secret
chain_code = "GETH"  # Your testing chain
coin_code = "GETH"  # Your testing coin
amount = "10000000000000000"  # Withdraw amount:0.01GETH
from_address = "your mpc wallet address"  # Your MPC wallet address
to_address = "your address"  # Your external address

# Initialize Cobo Client
mpc_client = MPCClient(signer=LocalSigner(api_secret), env=DEV_ENV, debug=False)

# Check if GETH has been added in your wallet
response = mpc_client.get_wallet_supported_coins()
geth_coin_found = any(coin['coin'] == coin_code for coin in response.result['coins'])
is_coin_added = f"{coin_code} supports deposits and withdrawals." if geth_coin_found \
    else f"Your wallet does not have the {coin_code} coin. Please configure it on Cobo Custody Web."
print(is_coin_added)

# Create GETH address
response = mpc_client.generate_addresses(chain_code=chain_code, count=1)
print(f"New Deposit Address: {response.result}")

# Get deposit transaction
response = mpc_client.list_transactions(transaction_type=1000, order_by="created_time", order="DESC", limit=1)
print(f"Get Transactions By Time: {response.result}")

# Get estimated gas fee
response = mpc_client.estimate_fee(coin=coin_code, amount=1, address=to_address)
print(f"Get Estimated Gas Fee: {response.result}")

# Withdraw 0.01GETH
request_id = f"MPCTransaction-{int(time.time() * 1000)}"  # Your custom request_id
response = mpc_client.create_transaction(
    coin=coin_code,
    request_id=request_id,
    amount=amount,
    from_addr=from_address,
    to_addr=to_address,
)
print(f"Withdraw: {response.result}")

# Get transaction by request_id
response = mpc_client.transactions_by_request_ids(request_id)
print(f"Get Transactions By Request Ids: {response.result}")
package com.cobo.custody.api.client.impl;

import java.math.BigDecimal;
import java.math.BigInteger;

import com.cobo.custody.api.client.CoboApiClientFactory;
import com.cobo.custody.api.client.CoboMPCApiRestClient;
import com.cobo.custody.api.client.config.Env;
import com.cobo.custody.api.client.domain.ApiResponse;
import com.cobo.custody.api.client.domain.account.MPCAddressList;

import com.cobo.custody.api.client.domain.account.MPCCoins;
import com.cobo.custody.api.client.domain.transaction.EstimateFeeDetails;
import com.cobo.custody.api.client.domain.transaction.MPCPostTransaction;

import com.cobo.custody.api.client.domain.transaction.MPCTransactionInfos;
import com.cobo.custody.api.client.domain.transaction.MPCTransactions;


public class CobоCustodyApiClientExample {
    public static void main(String[] args) {
        String apiSecret = "your_api_secret";  // Your wallet api secret
        String coin = "GETH";  // Your testing coin
        String chain_code = "GETH";  // Your testing chain
        String requestId = String.valueOf(System.currentTimeMillis());  // Your custom request_id
        String fromAddr = "your_mpc_wallet_address";  // Your MPC wallet address
        String toAddr = "your address";  // Your external address
        BigInteger withdraw_amount = new BigInteger("10000000000000000");  // Withdraw amount:0.01GETH
        String toAddressDetails = null;
        BigDecimal fee = null;
        BigInteger gasPrice = null;
        BigInteger gasLimit = null;
        Integer operation = null;
        String extraParameters = null;

        // Initialize Cobo Client
        CoboMPCApiRestClient mpcClient = CoboApiClientFactory.newInstance(
                new LocalSigner(apiSecret),
                Env.DEV,
                false).newMPCRestClient();

        // Check if GETH has been added to your wallet
        ApiResponse<MPCCoins> getSupportedCoinsResponse = mpcClient.getSupportedCoins(coin);
        System.out.println("GetSupportedCoins: " + getSupportedCoinsResponse.getResult());

        // Create GETH address
        ApiResponse<MPCAddressList> generateAddressResponse = mpcClient.generateAddresses(chain_code, 1);
        System.out.println("Generated Address: " + generateAddressResponse.getResult());

        // Get deposit transaction
        ApiResponse<MPCTransactions> listTransactionsResponse = mpcClient.listTransactions(null, null, null, "created_time", "DESC", 1000, null, null, null, 1);
        System.out.println("Deposit Transactions: " + listTransactionsResponse.getResult());

        // Get estimated gas fee
        ApiResponse<EstimateFeeDetails> estimateFeeResponse = mpcClient.estimateFee(coin, withdraw_amount, fromAddr, null,
                null, null, null, null, null, null);
        System.out.println("Estimated Gas Fee: " + estimateFeeResponse.getResult());

        // Withdraw 0.01GETH
        ApiResponse<MPCPostTransaction> createTransactionResponse = mpcClient.createTransaction(coin, requestId, withdraw_amount, fromAddr, toAddr,
                toAddressDetails, fee, gasPrice, gasLimit, operation, extraParameters, null, null, null);
        System.out.println("Withdraw: " + createTransactionResponse.getResult());

        // Get transaction by request_id
        ApiResponse<MPCTransactionInfos> transactionsByRequestIdsResponse = mpcClient.transactionsByRequestIds(requestId, null);
        System.out.println("Transactions by Request ID: " + transactionsByRequestIdsResponse.getResult());
    }
}