Skip to main content

cancelFlow

Cancels a flow before it has been broadcast to the blockchain. Once cancelled, the flow cannot be resumed — create a new one to start over.

Usage

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

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

console.log('Status:', flow.executionState); // 'cancelled'

Parameters

ParameterTypeDescription
flowIdstringThe flow ID to cancel.

Returns

Promise<Flow> — the cancelled flow with executionState: 'cancelled'.

Examples

Cancel on user action

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

const handleCancel = async (flowId) => {
  await cancelFlow({ flowId });
  console.log('Flow cancelled');
};

Cancel on wallet rejection

If a user rejects the signing request in their wallet, cancel the flow to clean up:
import { submitFlowTransaction, cancelFlow } from '@dynamic-labs-sdk/client';

try {
  await submitFlowTransaction({
    flowId: 'your-flow-id',
    walletAccount,
  });
} catch (error) {
  const isRejected =
    error.message?.includes('rejected') ||
    error.message?.includes('denied');

  if (isRejected) {
    await cancelFlow({ flowId: 'your-flow-id' });
  }
}