> ## 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.

# getFlow

# 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

```javascript theme={"system"}
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

| Parameter | Type     | Description  |
| --------- | -------- | ------------ |
| `flowId`  | `string` | The flow ID. |

## Returns

`Promise<Flow>` — the current flow state.

## Execution States

Use the state to resume a flow without replaying a mutation that already succeeded.

| State              | Description                                            | Next action                                                                                |
| ------------------ | ------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `initiated`        | Flow created, no source attached yet                   | Attach a source or cancel.                                                                 |
| `source_attached`  | Source wallet or exchange attached                     | Attach a different source, get a quote, record an exchange transfer, or cancel.            |
| `quoted`           | Quote fetched                                          | Re-quote, attach a different source, submit for signing, or cancel.                        |
| `signing`          | Signing payload prepared, waiting for wallet signature | Continue the active signing operation. If it cannot resume, re-quote, reattach, or cancel. |
| `broadcasted`      | Transaction broadcast to the blockchain                | Poll or process webhooks. Do not attach another source or cancel.                          |
| `source_confirmed` | Source chain confirmed the transaction                 | Poll settlement until `completed` or `failed`. Do not call another execution mutation.     |
| `cancelled`        | Flow cancelled before broadcast                        | Create a new flow for another attempt.                                                     |
| `expired`          | Flow expired before completion                         | Create a new flow for another attempt.                                                     |
| `failed`           | Flow failed during execution                           | Create a new flow for another attempt.                                                     |

## Settlement States

| State       | Description                               |
| ----------- | ----------------------------------------- |
| `none`      | No settlement in progress                 |
| `bridging`  | Funds are being bridged across chains     |
| `routing`   | Transaction is being routed through a DEX |
| `settling`  | Funds are settling to the destination     |
| `swapping`  | Token swap is in progress                 |
| `completed` | Settlement is complete                    |
| `failed`    | Settlement failed                         |

## Examples

### Poll for completion

```javascript theme={"system"}
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

```javascript theme={"system"}
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;
  }
};
```

## React

`useGetFlow` fetches on mount and returns the TanStack Query result. Pass `refetchInterval` to poll automatically:

```tsx theme={"system"}
import { useGetFlow } from '@dynamic-labs-sdk/react-hooks';

function FlowStatus({ flowId }) {
  const { data: flow, isLoading } = useGetFlow({
    flowId,
    queryParams: { refetchInterval: 3000 },
  });

  if (isLoading) return <p>Loading...</p>;
  return (
    <div>
      <p>Execution: {flow?.executionState}</p>
      <p>Settlement: {flow?.settlementState}</p>
    </div>
  );
}
```

## Related

* [Fireblocks Flow JavaScript SDK guide](/docs/overview/fireblocks-flow-js-sdk) - End-to-end flow guide
* [`submitFlowTransaction`](/docs/javascript/reference/client/submit-flow-transaction) - Submit for signing and broadcast
* [`cancelFlow`](/docs/javascript/reference/client/cancel-flow) - Cancel a pending flow
