Migration Guide

Key Benefits of V2

1

Simplified Direction Control

Clear fromToken/toToken parameters instead of confusing sell boolean

2

Automatic Order Management

No need to manually handle orders - everything managed via swapId

3

Multiple PSBT Support

Can handle complex transactions requiring multiple PSBTs

4

Normalized Data

Consistent, clean response structures

5

Better UX

Automatic marketplace selection and optimization

6

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

1

Update Method Names

  • Replace fetchQuote() with swapQuote()

  • Replace getPSBT() with swapPSBT()

  • Replace confirmPSBT() with swapSubmit()

2

Update Parameters

  • Replace sell: boolean with fromToken and toToken strings

  • Replace btcAmount with amount (works for any token)

  • Replace runeName with appropriate fromToken or toToken

  • Add protocol parameter ("runes" or "alkanes")

3

Update Response Handling

  • Replace quote.selectedOrders usage with quote.swapId

  • Update PSBT handling to support multiple PSBTs: psbt.psbts[]

  • Remove manual order management code

  • Update data access patterns for normalized structure

4

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 signedPsbtBase64 to signedPsbts[]

5

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