Documentation
Use Cases
Withdraw From Cex

Integrate the Withdrawal Feature in your dApp

ℹ️

Estimated feature integration time: ~2 hours*

Prerequisites

The following steps are required. If you haven't done so already, please follow the steps in the prerequisites guide:

  • Contact us to get access to the SDK package and client ID. You can also try the MOCK mode without a client ID (https://github.com/cedelabs/sdk-examples (opens in a new tab)).
  • Install the SDK package.
  • Create an SDK instance with your client ID. Every user's CEX account should have an exchange instance.
  • Subscribe to events to connect SDK's cache with your storage and manage errors.

Withdraw from CEX

  1. Retrieve withdrawable token list from our Provider API and display it to the user:
const tokens = await cedeSDK.api.getWithdrawableBalances({ exchangeInstanceId });
  1. When the user selects a token, you can retrieve the available withdrawal chains for the token:
const tokenSymbol = "ETH";
 
const networks = await cedeSDK.api.getNetworks({
  exchangeInstanceId,
  tokenSymbol,
  opts: {
    toWithdraw: true,
  },
});
  1. When the user selects a network, an amount, and a destination address, you should prepare the withdrawal. This is necessary to ensure that the withdrawable amount is available and that it exceeds the minimum withdrawal requirement:
const network = "ethereum";
const amount = "1";
const address = "0x123456789";
 
const data = await cedeSDK.api.prepareWithdrawal({
  fromExchangeInstanceId: exchangeInstanceId,
  tokenSymbol,
  amount,
  network,
});
  1. Then, you can detect if the exchange requires address whitelisting for withdrawals:
const supportedExchanges = await cedeSDK.api.getSupportedExchanges();
 
const exchangeInfo = supportedExchanges.find((exchange) => exchange.id === exchangeId);
 
const isRequiringAddressWhitelisting = exchangeInfo?.isRequiringAddressWhitelisting;
 
  1. Retrieve the list of whitelisted addresses for exchanges that support this feature and verify whether the intended destination address is on this list. This is especially recommended if the exchange mandates address whitelisting for withdrawals:
const provideWhitelistedAddresses = exchangeInfo?.provideWhitelistedAddresses
 
if (provideWhitelistedAddresses) { const whitelistedAddresses = await cedeSDK.api.getWhitelistedAddresses({
exchangeInstanceId, tokenSymbol, network });
 
// Check if the address is whitelisted const isAddressWhitelisted = whitelistedAddresses.find((whitelistedAddr) =>
whitelistedAddr.address === address); }
 
  1. After preparing the withdrawal (and optionally checking the whitelist), you can initiate the withdrawal:
const withdrawal = await cedeSDK.api.createWithdrawal({
  fromExchangeInstanceId,
  tokenSymbol,
  amount,
  address,
  network,
});
  1. Retrieve the withdrawal information by withdrawal ID:
const data = await cedeSDK.api.getWithdrawalById({
  exchangeInstanceId,
  tokenSymbol: withdrawal.from.transaction.tokenSymbol,
  withdrawalId: withdrawal.from.transaction.transactionId,
  timestamp: withdrawal.from.transaction.timestamp,
});

* The estimated integration time is for a project that already has UI components for a similar DeFi withdrawal feature.