> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Add swap capabilities

> Implement executeSwapTransaction on a custom WalletProvider to enable Fireblocks Flow and Swaps.

`executeSwapTransaction` is the method the Dynamic SDK calls when it needs your wallet to sign and broadcast a transaction. It is used by both the swaps flow (`executeSwapTransaction`) and Fireblocks Flow (`submitFlowTransaction`). If your `WalletProvider` does not implement it, the user can connect and sign messages, but cannot execute a swap or Flow transaction.

## What executeSwapTransaction receives

The method receives a `signingPayload` and a `walletAccount`, and must return `{ transactionHash }`.

* `signingPayload` — chain-specific transaction data prepared by the SDK.
* `walletAccount` — the connected account that should sign.

The exact fields on `signingPayload` depend on the chain:

* **EVM** — `evmTransaction` and optional `evmApproval` for ERC-20 allowances.
* **Solana / Sui** — `serializedTransaction`.
* **Bitcoin** — `psbt`.
* **Tron** — `tronTransaction`.

## High-level implementation

Add `executeSwapTransaction` to your `WalletProvider`:

```typescript theme={"system"}
import type { WalletProvider } from "@dynamic-labs-sdk/client/core";

const myWalletProvider: WalletProvider = {
  /* ... chain, key, metadata, connect, etc. ... */

  executeSwapTransaction: async ({ signingPayload, walletAccount }) => {
    // Replace with your wallet's native signing layer.
    // Branch by chain because the payload shape is different for each.
    const transactionHash = await myWalletSdk.signAndSend({
      signingPayload,
      walletAccount,
    });

    return { transactionHash };
  },
};
```

Your wallet's signing layer is responsible for:

1. Parsing the `signingPayload` for the target chain.
2. Ensuring the user is on the correct network (the SDK calls `ensureCorrectActiveNetwork` before `executeSwapTransaction`, but you can validate again).
3. Signing and broadcasting the transaction.
4. Returning the on-chain transaction hash.

## Use the wallet as a Flow source

With `executeSwapTransaction` implemented, a consumer can use the wallet to pay a Fireblocks Flow:

```typescript theme={"system"}
import {
  attachFlowSource,
  connectAndVerifyWithWalletProvider,
  getFlowQuote,
  submitFlowTransaction,
} from "@dynamic-labs-sdk/client";

const walletAccount = await connectAndVerifyWithWalletProvider({
  walletProviderKey: MY_WALLET_KEY,
});

await attachFlowSource({
  flowId: "flow-abc123",
  // Replace with the connected wallet address.
  fromAddress: walletAccount.address,
  // Replace with the chain ID the wallet is paying from.
  fromChainId: "1",
  // Replace with the chain family the wallet belongs to.
  fromChainName: "EVM",
  sourceType: "wallet",
});

await getFlowQuote({ flowId: "flow-abc123" });

const flow = await submitFlowTransaction({
  flowId: "flow-abc123",
  walletAccount,
});

console.log("Broadcasted:", flow.txHash);
```

`submitFlowTransaction` internally calls `prepareFlowSigning`, then delegates signing to your provider's `executeSwapTransaction`, then calls `broadcastFlow` with the resulting hash. The only wallet-specific work is inside `executeSwapTransaction`; everything else is handled by the Dynamic SDK.

## Use the wallet for Swaps

The same `executeSwapTransaction` method is used for generic swaps. The consumer calls `executeSwapTransaction` directly after fetching a swap quote:

```typescript theme={"system"}
import { executeSwapTransaction } from "@dynamic-labs-sdk/client";

const { transactionHash } = await executeSwapTransaction({
  signingPayload,
  walletAccount,
});
```

## Related

* [Build a WalletProvider](/docs/javascript/reference/creating-extensions/wallet-provider/build-wallet-provider)
* [Supported wallet standards](/docs/javascript/reference/creating-extensions/wallet-provider/supported-standards)
* [submitFlowTransaction](/docs/javascript/reference/client/submit-flow-transaction)
* [executeSwapTransaction](/docs/javascript/reference/client/execute-swap-transaction)
