Migration Guide
The SatsTerminal SDK V2 API introduces a significantly simplified approach to token swapping while maintaining full backward compatibility with V1. This guide will help you understand the conceptual differences and provide practical examples for migrating your code.
Key Benefits of V2
Simplified Direction Control
Clear fromToken/toToken parameters instead of confusing sell boolean
Automatic Order Management
No need to manually handle orders - everything managed via swapId
Multiple PSBT Support
Can handle complex transactions requiring multiple PSBTs
Normalized Data
Consistent, clean response structures
Better UX
Automatic marketplace selection and optimization
Reduced Complexity
Fewer parameters and simpler responses
Conceptual Differences
1. Direction Control
V1 Problem: The sell boolean parameter was confusing and error-prone.
// V1: Confusing direction control
const quote = await client.fetchQuote({
btcAmount: "0.00008",
runeName: "GOLD•DUST",
sell: false, // What does this mean? Buy runes with BTC? Sell BTC for runes?
address: "bc1..."
});V2 Solution: Clear, intuitive fromToken and toToken parameters.
// V2: Crystal clear direction
const quote = await client.swapQuote({
amount: "0.00008",
fromToken: "BTC", // I'm swapping FROM BTC
toToken: "GOLD DUST", // I'm swapping TO GOLD DUST
address: "bc1...",
protocol: "alkanes",
params: {}
});2. Order Management
V1 Problem: Manual order selection and management across multiple API calls.
V2 Solution: Automatic order management via swapId.
3. PSBT Handling
V1 Limitation: Always returned a single PSBT.
V2 Enhancement: Can return multiple PSBTs for complex transactions.
4. Data Structure Consistency
V1 Problem: Inconsistent, nested data structures.
V2 Solution: Normalized, consistent data format.
Migration Examples
Example 1: Basic Rune Purchase
V1 Implementation:
V2 Implementation (Migrated):
Example 2: Selling Runes for BTC
V1 Implementation:
V2 Implementation (Migrated):
Migration Checklist
Update Method Names
Replace
fetchQuote()withswapQuote()Replace
getPSBT()withswapPSBT()Replace
confirmPSBT()withswapSubmit()
Update Parameters
Replace
sell: booleanwithfromTokenandtoTokenstringsReplace
btcAmountwithamount(works for any token)Replace
runeNamewith appropriatefromTokenortoTokenAdd
protocolparameter ("runes" or "alkanes")
Update Response Handling
Replace
quote.selectedOrdersusage withquote.swapIdUpdate PSBT handling to support multiple PSBTs:
psbt.psbts[]Remove manual order management code
Update data access patterns for normalized structure
Update PSBT Signing
Change from single PSBT to array of PSBTs
Update signing loop:
psbt.psbts.map(p => signPSBT(p.hex))or use built-in wallet signPsbts method.Change parameter from
signedPsbtBase64tosignedPsbts[]
Simplify Error Handling
Remove order-related error handling
Simplify state management error handling
Focus on swap-specific errors (slippage, balance, etc.)
Common Pitfalls and Solutions
Pitfall 1: Single PSBT Assumption
Problem: Assuming V2 returns only one PSBT like V1.
Solution:
Pitfall 2: Order Management Confusion
Problem: Trying to manage orders manually in V2.
Solution:
Pitfall 3: Direction Confusion
Problem: Converting sell boolean incorrectly.
Solution:
Last updated