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

# prepareFlowSigning

# prepareFlowSigning

Locks in the quote and transitions the flow to the `signing` state. Returns the flow with `quote.signingPayload` containing the data to sign.

<Note>
  Most integrations should use [`submitFlowTransaction`](/docs/javascript/reference/client/submit-flow-transaction) instead, which calls `prepareFlowSigning` automatically. Use this function directly only when you need to handle signing and broadcasting yourself (e.g., server-side signing with a custody wallet).
</Note>

## When to call

Call `prepareFlowSigning` only when `executionState` is `quoted`.

Before restoring or retrying a flow, call [`getFlow`](/docs/javascript/reference/client/get-flow) and check its current state.

<Warning>
  Do not call `prepareFlowSigning` again after the flow reaches `signing`.
  Continue with the returned signing payload. If the transaction was submitted,
  call [`broadcastFlow`](/docs/javascript/reference/client/broadcast-flow) with its
  hash. If no transaction was submitted and you need to restart, call
  [`getFlowQuote`](/docs/javascript/reference/client/get-flow-quote) to return to
  `quoted` with a new quote. If the flow has not reached `quoted` yet, attach a
  source and get a quote first. Poll `broadcasted` or `source_confirmed` flows.
  If the flow is `cancelled`, `expired`, or `failed`, create a new flow. Calling
  from an unsupported state returns `409`.
</Warning>

## Usage

```javascript theme={"system"}
import { prepareFlowSigning } from '@dynamic-labs-sdk/client';

const flow = await prepareFlowSigning({
  flowId: 'your-flow-id',
  assertBalanceForGasCost: true,
  assertBalanceForTransferAmount: true,
});

const { signingPayload } = flow.quote;
```

## Parameters

| Parameter                        | Type                 | Description                                                                                     |
| -------------------------------- | -------------------- | ----------------------------------------------------------------------------------------------- |
| `flowId`                         | `string`             | The flow ID.                                                                                    |
| `assertBalanceForGasCost`        | `boolean` (optional) | Verify the wallet has enough for gas. Returns `422` if insufficient. Default: `false`.          |
| `assertBalanceForTransferAmount` | `boolean` (optional) | Verify the wallet has enough for the transfer. Returns `422` if insufficient. Default: `false`. |

## Returns

`Promise<Flow>` — the flow with `executionState: 'signing'` and `quote.signingPayload` populated.

The signing payload structure depends on the chain:

| Chain    | Fields                                                                                                                       |
| -------- | ---------------------------------------------------------------------------------------------------------------------------- |
| EVM      | `evmTransaction` (`to`, `data`, `value`, `gasLimit`) and optional `evmApproval` (`tokenAddress`, `spenderAddress`, `amount`) |
| SOL, SUI | `serializedTransaction` (base64-encoded)                                                                                     |
| BTC      | `psbt` (base64-encoded unsigned PSBT)                                                                                        |
| TRON     | `tronTransaction` (`rawDataHex`, `to`, `value`)                                                                              |

## Examples

### Prepare with balance assertions

```javascript theme={"system"}
import { prepareFlowSigning } from '@dynamic-labs-sdk/client';

const flow = await prepareFlowSigning({
  flowId: 'your-flow-id',
  assertBalanceForGasCost: true,
  assertBalanceForTransferAmount: true,
});
```

### Manual sign and broadcast flow

```javascript theme={"system"}
import { prepareFlowSigning, broadcastFlow } from '@dynamic-labs-sdk/client';

// 1. Prepare
const prepared = await prepareFlowSigning({ flowId: 'your-flow-id' });
const { signingPayload } = prepared.quote;

// 2. Sign with your wallet (EVM example)
const txHash = await walletClient.sendTransaction({
  to: signingPayload.evmTransaction.to,
  data: signingPayload.evmTransaction.data,
  value: BigInt(signingPayload.evmTransaction.value),
});

// 3. Broadcast
await broadcastFlow({ flowId: 'your-flow-id', txHash });
```

## React

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

function PrepareButton({ flowId }) {
  const { mutate: prepare, data: flow, isPending } = usePrepareFlowSigning();

  return (
    <div>
      <button onClick={() => prepare({ flowId })} disabled={isPending}>
        {isPending ? 'Preparing...' : 'Prepare Signing'}
      </button>
      {flow?.quote?.signingPayload && <p>Ready to sign</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) - Recommended: handles prepare, sign, and broadcast
* [`broadcastFlow`](/docs/javascript/reference/client/broadcast-flow) - Record the broadcast
* [Signing the transaction by chain](/docs/overview/fireblocks-flow-api#signing-the-transaction-by-chain) - Chain-specific signing examples
