# spark\_flashnet\_executeSwap

{% hint style="info" %}
This method is coming :soon:
{% endhint %}

Use the `spark_flashnet_executeSwap` method to request a **Flashnet swap** directly from the user’s Spark wallet.

Your app provides the swap parameters (pool, assets, amount, slippage, etc.), and the wallet handles the full Flashnet swap process.

This abstracts all back-and-forth with Flashnet into a **single request**, making swaps simple and secure.

## Parameters

{% hint style="success" %}
:rocket: Become an **Xverse Partner** to enable **integrator fees for your app ⇒** [**reach out**](https://calendly.com/jan-xverse) to get started
{% endhint %}

<table><thead><tr><th width="223.1796875">Request parameters</th><th>Description</th></tr></thead><tbody><tr><td><code>poolId</code></td><td>a string representing the Flashnet liquidity pool to use</td></tr><tr><td><code>assetInAddress</code>   <br></td><td>a string representing the address of the Spark asset being swapped in</td></tr><tr><td><code>assetOutAddress</code></td><td>a string representing the address of the Spark asset being swapped out </td></tr><tr><td><code>amountIn</code></td><td>a string representing the amount of input asset (in sats or smallest unit)</td></tr><tr><td><code>maxSlippageBps</code></td><td>Max slippage in basis points (e.g. 50 = 0.5%)</td></tr><tr><td><code>minAmountOut</code></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> Optional - a string representing the minimum acceptable output amount</td></tr><tr><td><code>totalIntegratorFeeRateBps</code></td><td>Fee (in basis points) your app requests for routing the swap.<br><span data-gb-custom-inline data-tag="emoji" data-code="26a0">⚠️</span><strong>To activate your app fee, you must be an approved Xverse partner.</strong> If you’re not approved, Xverse will ignore this value and apply its own default fee instead.<br><span data-gb-custom-inline data-tag="emoji" data-code="1f680">🚀</span> <a href="https://calendly.com/jan-xverse"><strong>Contact Xverse</strong></a> to become a partner and activate your app fee. </td></tr><tr><td><code>integratorPublicKey</code></td><td>Public key where your integrator fees should be sent.<br><span data-gb-custom-inline data-tag="emoji" data-code="26a0">⚠️</span> <strong>Only partner-approved (whitelisted) keys are accepted.</strong><br>If you pass a non-partner key, Xverse will replace it with its own.<br><span data-gb-custom-inline data-tag="emoji" data-code="1f680">🚀</span> <a href="https://calendly.com/jan-xverse"><strong>Contact Xverse</strong></a> to become a partner and get your key whitelisted.</td></tr><tr><td><code>userPublicKey</code></td><td>a string which must match the connected user's Spark public key</td></tr><tr><td><code>nonce</code></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> Optional - a string representing a unique swap nonce</td></tr></tbody></table>

## Example

```typescript
import { request } from "sats-connect";

try {
  const response = await request("spark_flashnet_executeSwap", {
    poolId: "03aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899",
    assetInAddress: "03bitcoinassetpubkey0000000000000000000000000000000000000000000000",
    assetOutAddress: "03usdstablecoinpubkey111111111111111111111111111111111111111111111",
    amountIn: "100000000", // in sats or smallest token units
    maxSlippageBps: 50, // 0.50% tolerance
    minAmountOut: "99500000", // optional safety check
    totalIntegratorFeeRateBps: 100, // 1.00% fee
    integratorPublicKey: "03aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899",
    userPublicKey: "02abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567",
    nonce: "unique-swap-nonce-123"
  });

  if ("result" in response) {
    console.log("Swap result:", response.result);
  } else {
    console.error("Swap failed:", response.error.message);
  }
} catch (error) {
  console.error("Unexpected error:", error);
}


```

## What `spark_flashnet_executeSwap` does

When called, this method:

1. Shows the user a **confirmation screen** with the swap details (pool, asset in/out, amount, fees, slippage).
2. On confirmation, the wallet:
   * Initiates the Spark transfer and authenticates your user with a Flashnet JWT
   * Generates the swap intent
   * Signs with the user’s Spark key
   * Submits to Flashnet
   * Returns the result (success or rejection)
3. Displays a **progress screen** while the steps complete.
4. Returns the swap result to the dApp.

<figure><img src="https://3630714736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F33DLypUqgcjkBSmN0gZn%2Fuploads%2FZDBvhxaXgpwq48KIBDxO%2Fimage.png?alt=media&#x26;token=afedcd12-b4e7-4aa1-bd2d-c0dc52cae7da" alt="" width="375"><figcaption></figcaption></figure>

## Responses&#x20;

The method returns a Promise that resolves to the `SparkFlashnetSwapResult`object

#### :white\_check\_mark: Success

```json
{
  "accepted": true,
  "amountOut": 4975000,
  "assetInAddress": "03bitcoinassetpubkey0000000000000000000000000000000000000000000000",
  "assetOutAddress": "03usdstablecoinpubkey111111111111111111111111111111111111111111111",
  "executionPrice": "0.00004975",
  "feeAmount": 5000,
  "outboundTransferId": "spark-transfer-out-123",
  "requestId": "01HJZKFABCDEFGHJKLMNPQRSTVW"
}

```

#### :x: Failure

```json
{
  "accepted": false,
  "error": "Insufficient liquidity in pool",
  "refundTransferId": "spark-transfer-refund-456",
  "refundedAmount": 100000000,
  "refundedAssetAddress": "03bitcoinassetpubkey0000000000000000000000000000000000000000000000",
  "requestId": "01HJZKFABCDEFGHJKLMNPQRSTVW"
}


```
