Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
getSwapStatus
Gets the current status of a swap transaction by its on-chain transaction hash. Use this to poll for completion after calling executeSwapTransaction.
Usage
import { getSwapStatus } from '@dynamic-labs-sdk/client';
const status = await getSwapStatus({
txHash: '0x1234567890abcdef...',
from: { chain: 'EVM', networkId: '1' },
to: { chain: 'EVM', networkId: '137' },
});
console.log('Status:', status.status);
console.log('Substatus:', status.substatus);
Parameters
| Parameter | Type | Description |
|---|
txHash | string | The on-chain transaction hash from executeSwapTransaction. |
from | object (optional) | Source chain details. |
from.chain | Chain | The source chain (e.g., 'EVM', 'SOL'). |
from.networkId | string | The source network ID. |
to | object (optional) | Destination chain details. |
to.chain | Chain | The destination chain. |
to.networkId | string | The destination network ID. |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<SwapStatusResponse> - The swap status:
type SwapStatusResponse = {
status: SwapStatus;
substatus?: SwapSubstatus | string;
};
Status Values
| Status | Description |
|---|
PENDING | Swap is in progress |
DONE | Swap completed successfully |
FAILED | Swap failed |
Substatus Values
When pending:
| Substatus | Description |
|---|
WAIT_SOURCE_CONFIRMATIONS | Waiting for source chain confirmations |
WAIT_DESTINATION_TRANSACTION | Waiting for destination chain transaction |
BRIDGE_NOT_AVAILABLE | Bridge temporarily unavailable |
CHAIN_NOT_AVAILABLE | Chain temporarily unavailable |
REFUND_IN_PROGRESS | Refund is being processed |
UNKNOWN_ERROR | Unknown pending error |
When done:
| Substatus | Description |
|---|
COMPLETED | Fully completed |
PARTIAL | Partially completed |
REFUNDED | Funds were refunded |
When failed:
| Substatus | Description |
|---|
INSUFFICIENT_ALLOWANCE | Token approval was insufficient |
INSUFFICIENT_BALANCE | Wallet had insufficient funds |
OUT_OF_GAS | Transaction ran out of gas |
EXPIRED | Swap route expired |
SLIPPAGE_EXCEEDED | Slippage tolerance was exceeded |
UNKNOWN_FAILED_ERROR | Unknown failure |
Examples
Poll until complete
import { getSwapStatus } from '@dynamic-labs-sdk/client';
const waitForSwap = async (txHash, from, to) => {
while (true) {
const { status, substatus } = await getSwapStatus({
txHash,
from,
to,
});
if (status === 'DONE') {
console.log('Swap completed:', substatus);
return { status, substatus };
}
if (status === 'FAILED') {
throw new Error(`Swap failed: ${substatus}`);
}
// Wait 3 seconds before polling again
await new Promise((resolve) => setTimeout(resolve, 3000));
}
};
const result = await waitForSwap(
'0x1234...',
{ chain: 'EVM', networkId: '1' },
{ chain: 'EVM', networkId: '137' }
);
Cross-chain status check
import {
executeSwapTransaction,
getSwapStatus,
} from '@dynamic-labs-sdk/client';
const { transactionHash } = await executeSwapTransaction({
walletAccount,
signingPayload: quote.signingPayload,
});
// For cross-chain swaps, provide both source and destination chain info
const status = await getSwapStatus({
txHash: transactionHash,
from: { chain: 'EVM', networkId: '1' }, // Ethereum
to: { chain: 'EVM', networkId: '137' }, // Polygon
});
if (status.substatus === 'WAIT_DESTINATION_TRANSACTION') {
console.log('Bridging in progress, waiting for destination chain...');
}