Recommended: JavaScript SDK with React Hooks
For new React apps, we recommend the JavaScript SDK with React Hooks (
@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.useExchangeAccounts hook provides functionality for managing exchange accounts and performing exchange-related operations. It allows users to retrieve their exchange accounts, view transaction history, fetch whitelisted transfer destinations (for exchanges that enforce whitelisting), and execute transfers.
This hook integrates with the Dynamic SDK to handle exchange operations across different blockchain networks and exchange platforms.
This hook supports the Fund from Exchange feature, allowing users to transfer funds directly from their exchange accounts to their wallets.
Available Methods
- exchangeTransfer - Execute transfers between exchange accounts
- getExchangeTransactions - Retrieve transaction history for exchange accounts
- getExchangeWhitelistedDestinations - Retrieve available destinations that a user may transfer to for a specific exchange
- getExchangeUserAccounts - Get all user accounts for a specific exchange
Methods
exchangeTransfer
Summary: Executes a transfer between exchange accounts. The method automatically finds the appropriate account based on the currency being transferred and creates the transfer request. Note: Kraken does not support specifying the network that a transfer will take place on. ThenetworkObject that you pass into a Kraken transfer will have no effect.
Inputs:
CreateExchangeTransferRequest Fields:
CreateExchangeTransferRequestNetworkObject:
Outputs:
ExchangeTransferResponse Fields:
Example Response:
getExchangeTransactions
Summary: Retrieves transaction history for exchange accounts. Can fetch transactions for a specific account or all accounts if no accountId is provided. Inputs:
Outputs:
ExchangeTransaction Fields:
Example Response:
getExchangeWhitelistedDestinations
Summary: Retrieves available destinations that a user may transfer to for a specific exchange Inputs:
Outputs:
TransferDestinationResponse Fields:
TransferDestination Fields:
Example Response:
getExchangeUserAccounts
Summary: Retrieves all exchange accounts associated with the current user for a specific exchange platform. Returns accounts with their balances and currency information. Inputs:
Outputs:
Account Fields:
Balance Fields:
Example Response:
Usage Example
Error Handling
The hook throwsDynamicError with specific error codes when operations fail:
UnprocessableEntityErrorCode.InvalidTransferCurrency: Thrown when no account is found for the specified currency during transfer operations.
Dependencies
This hook depends on:useInternalDynamicContextfor accessing wallet and network information- Dynamic SDK data layer for API calls
- Environment configuration for API endpoints