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:
Parameter | Type | Description |
---|---|---|
exchange | ExchangeKeyEnum | The exchange platform identifier (e.g., Coinbase, Binance, etc.) |
transferRequest | CreateExchangeTransferRequest | The transfer request object containing transfer details |
Field | Type | Description |
---|---|---|
to | string | The recipient address (e.g., ‘0xRecipientAddr’) |
amount | number | The amount to transfer (e.g., 0.25) |
currency | string | The currency code (e.g., ‘ETH’, ‘USDC’) |
network | string | (Deprecated: use networkObject instead) The blockchain network (e.g., ‘ethereum’) |
networkObject | CreateExchangeTransferRequestNetworkObject | The networkId and chain that the transaction will occur on |
description | string | Optional description of the transfer |
mfaCode | string | Optional MFA verification code |
Field | Type | Description |
---|---|---|
networkId | string | The networkId that the transfer should take place on (e.g., ‘1’) |
chainName | ChainEnum | The chain that the transfer should take place on (e.g., ChainEnum.Evm) |
Field | Type | Description |
---|---|---|
Returns | Promise<ExchangeTransferResponse> | A promise that resolves to the transfer response containing transfer status and details |
Field | Type | Description |
---|---|---|
id | string | Unique transfer identifier (e.g., ‘tx-1’) |
exchangeAccountId | string | ID of the exchange account used for transfer |
status | string | Transfer status (e.g., ‘pending’, ‘completed’, ‘failed’) |
amount | number | The transferred amount |
currency | string | The currency that was transferred |
createdAt | Date | Timestamp when the transfer was created |
getExchangeTransactions
Summary: Retrieves transaction history for exchange accounts. Can fetch transactions for a specific account or all accounts if no accountId is provided. Inputs:Parameter | Type | Description |
---|---|---|
exchange | ExchangeKeyEnum | The exchange platform identifier |
accountId | string | undefined | Optional account ID to filter transactions for a specific account |
Field | Type | Description |
---|---|---|
Returns | Promise<ExchangeTransaction[]> | A promise that resolves to an array of exchange transactions |
Field | Type | Description |
---|---|---|
transactionId | string | Unique transaction identifier (e.g., ‘tx-123’) |
transactionHash | string | Blockchain transaction hash (e.g., ‘0xabc’) |
status | string | Transaction status (e.g., ‘pending’, ‘completed’, ‘failed’) |
amount | number | Transaction amount |
currency | string | Currency involved in the transaction |
createdAt | Date | Timestamp when the transaction was created |
getExchangeWhitelistedDestinations
Summary: Retrieves available destinations that a user may transfer to for a specific exchange Inputs:Parameter | Type | Description |
---|---|---|
exchange | ExchangeKeyEnum | The exchange platform identifier |
Field | Type | Description |
---|---|---|
Returns | Promise<TransferDestinationResponse> | A promise that resolves to an array of available destinations and an attribute whether this exchange enforces a whitelist |
Field | Type | Description |
---|---|---|
destinations | TransferDestination[] | An array of destinations available for transfer |
enforcesAddressWhitelist | boolean | A boolean whether this exchange has a whitelist. If false, then all addresses are available for transfer |
Field | Type | Description |
---|---|---|
address | string | The address included on the whitelist |
tokens | string[] | A list of tokens that the whitelist allows for transferring to the address with. If this field is undefined, then the address is whitelisted for all tokens |
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:Parameter | Type | Description |
---|---|---|
exchange | ExchangeKeyEnum | The exchange platform identifier |
Field | Type | Description |
---|---|---|
Returns | Promise<Account[]> | A promise that resolves to an array of user accounts with balance information |
Field | Type | Description |
---|---|---|
id | string | Unique account identifier (e.g., ‘acc-1’, ‘acc-2’) |
exchange | ExchangeKeyEnum | The exchange platform this account belongs to |
balances | Array<Balance> | Array of balance objects for different currencies |
Field | Type | Description |
---|---|---|
currency | string | Currency code (e.g., ‘USDC’, ‘BTC’, ‘ETH’) |
balance | number | Available balance amount |
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:useInternalDynamicContext
for accessing wallet and network information- Dynamic SDK data layer for API calls
- Environment configuration for API endpoints