Agentic 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:
Get swap quotes between Spark BTC and Spark tokens
Execute trades on Flashnet via the Xverse swap engine
Run DCA strategies — periodic small buys at regular intervals
Rebalance a portfolio between BTC and stablecoins on Spark
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 Started)
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
--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:
spark:BTC
spark:USDB
Instant
spark:USDB
spark:BTC
Instant
Any Spark token
Any Spark token
Instant
What's next
Combine Flashnet trading with Lightning commerce for agents that both trade and accept payments
Add Starknet trading for deeper liquidity across AVNU DEX pairs
Explore treasury management for cross-chain fund sweeping
Last updated