Skip to main content

Best Practices

Guidelines for building robust applications with the SatsTerminal Borrow SDK.

Initialization

Always Call Setup First

Validate Configuration

Use Environment-Specific Configuration

Error Handling

Always Handle Errors

Use Typed Error Handling

Handle Workflow Errors Separately

Session Management

Check Session Before Operations

Clear Session on Disconnect

Workflow Tracking

Always Provide All Callbacks

Persist Workflow IDs

Resume Pending Workflows

Quotes

Validate Quote Selection

Configure Quote Selector

Transactions

Validate Inputs

Check Collateral Before Withdrawal

Performance

Cache Positions

Batch Operations

Use Appropriate Poll Interval

Security

Never Log Sensitive Data

Validate BTC Addresses

Use Secure Storage

Testing

Mock the SDK

Test Error Scenarios

Logging

Structured Logging

Log Important Events

Unit Handling

Use Units for Type-Safe Conversions

Normalize Unknown Units

When handling values from API responses where units may be ambiguous:

Use ResponseNormalizer for API Responses

Format Consistently for Display

Summary

  1. Initialize intentionally - Use setup() for dashboard/session preload; executeBorrow() prepares borrow state automatically
  2. Handle all errors - Use typed error handling
  3. Manage sessions - Check validity, refresh proactively
  4. Track workflows - Persist IDs, handle all callbacks
  5. Validate inputs - Check parameters before API calls
  6. Cache when possible - Reduce unnecessary API calls
  7. Secure sensitive data - Don’t log secrets, validate addresses
  8. Test thoroughly - Mock SDK, test error paths
  9. Log structured data - Track important events