Migration Guide

Overview

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.

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

1. Update Method Names

2. Update Parameters

3. Update Response Handling

4. Update PSBT Signing

5. Simplify Error Handling

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