sparkleAgentic Flashnet Trading

✨ Guide: Agentic Flashnet Trading

Build AI agents that trade on Flashnet β€” the decentralized trading protocol on Spark. Instant swaps between Spark BTC and Spark-based tokens, powered by an offchain orderbook with on-chain settlement.

What you'll build

An agent that can:

  1. Get swap quotes between Spark BTC and Spark tokens

  2. Execute trades on Flashnet via the Xverse swap engine

  3. Run DCA strategies β€” periodic small buys at regular intervals

  4. Rebalance a portfolio between BTC and stablecoins on Spark

  5. Manage treasury β€” sweep profits back to cold BTC storage

Prerequisites

  • Xverse Agentic Wallet CLI installed (npm i -g @secretkeylabs/xverse-wallet-cli)

  • A funded wallet with BTC on Spark (see Getting Startedarrow-up-right)

Why Flashnet?

Flashnet is a trading protocol built on Spark that combines an offchain orderbook with fast, low-fee on-chain settlement. For agents, this means:

  • Instant settlement β€” swaps complete in seconds, not minutes

  • Low fees β€” no Bitcoin L1 confirmation overhead

  • BTC-native β€” trade between BTC and Spark-based tokens without leaving the Bitcoin ecosystem

  • Programmatic access β€” the Xverse swap engine routes through Flashnet automatically


Step 1: Fund Spark with BTC

Your agent needs BTC on Spark to trade. Check and fund:

Or if you have USDB or other Spark tokens, you're already set to swap.

Step 2: Get swap quotes

Use swap quote to get pricing from Flashnet and other available providers:

The response includes quotes from all available providers with rates, output amounts, and fees. Your agent can compare and pick the best.

Step 3: Execute a swap

Options

Option
Description

--from <token>

Source token (e.g. spark:BTC)

--to <token>

Destination token (e.g. spark:USDB)

--amount <value>

Amount of the source token

--provider <code>

Use a specific provider

--slippage <pct>

Slippage tolerance (percentage)

--yes

Execute (omit for dry run)

Step 4: DCA strategy β€” periodic buys

A Dollar-Cost Averaging agent buys a fixed amount at regular intervals, regardless of price:

Agent pseudocode:

Step 5: Portfolio rebalancing

An agent that maintains a target allocation between BTC and stablecoins:

Step 6: Sweep to cold BTC storage

Periodically move profits from Spark to Bitcoin L1:


Putting it all together: trading agent loop

Available Spark trading pairs

Run swap quote to discover currently available pairs. Common routes:

From
To
Settlement

spark:BTC

spark:USDB

Instant

spark:USDB

spark:BTC

Instant

Any Spark token

Any Spark token

Instant

What's next

Last updated