spark_flashnet_executeRouteSwap
Use the spark_flashnet_executeRouteSwap method to request a multi-hop swap through Flashnet.
Your app specifies the input amount, route (up to 4 hops), and slippage parameters. The wallet handles the full process: verifying the Spark transfer, signing the swap request, submitting it to Flashnet, and returning the results.
This abstracts all route complexity into a single wallet request while preserving atomic execution: either all hops succeed, or the swap is reverted.
Example
import { request } from "sats-connect";
try {
const response = await request("spark_flashnet_executeRouteSwap", {
userPublicKey: "02abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567",
initialSparkTransferId: "spark-route-transfer-uuid-123456",
inputAmount: 100000000, // sats or smallest unit of input asset
maxRouteSlippageBps: 200, // 2.00% tolerance
minAmountOut: 99500000, // optional safety check
nonce: "unique-route-swap-nonce-789",
hops: [
{
assetInAddress: "03bitcoinassetpubkey0000000000000000000000000000000000000000000000",
assetOutAddress: "03ethereumassetpubkey1111111111111111111111111111111111111111111111",
hopIntegratorFeeRateBps: "25",
poolId: "03pool1aabbccddeeff00112233445566778899aabbccddeeff00112233445566778"
},
{
assetInAddress: "03ethereumassetpubkey1111111111111111111111111111111111111111111111",
assetOutAddress: "03usdstablecoinpubkey2222222222222222222222222222222222222222222222",
hopIntegratorFeeRateBps: "25",
poolId: "03pool2bbccddeeffffaabbccddeeff00112233445566778899aabbccddeeff0011"
}
]
});
if ("result" in response) {
console.log("Route swap result:", response.result);
} else {
console.error("Route swap failed:", response.error.message);
}
} catch (error) {
console.error("Unexpected error:", error);
}Parameters
userPublicKey(string, required) β Spark public key of the user.initialSparkTransferId(string, required) β Spark transfer ID proving the input deposit.inputAmount(integer, required) β Amount of input asset in smallest units.maxRouteSlippageBps(integer, required) β Maximum slippage allowed for the entire route.minAmountOut(integer, required) β Minimum acceptable final output.nonce(string, required) β Unique identifier to prevent replay.hops(array, required) β Ordered sequence of hops (1β4). Each hop includes:assetInAddressassetOutAddresspoolIdhopIntegratorFeeRateBps(optional)
integratorFeeRateBps(integer, optional) β Default integrator fee for the route.integratorPublicKey(string, optional) β Public key of the integrator.
What it does
When called, the wallet:
Shows a confirmation screen summarizing:
Input asset & amount
Route hops (pool IDs, asset in/out per hop)
Expected output & slippage tolerance
Applicable fees
On approval:
Validates and signs the route swap request
Submits to Flashnet
Displays a progress screen
Returns the route swap result back to the dApp.
Response
The method returns a Promise resolving to a SparkFlashnetRouteSwapResult.
β
Success
{
"accepted": true,
"outputAmount": 99500000,
"executionPrice": "0.00004975",
"finalOutboundTransferId": "spark-transfer-out-123",
"requestId": "01HJZKFABCDEFGHJKLMNPQRSTVW"
}β Failure
{
"accepted": false,
"error": "Insufficient liquidity on hop 2",
"refundedAssetAddress": "03bitcoinassetpubkey0000000000000000000000000000000000000000000000",
"refundedAmount": 100000000,
"refundTransferId": "spark-transfer-refund-456",
"requestId": "01HJZKFABCDEFGHJKLMNPQRSTVW"
}Last updated