Skip to main content

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

ParameterTypeDescription
txHashstringThe on-chain transaction hash from executeSwapTransaction.
fromobject (optional)Source chain details.
from.chainChainThe source chain (e.g., 'EVM', 'SOL').
from.networkIdstringThe source network ID.
toobject (optional)Destination chain details.
to.chainChainThe destination chain.
to.networkIdstringThe destination network ID.
clientDynamicClient (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

StatusDescription
PENDINGSwap is in progress
DONESwap completed successfully
FAILEDSwap failed

Substatus Values

When pending:
SubstatusDescription
WAIT_SOURCE_CONFIRMATIONSWaiting for source chain confirmations
WAIT_DESTINATION_TRANSACTIONWaiting for destination chain transaction
BRIDGE_NOT_AVAILABLEBridge temporarily unavailable
CHAIN_NOT_AVAILABLEChain temporarily unavailable
REFUND_IN_PROGRESSRefund is being processed
UNKNOWN_ERRORUnknown pending error
When done:
SubstatusDescription
COMPLETEDFully completed
PARTIALPartially completed
REFUNDEDFunds were refunded
When failed:
SubstatusDescription
INSUFFICIENT_ALLOWANCEToken approval was insufficient
INSUFFICIENT_BALANCEWallet had insufficient funds
OUT_OF_GASTransaction ran out of gas
EXPIREDSwap route expired
SLIPPAGE_EXCEEDEDSlippage tolerance was exceeded
UNKNOWN_FAILED_ERRORUnknown 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...');
}