Skip to main content

Install

npm install @satsterminal-sdk/swaps
# or via suite
npm install satsterminal-sdk

Initialize the client

import { SatsTerminal } from "@satsterminal-sdk/swaps";
// or: import { SatsTerminal } from "satsterminal-sdk";

const swaps = new SatsTerminal({
  apiKey: process.env.API_KEY!,
});

1) Get a V2 quote

const quote = await swaps.swapQuote({
  amount: "0.001",
  fromToken: "BTC",
  toToken: "USDC",
  address: "bc1p...",
  protocol: "runes",
  params: {},               // keep empty unless protocol requires extras
});

console.log(quote.bestMarketplace, quote.swapId, quote.metrics);

2) Create PSBT(s)

const psbt = await swaps.swapPSBT({
  marketplace: quote.bestMarketplace,
  swapId: quote.swapId,
  address: "bc1p...",
  publicKey: "<your-pubkey>",
  paymentAddress: "<change-or-receive-address>",
  paymentPublicKey: "<change-pubkey>",
  protocol: "runes",
  feeRate: 5,
  slippage: 9,
  themeID: null,            // optional UI theme id
});

// psbt.psbts is an array; each entry has { base64, hex, inputs }

3) Sign + submit

const signedPsbts = psbt.psbts.map(({ hex }) => signWithWallet(hex));

const result = await swaps.swapSubmit({
  marketplace: quote.bestMarketplace,
  swapId: psbt.swapId,
  address: "bc1p...",
  publicKey: "<your-pubkey>",
  paymentAddress: "<change-or-receive-address>",
  paymentPublicKey: "<change-pubkey>",
  protocol: "runes",
  signedPsbts,
});

console.log("txid", result.txid, "marketplace", result.marketplace);

Optional: suite + borrow

import { createClient } from "satsterminal-sdk";
import { ChainType } from "@satsterminal-sdk/borrow";

const { swaps, borrow } = createClient({
  apiKey: process.env.API_KEY!,
  borrow: { chain: ChainType.BASE, wallet: /* wallet provider */ },
});

Legacy V1 flow (still supported)

If you need explicit rune order handling or RBF protection, keep using:
await swaps.fetchQuote();
await swaps.getPSBT();
await swaps.confirmPSBT();