Skip to main content

getFlow

Fetches the current state of a flow. Use this to poll for status updates after submitting a transaction, or to restore flow state on page reload.

Usage

import { getFlow } from '@dynamic-labs-sdk/client';

const flow = await getFlow({ flowId: 'your-flow-id' });

console.log('Execution state:', flow.executionState);
console.log('Settlement state:', flow.settlementState);

Parameters

ParameterTypeDescription
flowIdstringThe flow ID.

Returns

Promise<Flow> — the current flow state.

Execution States

StateDescription
initiatedFlow created, no source attached yet
source_attachedSource wallet or exchange attached
quotedQuote fetched
signingSigning payload prepared, waiting for wallet signature
broadcastedTransaction broadcast to the blockchain
source_confirmedSource chain confirmed the transaction
cancelledFlow cancelled before broadcast
expiredFlow expired before completion
failedFlow failed during execution

Settlement States

StateDescription
noneNo settlement in progress
bridgingFunds are being bridged across chains
routingTransaction is being routed through a DEX
settlingFunds are settling to the destination
swappingToken swap is in progress
completedSettlement is complete
failedSettlement failed

Examples

Poll for completion

import { getFlow } from '@dynamic-labs-sdk/client';

const TERMINAL_EXECUTION = ['cancelled', 'expired', 'failed'];
const TERMINAL_SETTLEMENT = ['completed', 'failed'];

const pollFlow = async (flowId) => {
  const poll = async () => {
    const flow = await getFlow({ flowId });

    if (
      TERMINAL_EXECUTION.includes(flow.executionState) ||
      TERMINAL_SETTLEMENT.includes(flow.settlementState)
    ) {
      return flow;
    }

    await new Promise((resolve) => setTimeout(resolve, 3000));
    return poll();
  };

  return poll();
};

const finalFlow = await pollFlow('your-flow-id');
console.log('Final state:', finalFlow.settlementState);

Restore flow on page reload

import { getFlow } from '@dynamic-labs-sdk/client';

const restoreFlow = async () => {
  const storedId = localStorage.getItem('flowId');
  if (!storedId) return null;

  try {
    return await getFlow({ flowId: storedId });
  } catch {
    localStorage.removeItem('flowId');
    return null;
  }
};