Skip to main content

Quick Start

Get your first Bitcoin-backed loan in under 5 minutes.

Prerequisites

Before you begin, ensure you have:
  • Installed the SDK (npm install @satsterminal-sdk/borrow)
  • An API key from SatsTerminal
  • A Bitcoin wallet with signing capability

Step 1: Initialize the SDK

import { BorrowSDK, ChainType } from '@satsterminal-sdk/borrow';

const sdk = new BorrowSDK({
  apiKey: 'your-api-key',
  chain: ChainType.ARBITRUM,
  wallet: {
    address: 'bc1qxyz...', // Your BTC address
    signMessage: async (message: string) => {
      // Implement signing with your wallet
      return await yourWallet.signMessage(message);
    }
  }
});

Step 2: Setup Your Account

The setup() method initializes your smart account and creates a session:
const { baseWallet, userStatus, activeSession } = await sdk.setup();

console.log('Smart Account:', baseWallet.address);
console.log('Session valid until:', new Date(activeSession.validUntil * 1000));
The first call to setup() will prompt the user to sign a message with their Bitcoin wallet. This signature is used to derive the smart account.

Step 3: Get a Loan

Use the high-level getLoan() method for the simplest experience:
const result = await sdk.getLoan({
  collateralBTC: 0.1,      // 0.1 BTC as collateral
  loanAmountUSD: 5000,     // Borrow $5,000
  ltv: 70,                 // 70% loan-to-value ratio

  // Callbacks for real-time updates
  onStatusUpdate: (status) => {
    console.log(`[${status.step}] ${status.label}`);
  },

  onDepositReady: (info) => {
    console.log(`\nDeposit Required:`);
    console.log(`  Amount: ${info.amountBTC} BTC`);
    console.log(`  Address: ${info.address}`);
  },

  onComplete: (result) => {
    console.log('\nLoan Complete!');
  },

  onError: (error) => {
    console.error('Error:', error);
  }
});

console.log('Workflow ID:', result.workflowId);
console.log('Selected Quote:', result.quote);

Step 4: Deposit Bitcoin

When onDepositReady fires, send the required Bitcoin to the deposit address:
onDepositReady: async (info) => {
  // If your wallet supports programmatic sending:
  if (sdk.walletProvider.sendBitcoin) {
    const txHash = await sdk.sendBitcoin(
      info.address,
      Math.round(info.amountBTC * 100_000_000) // Convert to satoshis
    );
    console.log('Deposit TX:', txHash);
  } else {
    // Otherwise, display for manual deposit
    console.log(`Please send ${info.amountBTC} BTC to ${info.address}`);
  }
}

Step 5: Loan Complete

Once the deposit is confirmed and processed, the loan will be executed automatically. The borrowed stablecoins will be available in your smart account.

Complete Example

import { BorrowSDK, ChainType } from '@satsterminal-sdk/borrow';

async function main() {
  // Initialize
  const sdk = new BorrowSDK({
    apiKey: process.env.SATSTERMINAL_API_KEY!,
    chain: ChainType.ARBITRUM,
    wallet: {
      address: process.env.BTC_ADDRESS!,
      signMessage: async (msg) => yourWallet.signMessage(msg)
    }
  });

  // Setup
  console.log('Setting up...');
  await sdk.setup();

  // Get loan
  console.log('Requesting loan...');
  await sdk.getLoan({
    collateralBTC: 0.1,
    loanAmountUSD: 5000,
    onStatusUpdate: (s) => console.log(`Status: ${s.label}`),
    onDepositReady: (i) => console.log(`Deposit ${i.amountBTC} BTC to ${i.address}`),
    onComplete: () => console.log('Done!'),
    onError: (e) => console.error(e)
  });
}

main().catch(console.error);

What’s Next?